简体   繁体   English

BOOST_PHOENIX_ADAPT_FUNCTION导致无效的模板错误

[英]BOOST_PHOENIX_ADAPT_FUNCTION causes invalid template error

I am trying to create a lazy function from a template function following the Boost::phoenix documentation. 我试图在Boost :: phoenix文档之后从模板函数创建一个惰性函数。 The code looks like this 代码看起来像这样

#include <iostream>

#include <boost/phoenix/core.hpp>
#include <boost/phoenix/function.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/phoenix/statement.hpp>
#include <boost/phoenix/object.hpp>
#include <boost/phoenix/function/adapt_function.hpp>
#include <boost/phoenix/core/argument.hpp>

using namespace boost;
using namespace boost::phoenix;

namespace demo
{
     bool func(double a,double b)
     {
         return bool(a > b);
     }
}

BOOST_PHOENIX_ADAPT_FUNCTION( bool , func , demo::func , 2)

int main(int argc,char **argv)
{
     namespace pl = boost::phoenix::placeholders;
     auto comperator = func(pl::arg1,pl::arg2);
     std::cout<<comperator(1.2,12.4)<<std::endl;
     std::cout<<comperator(0.5,0.1)<<std::endl;
}

This is virtually one of the examples from the BOOST documentation. 这实际上是BOOST文档中的一个示例。 Storing this file as mk_lazy1.cpp and try to compile gives 将此文件存储为mk_lazy1.cpp并尝试编译给出

$ g++ -omk_lazy1 mk_lazy1.cpp                 
mk_lazy1.cpp:26:1: error: template argument 1 is invalid      
mk_lazy1.cpp:26:1: error: expected identifier before ‘::’ token  
mk_lazy1.cpp:26:1: error: expected initializer before ‘const’ 
mk_lazy1.cpp: In function ‘int main(int, char**)’:
mk_lazy1.cpp:31:10: error: ‘comperator’ does not name a type    
mk_lazy1.cpp:32:35: error: ‘comperator’ was not declared in this scope   

I use gcc-4.7 on a Debian testing system. 我在Debian测试系统上使用gcc-4.7。 An honestly I am a bit lost as I have absolutely no idea what is wrong here (as I said, this is virtually a word by word copy of one of the examples provided by the Boost documentation). 说实话,我有点迷失,因为我完全不知道这里有什么问题(正如我所说,这实际上是Boost文档提供的一个例子的逐字复制)。

Does anyone have a good idea? 有没有人有个好主意?

Remove using namespaces and all will work fine. 删除使用命名空间,一切都会正常工作。 Or write using namespaces AFTER adapt macro and all will work fine too. 或者使用命名空间写入AFTER adapt宏,所有这些都可以正常工作。 Or put macro into unnamed namespace. 或者将宏放入未命名的命名空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM