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
>::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
#include
#include
#include
#include
#include
namespace mpl = boost::mpl;
// specializations are nullary metafunctions that compute n>0
template <int n>
struct FACTORIAL_of_NEGATIVE_NUMBER
: mpl::greater_equal >
{};
template <class N>
struct factorial
: mpl::eval_if<
mpl::equal_to >
, mpl::int_<1>
, mpl::multiplies<
N
, factorial
>
{
BOOST_MPL_ASSERT((FACTORIAL_of_NEGATIVE_NUMBER));
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.