当我尝试使用以下测试代码的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 );
}
错误信息:
|| === Build:在jtest2中调试(编译器:GNU GCC编译器)=== |
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_ ::中没有名为'type'的类型bool_>'|
|| ===构建失败:2个错误,5个警告(0分钟,0秒(秒))=== |
1 回答
在检查bind的定义和语义之后,需要一个元函数类作为第一个参数,这意味着元函数无法工作;
我们有几种方法可以将元函数转换为matafunction类,在这个例子中,元函数int_plus可以隐藏
1) quote2(int_plus)
2) int_plus_f
3) int_plus_f2