$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] [type_traits] will the future has_operator_left_shift be able to test if a type is serializable to a stream ?
From: Mathieu Champlon (mathieu.champlon_at_[hidden])
Date: 2011-02-01 18:09:41
Hello,
I just tried the type_traits extension from the sandbox : 
http://svn.boost.org/svn/boost/sandbox/type_traits
(by the way the source files are indented with tabs)
Simply including for instance 
<boost/type_traits/has_operator_left_shift.hpp> on vc80 and vc100 yields :
boost/type_traits/detail/has_binary_operator.hpp(80) : warning C4346: 
'boost::is_class<boost::remove_reference<T>::type>::value' : dependent 
name is not a type
         prefix with 'typename' to indicate a type
boost/type_traits/detail/has_binary_operator.hpp(142) : see reference to 
class template instantiation 
'boost::has_operator_left_shift<LHS,RHS,RET>' being compiled
boost/type_traits/detail/has_binary_operator.hpp(80) : error C2146: 
syntax error : missing ')' before identifier 'or'
boost/type_traits/detail/has_binary_operator.hpp(142) : error C2039: 
'value' : is not a member of '`global namespace''
boost/type_traits/detail/has_binary_operator.hpp(142) : error C2059: 
syntax error : ')'
boost/type_traits/detail/has_binary_operator.hpp(142) : error C2143: 
syntax error : missing ';' before '{'
boost/type_traits/detail/has_binary_operator.hpp(142) : fatal error 
C1004: unexpected end-of-file found
It compiles fine on cygwin with gcc 3.4.4 though.
I spent a few minutes trying to pinpoint the exact location of the error 
without much success (got lost in the macros).
I'm using boost 1.42.
Anyway, it seems that nothing in the documentation indicates the new 
traits are limited to numeric types.
Moreover it sort of works for testing if a type is serializable to an 
std::ostream :
     BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< std::ostream, 
int >::value ));
And it also works for far more advanced cases (like a type convertible 
to another type which is serializable, or a class deriving from another 
class which is serializable, etc..)
However it doesn't work with a pointer type, for instance this fails :
     BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< std::ostream, 
void* >::value ));
Will this use case be supported ?
Thanks,
MAT.