Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-12-02 08:10:43


David Abrahams wrote:

> Still no dice for vc7.1, though.

Hum, that was too easy:

#include <boost/static_assert.hpp>

typedef char yes;
typedef char (&no)[2];

template <class T>
yes is_nonconst_rvalue(T const&, ...);

template <class T>
no is_nonconst_rvalue(T&, int);

struct foo
{
#ifndef BOOST_MSVC
     template<typename U>
     operator U() const;

     template<typename V>
     operator V& ()
         volatile
     const
     ;
#else
     template<typename U>
     operator U() volatile;

     template<typename V>
     operator V& ()
     const
     ;
#endif

     static foo const instance;
     static bool select;
};

#define IS_RVALUE(x)
                 \
     (sizeof(is_nonconst_rvalue((foo::select ? foo::instance : (x)), 0))
== sizeof(yes))

int rvalue();
int const_rvalue();
int& lvalue();
int const& const_lvalue();

int volatile volatile_rvalue();
int const_volatile_rvalue();
int volatile& volatile_lvalue();
int const volatile& const_volatile_lvalue();

BOOST_STATIC_ASSERT(IS_RVALUE(rvalue()));
BOOST_STATIC_ASSERT(IS_RVALUE(const_rvalue()));
BOOST_STATIC_ASSERT(!IS_RVALUE(lvalue()));
BOOST_STATIC_ASSERT(!IS_RVALUE(const_lvalue()));

BOOST_STATIC_ASSERT(IS_RVALUE(volatile_rvalue()));
BOOST_STATIC_ASSERT(IS_RVALUE(const_volatile_rvalue()));
BOOST_STATIC_ASSERT(!IS_RVALUE(volatile_lvalue()));
BOOST_STATIC_ASSERT(!IS_RVALUE(const_volatile_lvalue()));

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