Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-08-24 02:34:01


"Pavel Kuznetsov" <pavel_at_[hidden]> writes:

> David,
>
>>> Ok, I got your point. But maybe then it might be a good idea to add
>>> some kind of compile-time assert to
>>> boost::dereferenceable<>::operator->()?
>
>> I'd be happy to evaluate your patch containing an assert.
>
> Here it is.

Looks way too heavy to me for what it's accomplishing.

How about:

namespace error
{
  template <class T, class Value>
  int dereferenceable_requires_lvalue_dereference(Value&);
}

template <class T, class P, class B = ::boost::detail::empty_base>
struct dereferenceable : B
{
   P operator->() const
   {
     enum
     {
        assertion = sizeof(
          error::dereferenceable_requires_lvalue_dereference<T>(
             *static_cast<const T&>(*this)
          ))
     };
     return &*static_cast<const T&>(*this);
   }
};

??

Does that work?

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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