【发布时间】:2014-04-14 23:26:36
【问题描述】:
当我使用以下测试代码尝试 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 );
}
错误信息:
||=== 构建:在 jtest2 中调试(编译器:GNU GCC 编译器)===|
C:\boost\mpl\aux_\preprocessed\gcc\apply_wrap.hpp||在'struct boost::mpl::apply_wrap0, mpl_::arg, mpl_::bool_ >'的实例化中: |
C:\boost\mpl\aux_\preprocessed\gcc\bind.hpp|86|需要来自 'struct boost::mpl::bind0, mpl_::arg > >::apply, mpl_:: int_ >'| C:\ls\jtest2\main.cpp|30|从这里需要|
C:\boost\mpl\aux_\preprocessed\gcc\apply_wrap.hpp|20|错误:'struct int_plus, mpl_::arg >'中没有名为'apply'的类模板|
C:\boost\mpl\aux_\preprocessed\gcc\bind.hpp||在实例化'struct boost::mpl::bind0, mpl_::arg >::apply, mpl_:: int_ >':|
C:\ls\jtest2\main.cpp|30|从这里需要| C:\boost\mpl\aux_\preprocessed\gcc\bind.hpp|86|错误:在 'struct boost::mpl::apply_wrap0、mpl_::arg >、mpl_:: 中没有名为 'type' 的类型bool_ >'|
||=== 构建失败:2 个错误,5 个警告(0 分钟,0 秒)===|
【问题讨论】:
-
你能发布完整的错误信息吗?您所显示的只是有关编译器在遇到错误时实例化模板的位置的信息。
-
test4不能解决您遇到的test2的问题吗? -
是的,test4 工作正常,test1、test3 都工作。我无法理解 test2,也许我偷了更多关于 mpl::bind 的检查
-
我已更新问题以包含完整的测试代码和错误消息。