3

Is there any way to determine that some type is non-copyable during compile time? I need following:

template<typename T, unsigned long long MaxSize>
struct circular_buffer : boost::noncopyable {
    static_assert(typeof(T) ?????, "T must be noncopyable!");
};
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
nothrow
  • 15,882
  • 9
  • 57
  • 104
  • 1
    Why would it matter if `T` is copyable if you do not copy `T` objects? If you were using copyability to select between different implementations it would make sense, but I can't otherwise imagine why you would want to restrict something to work only with noncopyable objects. Obviously anything you can do with a non-copyable type you could also do with a copyable type. – Casey Feb 04 '14 at 16:52
  • @Casey, the T isn't homogenous type - as it's last field, there is char data[0]. I need spsc-lockfree buffer for heterogenous types - and I want it to be as safe as possible – nothrow Feb 04 '14 at 17:06

1 Answers1

11

C++11 has the is_copy_assignable and is_copy_constructible type traits. Assert that both are false.

Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157