简体   繁体   English

使用boost :: phoenix :: function解决问题

[英]Troubles with boost::phoenix::function

Using boost::phoenix::function I encountered some problems. 使用boost :: phoenix :: function我遇到了一些问题。 As far as I know this lazy function requiries functor as its template parameter. 据我所知,这个懒函数重新验证函数作为其模板参数。 I have to define a functor class/structure and then pass it as a template parameter for instantiation. 我必须定义一个仿函数类/结构,然后将其作为模板参数传递给实例化。 But it's too long and redundant. 但它太长而且多余。 Can I use some other callable type for phoenix::function creation (function reference/pointer etc.)? 我可以为phoenix::function creation(函数引用/指针等)使用其他一些可调用类型吗? I tried lambdas : 我试过lambdas

 const auto foo = [] { cout <<"Test"; }
 const boost::phoenix::function<decltype(foo)> lazy;

but call to lazy() didn't compile. 但是调用lazy()没有编译。 So the question are there any alternatives instead of functor classes for fast one-line phoenix::function creation? 所以问题是快速单行phoenix::function creation有没有替代functor类的替代品?

由于foo的类型不是默认的可构造的, lazy需要初始化器:

boost::phoenix::function<decltype(foo)> lazy { foo };

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

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