
On Dec 17, 2005, at 12:17 AM, Eric Niebler wrote:
Here's my latest attempt. This works on gcc 3.4.4 (cygwin), but not on VC7.1 or (sadly) Comeau Online. Language lawyers, start your engines!
template<typename T> struct probe { operator T (); operator T volatile const &() const; };
template<typename T> probe<T> make_probe(T const &);
template<typename T> char is_volatile(T const &);
template<typename T> double is_volatile(T const volatile &);
#define IS_RVALUE(x) \ (\ sizeof(char) == \ sizeof(is_volatile(true?make_probe(x):(x)))\ )
That's very cool! Just as a thought experiment, I tried to re-implement your IS_RVALUE macro in (what I hope to be) C++0X. My purpose was mainly just to amuse myself, but also as a sanity check that C++0X will actually make things like this easier. I'm aware that the motivation for IS_RVALUE is also greatly reduced in C++0X. I'm just exploring. Fwiw I came up with: #include <type_traits> template<typename T> T&& test(T&&); #define IS_RVALUE(x) (std::is_rvalue_reference<decltype(test(x))
::value)
I only spent a couple of minutes on it, so I wouldn't take it to the bank. But it is lightly tested. -Howard