Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-08-24 11:49:05


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

>> Does that work?
>
> Alas, that does not, since at least MSVC allows binding rvalue
> to non-const reference. But we can simplify original approach
> along these lines:
>
> namespace error
> {
> template <class T, class Value>
> int
> dereferenceable_requires_lvalue_dereference(
> Value& (T::*)()const);
> }
>
> 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>(
> &T::operator*
> ))
> };
> return &*static_cast<const T&>(*this);
> }
> };

No good, I'm afraid. You can define a unary non-member operator*:

  struct X {};
  int operator*(X const&);

-- 
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