[bind10-dev] boost non-copyable

JINMEI Tatuya / 神明達哉 jinmei at isc.org
Mon May 24 19:38:11 UTC 2010


At Mon, 24 May 2010 19:04:20 +0800,
han benjamin <ben.han.cn at gmail.com> wrote:

> I read some code in c++ that try to make the class non-copyable.  In boost
> there is one utility class called noncopyable, which will make the code more
> clean and easy to read.

Yeah, I know boost noncopyable.  So far, however, I've not used it
because I wanted to minimize dependency on external libraries.  In
particular, I'd like to minimize the use of boost specific definitions
in public header files for wider portability.  For example, the only
boost header file I include in DNS library header files is
shared_ptr.hpp, while I use some other convenient things such as
lexical_cast in .cc's.  (Ideally I'd like to eliminate the dependency
on shared_ptr from header files, too, but that doesn't look like an
easy change).

If the introduction of the additional dependency sufficiently
outweighs the portability concern, it may make sense.  To me shared
pointers are crucial to make the implementation robust especially with
exceptions (and it wouldn't make sense to develop an in-house version
of it due to its complexity), so I've accepted its disadvantages.

As for noncopyable, although it may make the code simpler, IMO the
advantage isn't that substantial:

> Class PleaseDonotCopyMe
> {
> Private:
>          PleaseDonotCopyMe(const PleaseDonotCopyMe &);
>          PleaseDonotCopyMe & operator=(const PleaseDonotCopyMe &);
> 
> };
> 
> Boost way:
> 
> #include <boost/utility.hpp>
> 
> Class PleaseDonotCopyMe : boost::noncopyable  // use private inheritance

so personally I'm not convinced we should use it.

Others may have different opinions, of course.  Maybe a topic for
tomorrow's call?

---
JINMEI, Tatuya
Internet Systems Consortium, Inc.



More information about the bind10-dev mailing list