当我尝试使用mpl::bind函数进行以下测试代码时,我未能在gcc编译器中通过, 有人可以帮助我找出问题吗,非常感谢。
#include <iostream>
#include <typeinfo>
#include <string>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/char.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/arg.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/add_pointer.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/quote.hpp>
using namespace std;
using namespace boost::mpl;
template< typename T1,typename T2 >
struct int_plus:boost::mpl::int_< (T1::value+T2::value) >
{
};
int main()
{
typedef boost::mpl::lambda< int_plus<_1, _2 > >::type test1; //-fine
// test2 define is causeing error
typedef boost::mpl::bind < int_plus<_1, _2 > > test2; //-error?
typedef boost::mpl::lambda< quote2<int_plus>, _2, _1 >::type test3; //-fine
typedef boost::mpl::bind< quote2<int_plus>, _2, _1 > test4; //-fine
typedef test1::apply<int_<42>, int_<23>>::type test5; //-fine
typedef test2::apply<int_<42>, int_<23>>::type test6; //-error
typedef test3::apply<int_<42>, int_<24>>::type test7; //-fine
typedef test4::apply<int_<42>, int_<24>>::type test8; //-fine
BOOST_MPL_ASSERT_RELATION( test5::value, ==, 65 ); //-fine
//BOOST_MPL_ASSERT_RELATION( test6::value, ==, 65 );
}
错误信息:
||=== 构建: Debug in jtest2 (编译器: GNU GCC Compiler) ===|
C:\boost\mpl\aux_\preprocessed\gcc\apply_wrap.hpp||在 'struct boost::mpl::apply_wrap0, mpl_::arg<2> >, mpl_::bool_ >' 的实例化中:|
C:\boost\mpl\aux_\_\preprocessed\gcc\bind.hpp|86|要求从 'struct boost::mpl::bind0, mpl_::arg<2> > >::apply, mpl_::int_<23> >' 得到的结构体| C:\ls\jtest2\main.cpp|30|从这里开始需要|
C:\boost\mpl\aux_\preprocessed\gcc\apply_wrap.hpp|20|错误:在 'struct int_plus, mpl_::arg<2> >' 中没有名为 'apply' 的类模板|
C:\boost\mpl\aux_\preprocessed\gcc\bind.hpp||在 'struct boost::mpl::bind0, mpl_::arg<2> > >::apply, mpl_::int_<23> >' 的实例化中:|
C:\ls\jtest2\main.cpp|30|从这里开始需要| C:\boost\mpl\aux_\preprocessed\gcc\bind.hpp|86|错误:在 'struct boost::mpl::apply_wrap0, mpl_::arg<2> >, mpl_::bool_ >' 中没有名为 'type' 的类型|
||=== 构建失败:2 个错误,5 个警告 (0 分钟,0 秒) ===|
test4
是否解决了你在test2
中遇到的问题? - Igor R.