Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;Boost::MPL折叠示例-参数数目错误_C++_Templates_Boost_Metaprogramming_Boost Mpl - Fatal编程技术网

C++ C++;Boost::MPL折叠示例-参数数目错误

C++ C++;Boost::MPL折叠示例-参数数目错误,c++,templates,boost,metaprogramming,boost-mpl,C++,Templates,Boost,Metaprogramming,Boost Mpl,我想使用boost::mpl::fold处理一些模板参数。目前,我仍然坚持使用Boost提供的示例,因为即使这样也不适合我。我得到以下错误: ..\src\main.cpp:18:32: error: template argument 2 is invalid ..\src\main.cpp:18:37: error: wrong number of template arguments (4, should be 3) 以下代码取自 #包括 #包括 #包括 #包括 #包括 #包括 使用名称

我想使用boost::mpl::fold处理一些模板参数。目前,我仍然坚持使用Boost提供的示例,因为即使这样也不适合我。我得到以下错误:

..\src\main.cpp:18:32: error: template argument 2 is invalid
..\src\main.cpp:18:37: error: wrong number of template arguments (4, should be 3)
以下代码取自

#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间boost;
使用名称空间boost::mpl;
使用名称空间boost::type_traits;
类型定义向量类型;
typedef折叠<
类型
,int_
,如果
>::键入浮点数;
BOOST\u MPL\u ASSERT\u关系(浮点数::value,==,4);
int main(){
}

我正在使用“-std=c++11”标志运行mingw4.7.0。我在网上找到了一些其他的例子,但还没有成功地编译出任何有用的东西。有什么建议吗?

你把名称空间搞砸了。使许多符号模棱两可

使用删除
,该示例对我来说效果很好

...
using namespace boost;

typedef mpl::vector<long,float,short,double,float,long,long double> types;
typedef mpl::fold<
    types
    , mpl::int_<0>
    , mpl::if_< is_float<boost::mpl::_2>,boost::mpl::next<boost::mpl::_1>,boost::mpl::_1 >
>::type number_of_floats;
...
。。。
使用名称空间boost;
typedefmpl::向量类型;
typedefmpl::fold<
类型
,mpl::int_
,mpl::如果
>::键入浮点数;
...

你的例子看起来不错:(注意C++链接的版本是旧的标准不是11)OK,STD和Boost都是个坏主意。没想到,非常感谢!
...
using namespace boost;

typedef mpl::vector<long,float,short,double,float,long,long double> types;
typedef mpl::fold<
    types
    , mpl::int_<0>
    , mpl::if_< is_float<boost::mpl::_2>,boost::mpl::next<boost::mpl::_1>,boost::mpl::_1 >
>::type number_of_floats;
...