Boost logo

Boost :

From: Gmane (d.frey_at_[hidden])
Date: 2007-05-31 14:09:37


Hi,

as sparent_at_[hidden] pointed out in
<http://svn.boost.org/trac/boost/ticket/979>, the EBO is not possible in
some cases. I fixed the operators library, but now I wonder if we should
fix boost::noncopyable as well.

Consider:

class A : boost::noncopyable {};
class B : boost::noncopyable { A a; };

now sizeof(B)==2 instead of the expected 1. To fix it, we have to change
the interface (or at least allow an alternative interface). Example with
   the interface I'd like to suggest:

class A : boost::noncopyable_<A> {};
class B : boost::noncopyable_<B> { A a; };

now sizeof(B)==1, as expected.

The crucial point of such a change is IMHO the interface. Breaking
noncopyable is bad, so I'd like to add noncopyable_<T> and make
noncopyable a typedef to noncopyable_<void>. This should provide
backwards compatibility and provides users with a better, but less brief
alternative in case they need the additional EBO opportunity. Comments?

Since it's so damn short, here's the suggested implementation:

namespace boost
{
  namespace noncopyable_impl // prevent unintended ADL
  {
    template< typename > class noncopyable_
    {
    protected:
      noncopyable_() {}
      ~noncopyable_() {}
    private:
      noncopyable_( const noncopyable_& );
      const noncopyable_& operator=( const noncopyable_& );
    };
    typedef noncopyable_<void> noncopyable;
  }

  using namespace noncopyable_impl;
}

Regards, Daniel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk