C++ 如何将std::map与boost::phoenix一起使用?

C++ 如何将std::map与boost::phoenix一起使用?,c++,boost,phoenix,C++,Boost,Phoenix,如何在phoenix lambda函数中使用std::map #include <boost\phoenix.hpp> #include <map> int main() { using namespace boost::phoenix; using namespace boost::phoenix::arg_names; using namespace std; map<int, int> m; auto foo =

如何在phoenix lambda函数中使用
std::map

#include <boost\phoenix.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();
}
#包括
#包括
int main(){
使用名称空间boost::phoenix;
使用名称空间boost::phoenix::arg_名称;
使用名称空间std;
地图m;
自动foo=at(m,3);
foo();
}
为什么它不起作用? 我得到以下错误:

C2440   'return': cannot convert from 'int' to 'std::pair<const _Kty,_Ty> ' xxx c:\lib\boost\phoenix\stl\container\container.hpp    167
C2440“return”:无法从“int”转换为“std::pair”xxx c:\lib\boost\phoenix\stl\container\container.hpp 167
我目前正在使用Visual Studio 2015社区和boost 1.60库。

基于以下方面:

不要使用
at
功能,而是使用
操作符[]

#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";
}
#包括
#包括
int main(){
std::map m;
m[3]=33;
自动foo=boost::phoenix::ref(m)[3];

std::cout请阅读此链接并发布一个可接受的代码示例:现在看起来不错了?它可能使用
std::map::value\u type
来确定结果类型,这是一个
std::pair
,而
std::map::at
只返回对映射类型的引用,即
int&
int const&
。是否可以修复它?我认为phoenix支持所有基本的
std
容器。我现在没有时间检查,但我认为这是类似的。值得指出的是,它有一个限制,即它不能与
cref(m)
一起工作,因为
操作符[]
是一个非常量operation@sehe说得好。弗兰基,我不明白他们为什么要用这种方式实现它,因为任何
容器
都必须有
引用
常量引用
。但我可能遗漏了一些东西。。。