[type_traits] will the future has_operator_left_shift be able to test if a type is serializable to a stream ?

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

Simply including for instance
on vc80 and vc100 yields :
Could it be a problem of line ending (windows/linux)? Could you try with that version: http://www.boostpro.com/vault/index.php?action=downloadfile&filename=type_traits-dos.tar.bz2&directory=Extension&
Anyway, it seems that nothing in the documentation indicates the new traits are limited to numeric types.
It should not be 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..)
OK, thank you for testing this.
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 ));
Can you say what you mean by it doesn't work? Do you mean compile error or returns the wrong value?
Will this use case be supported ?
This should work properly. I will have a look. Thanks for testing. Frédéric

On 02/02/2011 08:23, Frédéric Bron wrote:
Could it be a problem of line ending (windows/linux)? Could you try with that version: http://www.boostpro.com/vault/index.php?action=downloadfile&filename=type_traits-dos.tar.bz2&directory=Extension&
I just tried and it gives the same error. Actually it seems MSVC doesn't like "not", "or" and "and" : replacing them with "!", "||" and "&&" makes the error (and the warning) go away. However next, the following code : BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< int, int
::value ));
Yields the rather non-informative error :
..... the code ..... : error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
(yes that's the only line in the error trace...)
And :
BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< std::ostream,
int >::value ));
Adds a warning on top of the same error :
boost/type_traits/detail/has_binary_operator.hpp(106) : warning C4913:
user defined binary operator ',' exists but no overload could convert
all operands, default built-in binary operator ',' used
boost/type_traits/detail/has_binary_operator.hpp(142) : see
reference to class template instantiation
'boost::detail::has_operator_left_shift_impl::has_operator_left_shift_impl
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 )); Can you say what you mean by it doesn't work? Do you mean compile error or returns the wrong value?
Sorry, I meant the assertion fails. Another case which doesn't compile however is : struct convertible_ambiguous { operator int() const; operator float() const; }; BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< std::ostream, convertible_ambiguous >::value )); Thanks ! MAT.

(by the way the source files are indented with tabs) I found here (http://www.boost.org/development/header.html) that indentation with space is not a requirement: "The alert reader will have noticed that the sample header employs a certain coding style for indentation, positioning braces, commenting ending braces, and similar formatting issues. These stylistic issues are viewed as personal preferences and are not part of the Boost Header Policy."
Have you seen anything else that shows this may be wrong?
Actually it seems MSVC doesn't like "not", "or" and "and" : replacing them with "!", "||" and "&&" makes the error (and the warning) go away.
It may be related to this page: http://www.boost.org/development/int_const_guidelines.html I will try to comply with all these recommendations which will be difficult! Hope it will solve this type of issues.
struct convertible_ambiguous { operator int() const; operator float() const; };
Yes I have seen that (if you look at the tests in type_traits/libs/type_traits/test, you will see that I have commented such tests. I am not sure if there is any solution for this. Frédéric

Actually it seems MSVC doesn't like "not", "or" and "and" : replacing them with "!", "||" and "&&" makes the error (and the warning) go away.
It may be related to this page: http://www.boost.org/development/int_const_guidelines.html I will try to comply with all these recommendations which will be difficult! Hope it will solve this type of issues.
Can you try the following version and tell me if it compiles fine? http://www.boostpro.com/vault/index.php?action=downloadfile&filename=type_traits-dos.tar.bz2&directory=Extension& I have removed any call to logical operators in constant expressions and replaced them by ice constructs (not done yet for all operators but should be ok for <<). I still have to remove reference to numeric_limits which seems to be an issue with some compilers. Frédéric

On 02/02/2011 22:20, Frédéric Bron wrote:
Can you try the following version and tell me if it compiles fine? http://www.boostpro.com/vault/index.php?action=downloadfile&filename=type_traits-dos.tar.bz2&directory=Extension&
I have removed any call to logical operators in constant expressions and replaced them by ice constructs (not done yet for all operators but should be ok for<<). I still have to remove reference to numeric_limits which seems to be an issue with some compilers.
The #include goes fine but I still get the following error : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int With the code : BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< int, int
::value ));
On 02/02/2011 20:13, Frédéric Bron wrote:
(by the way the source files are indented with tabs) I found here (http://www.boost.org/development/header.html) that indentation with space is not a requirement: "The alert reader will have noticed that the sample header employs a certain coding style for indentation, positioning braces, commenting ending braces, and similar formatting issues. These stylistic issues are viewed as personal preferences and are not part of the Boost Header Policy."
Have you seen anything else that shows this may be wrong?
Yes at http://www.boost.org/development/requirements.html#Tabs (Tabs rationale). I'm not an expert at boost guidelines however.
struct convertible_ambiguous { operator int() const; operator float() const; };
Yes I have seen that (if you look at the tests in type_traits/libs/type_traits/test, you will see that I have commented such tests. I am not sure if there is any solution for this.
I haven't been able to find any in the past and was quite curious to see if you succeeded. :) Maybe this should be written in the documentation as a limitation, though ? MAT.

The #include goes fine but I still get the following error : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int With the code : BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< int, int >::value ));
New version here: http://www.boostpro.com/vault/index.php?action=downloadfile&filename=type_traits-dos.tar.bz2&directory=Extension&
(by the way the source files are indented with tabs)
now with spaces
struct convertible_ambiguous { operator int() const; operator float() const; }; Maybe this should be written in the documentation as a limitation, though ?
Yes, good point. Thanks, I am trying to install Visual Express 10 for testing purposes but its is really really heavy (2.3 Gb!!!). Hope I will be able to remove it soon. Frédéric

On 2/3/2011 6:03 PM, Frédéric Bron wrote:
The #include goes fine but I still get the following error : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int With the code : BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< int, int>::value ));
New version here: http://www.boostpro.com/vault/index.php?action=downloadfile&filename=type_traits-dos.tar.bz2&directory=Extension&
I hope you are updating your sandbox version also. I find getting anything from the vault to be harder than simply updating a sandbox library through TortoiseSVN.

On 03/02/2011 23:03, Frédéric Bron wrote:
The #include goes fine but I still get the following error : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int With the code : BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< int, int>::value )); New version here: http://www.boostpro.com/vault/index.php?action=downloadfile&filename=type_traits-dos.tar.bz2&directory=Extension&
Yes this fixes the error.
Now :
BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< std::ostream,
int >::value ));
Yields :
boost/type_traits/detail/has_binary_operator.hpp(103) : warning C4913:
user defined binary operator ',' exists but no overload could convert
all operands, default built-in binary operator ',' used
boost/type_traits/detail/has_binary_operator.hpp(139) : see
reference to class template instantiation
'boost::detail::has_operator_left_shift_impl::has_operator_left_shift_impl

New version of the type_traits extension available here: - vault unix: http://www.boostpro.com/vault/index.php?action=downloadfile&filename=type_traits.tar.bz2&directory=Extension& - vault dos: http://www.boostpro.com/vault/index.php?action=downloadfile&filename=type_traits-dos.tar.bz2&directory=Extension& - sandbox: http://svn.boost.org/svn/boost/sandbox/type_traits/ can you check? BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< int, int >::value )); BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< std::ostream, int >::value )); Regards, Frédéric

On 05/02/2011 21:01, Frédéric Bron wrote:
BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< std::ostream, int>::value ));
This one still produces the following warning (with both vc80 and vc100) :
boost/type_traits/detail/has_binary_operator.hpp(102): warning C4913:
user defined binary operator ',' exists but no overload could convert
all operands, default built-in binary operator ',' used
boost/type_traits/detail/has_binary_operator.hpp(136) : see
reference to class template instantiation
'boost::detail::has_operator_left_shift_impl::has_operator_left_shift_impl1

BOOST_STATIC_ASSERT(( boost::has_operator_left_shift< std::ostream, int>::value ));
This one still produces the following warning (with both vc80 and vc100) :
boost/type_traits/detail/has_binary_operator.hpp(102): warning C4913: user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used boost/type_traits/detail/has_binary_operator.hpp(136)
What says this warning is fine (by the way I have been able to reproduce it with VC++ 2010). It describes well what happen. I do not know if it is possbile to remove the warning. Nevertheless, what is important is that the result is now 'true'. I am getting closer to the review. Frédéric

On 06/02/11 07:19, Frédéric Bron wrote:
know if it is possbile to remove the warning. It describes well what happen. You can try to disable it using some MSVC warning pragma to locally disable it/reenable it at end of the file:
http://msdn.microsoft.com/en-us/library/2c8f766e%28v=vs.80%29.aspx
participants (4)
-
Edward Diener
-
Frédéric Bron
-
Joel Falcou
-
Mathieu Champlon