如何使用 std::map 和 boost::phoenix?

How to use std::map with 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 = 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

我目前正在使用 Visual Studio 2015 Community 和 boost 1.60 库。

基于question pointed out by 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] 来确定结果类型,即a std::pair<const int,int> 在这种情况下。但是 std::map<int,int>::at 只是 returns 一个 referenceconst_reference.