Is there any point using boost::noncopyable?

Does anyone use this class? Is it worth the dependency just to save writing your own (few line) non copyable class? Perhaps the sensible thing is to use it only when Boost is already a dependency?
Last edited on
I'm not 100% sure but noncopyable class is old overhead of what is today in C++11 called = delete;

MyCopyCotor = delete; // this is noncopyable class
the same steps goes for move ctor.

So yes if you ask me I would never use noncopyable class from boost library.
Yes, I think that is the best way to make a class non copyable in C++11. But I wonder if it's still worth having a base class
class NonCopyable {
  NonCopyable(const NonCopyable&) = delete;
  const NonCopyable& operator=(const NonCopyable&) = delete;

Perhaps this makes for slightly improved clarity of code, and it saves a bit of typing. On the other hand, the compiler starts to output more errors per attempted copy.

So I guess the question now has become a choice between
(1) use boost::noncopyable
(2) write a noncopyable base class using C++11 semantics
(3) use C++11 semantics to delete copy and assignment functions in each noncopyable class
Last edited on
maybe better (and cleaner) approach would be to use =delete only in most base class if you use multiple inheritance.

all derived classes are thus indirecly noncopyable.

otherwise boost::noncopyable is better IMO only for single classes, and only benefit is that you don't have to manualy type =delete;

Don't forget that derived assgnment operators and others may not work as you think they do, they don't call base class operators, move ctors and others!

The following will be hidden in the derived class by implicitly-declared versions (or user-declared versions, if the user declares them):
Default constructor: T()
Destructor: ~T()
Copy constructor: T(T const &) (sometimes without const)
Copy-assignment operator: T & operator=(T const &) (sometimes without const)
Move constructor: T(T &&)
Move-assignment operator: T & operator=(T &&)

Now you gotta ask your self what your primary goal is, and according to that you see what is the best approach.

I strongly belive that boost::noncopyable can bring more trouble then benefit in multiple inheritance.

Kind regards!
I use it, in a pre-11 product. Gives obvious compiler errors when someone attempts to copy those classes. (but yes, it is not the only thing we use from boost, of course)
Topic archived. No new replies allowed.