开发者

Problem with BOOST_MPL_ASSERT

开发者 https://www.devze.com 2023-02-24 07:39 出处:网络
Compiles f开发者_如何学Pythonine with gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)/ boost 1.33.1

Compiles f开发者_如何学Pythonine with gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)/ boost 1.33.1

#include <boost/mpl/assert.hpp>

int main()
{
    BOOST_MPL_ASSERT(( mpl::equal_to< mpl::long_<10>, mpl::int_<11> > ));
}

After preprocessing main() looks like:

int main()
{
    enum { mpl_assertion_in_line_5 = sizeof( boost::mpl::assertion_failed<false>( boost::mpl::assert_arg( (void (*) ( mpl::equal_to< mpl::long_<10>, mpl::int_<11> > ))0, 1 ) ) ) };
}

What is wrong?


You could be missing some headers (and this might depend on the exact version of boost - I don't have that one available). This fails to compile properly:

#include <boost/mpl/int.hpp>
#include <boost/mpl/long.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/assert.hpp>

int main()
{
    BOOST_MPL_ASSERT(( boost::mpl::equal_to< boost::mpl::long_<10>, boost::mpl::int_<11> > ));
}

The output is:

# g++ -Wall t.cpp
t.cpp: In function ‘int main()’:
t.cpp:8:2: error: no matching function for call to ‘assertion_failed(mpl_::failed************ boost::mpl::equal_to<mpl_::long_<10l>, mpl_::int_<11> >::************)’

Without the proper headers, various other unrelated compile errors happen.

If you don't want the namespace qualifiers, you can do:

#include <boost/mpl/int.hpp>
#include <boost/mpl/long.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/assert.hpp>

using namespace boost; // brings boost:: into scope

int main()
{
    BOOST_MPL_ASSERT(( mpl::equal_to< mpl::long_<10>, mpl::int_<11> > ));
}

Or even:

#include <boost/mpl/int.hpp>
#include <boost/mpl/long.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/assert.hpp>

using namespace boost::mpl; // brings boost::mpl:: in scope

int main()
{
    BOOST_MPL_ASSERT(( equal_to< long_<10>, int_<11> > ));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号