gpt4 book ai didi

c++ - 结合 boost unordered_map、bind 和 std::find_if

转载 作者:行者123 更新时间:2023-11-30 05:42:28 26 4
gpt4 key购买 nike

我有一个很大的 boost::unordered_map 容器,如下所示:

typedef boost::unordered_map< vertex, entity > vertex_container; 

顶点类有一个坐标成员变量表示它的位置。我有几个坐标点_(s)。我想搜索我的容器内是否存在任何顶点,以便 vertex.coordinate = point。

类似于:

vertex_container::iterator it = std::find_if(v_container.begin(), v_container.end(), boost::bind(&Vertex::coordinate(), _1) == point);

但它失败了。

我试过:

vertex_container::iterator it = std::find_if(v_container | boost::adaptors::map_keys(boost::bind(&vertex::coordinate(), _1)) == point);

error: cannot call member function ‘mesh::coordinate mesh::Vertex::coordinate() const’ without object.

我以某种方式尝试组合 boost unordered_map、bind 和 std::find_if。

注意 我只能使用 C++09 标准和 boost 1.53.0 版本。

最佳答案

您需要做的是首先将键绑定(bind)到unordered_map 之外,然后再绑定(bind)成员函数。

vertex_container::iterator it = std::find_if( v_container.begin(), v_container.end(), (boost::bind(&vertex::coordinate, (boost::bind( &vertex_container::value_type::first, _1))) == point) );

而且你不能在 std::find_if 中使用管道。

关于c++ - 结合 boost unordered_map、bind 和 std::find_if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30641066/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com