如何使用std::map和boost::phoenix
How to use std::map with boost::phoenix?
如何在phoenix lambda函数中使用std::map
?
#include <boostphoenix.hpp>
#include <map>
int main() {
using namespace boost::phoenix;
using namespace boost::phoenix::arg_names;
using namespace std;
map<int, int> m;
auto foo = at(m, 3);
foo();
}
为什么它不起作用?我得到以下错误:
C2440 'return': cannot convert from 'int' to 'std::pair<const _Kty,_Ty> ' xxx c:libboostphoenixstlcontainercontainer.hpp 167
我目前正在使用Visual Studio 2015社区和boost 1.60库。
基于jv_提出的问题
与其使用at
函数,不如使用operator[]
。
#include <boost/phoenix.hpp>
#include <map>
int main() {
std::map<int, int> m;
m[3] = 33;
auto foo = boost::phoenix::ref(m)[3];
std::cout << foo() << "n";
}
phoenix at
懒惰函数的实现使用value_type
[1][2]来确定结果类型,在这种情况下是std::pair<const int,int>
。然而,std::map<int,int>::at
只是返回一个reference
或const_reference
。
相关文章:
- 如果功能超载,则BOOST PHOENIX成员功能操作员无法编译
- boost::spirit::qi and boost::phoenix::push_back
- 如何创建Boost Phoenix Make_shared
- boost :: phoenix ::功能遇到麻烦
- 如何使用std::map和boost::phoenix
- 使用 boost.phoenix 容器算法
- 在 Qi 中使用 Boost Phoenix 在语法中引用以前的匹配项
- 如何将命名函数发送到boost::phoenix表达式
- boost::phoenix用作函数时出现错误消息
- 在Boost Phoenix中获取局部变量的类型
- 如何在生成boost::spirit::karma时避免boost::phoenix
- boost::bind、boost::lambda::bind和boost::phoenix::bind的区别
- 变量隐藏在Boost Phoenix的嵌套let块中
- ' boost::phoenix::static_cast_ '与标准库混合使用
- 如何使用Boost::Phoenix传递函数参数
- 使用boost::lambda或boost::phoenix与std::find_if
- boost::phoenix with VS2008
- 在boost::phoenix::lambda中调用函数
- 使用 Boost.Phoenix 的运算符 ->*
- 在Boost Phoenix表达式中转换函数体