[fusion] inconsistency in size metafunction

Consider : #include <boost/fusion/include/vector.hpp> #include <boost/fusion/include/push_back.hpp> #include <boost/fusion/include/size.hpp> #include <boost/mpl/assert.hpp> #include <boost/type_traits/is_same.hpp> int main() { using namespace boost; using namespace fusion; typedef vector<int, int> seq1; typedef result_of::push_back<vector<int>, int>::type seq2; BOOST_MPL_ASSERT((is_same<result_of::size<seq1>::type, result_of::size<seq2>::type>)); } One would not expect this to fail, however it does : 'boost::mpl::assertion_failed' : cannot convert parameter 1 from 'boost::mpl::failed ************boost::is_same<T,U>::* ***********' to 'boost::mpl::assert<false>::type' 1> with 1> [ 1> T=boost::mpl::int_<2>, 1> U=boost::mpl::integral_c<int,2> 1> ] J-L

Jean-Louis Leroy wrote:
BOOST_MPL_ASSERT((is_same<result_of::size<seq1>::type, result_of::size<seq2>::type>)); }
One would not expect this to fail, however it does :
'boost::mpl::assertion_failed' : cannot convert parameter 1 from 'boost::mpl::failed ************boost::is_same<T,U>::* ***********' to 'boost::mpl::assert<false>::type' 1> with 1> [ 1> T=boost::mpl::int_<2>, 1> U=boost::mpl::integral_c<int,2> 1> ]
This failure is reasonable IMO, the documented return type of size is an MPL integral constant.. Ensuring that the same MPL type is used everywhere would require marginally more TMP overhead, and make things fiddlier for implementers of sequences. We could possibly provide consistent use of the same MPL type for all the Fusion built in sequence types, but I think that would just hide bugs in user code. The comparison should be with mpl::equal_to.
J-L
Cheers Dan

We could possibly provide consistent use of the same MPL type for all the Fusion built in sequence types, but I think that would just hide bugs in user code. The comparison should be with mpl::equal_to.
I see. I had worked around the problem by using value_type instead of just type. I'll use equal_to now. Thanks, J-L
participants (2)
-
dan marsden
-
Jean-Louis Leroy