|
Boost Users : |
From: Kiuhnm (kiuhnm03_at_[hidden])
Date: 2006-04-05 14:18:23
I'm using MSVC8 (2005) with Boost 1.33.1.
The code at the end of this post should cause the compiler to print out
something like this (GCC):
conversion from 'mpl_::failed
****************(factorial<mpl_::int_<-5>
>::FACTORIAL_of_NEGATIVE_NUMBER::****************)
(mpl_::int_<-5>)' to non-scalar type 'mpl_::assert<false>'
requested.
but I obtain something completely different.
It seems that the compiler continues to evaluate the factorial (-1, -2, -3,
...) ignoring the assertions. Since the template expansion is quite
"complex", the compiler fails and prints out:
--- fatal error C1202: recursive type or function dependency context too complex c:\boost\include\boost-1_33_1\boost\mpl\aux_\preprocessed\plain\times.hpp(60) : see reference to class template instantiation 'factorial<N>' being compiled with [ N=boost::mpl::int_<-88> ] --- What's wrong? --- #include <boost/mpl/assert.hpp> #include <boost/mpl/greater_equal.hpp> #include <boost/mpl/equal_to.hpp> #include <boost/mpl/multiplies.hpp> #include <boost/mpl/prior.hpp> #include <boost/static_assert.hpp> namespace mpl = boost::mpl; // specializations are nullary metafunctions that compute n>0 template <int n> struct FACTORIAL_of_NEGATIVE_NUMBER : mpl::greater_equal<mpl::int_<n>, mpl::int_<0> > {}; template <class N> struct factorial : mpl::eval_if< mpl::equal_to<N,mpl::int_<0> > , mpl::int_<1> , mpl::multiplies< N , factorial<typename mpl::prior<N>::type> > > { BOOST_MPL_ASSERT((FACTORIAL_of_NEGATIVE_NUMBER<N::value>)); BOOST_STATIC_ASSERT((0)); // !!! BOOST_MPL_ASSERT_MSG(N::value >= 0, FACTORIAL_of_NEGATIVE_NUMBER, (N)); // !!! }; int main() { int f = factorial< mpl::int_<-5> >::type::value; } --- Thank you, Kiuhnm -- View this message in context: http://www.nabble.com/Assertions-doesn%27t-work%21-t1401263.html#a3770376 Sent from the Boost - Users forum at Nabble.com.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net