我想使用这个函数并创建一个自定义排序函数,但我不知道Compare函数是如何工作的,也不知道lambda是如何工作的。
有没有人能给我一个使用它的工作示例?
/* Sorts the direct children of this node according to the predicate.
The predicate is passed the whole pair of key and child. */
template <class Compare> void sort (Compare comp);向谓词传递整个键和子项对。
这是一对key/ptree吗?我不知道数据类型是什么。
我正在搜索类似于列表的lambda函数equal
unorderedGenList.sort([](const boost::property_tree::ptree & treeA, const boost::property_tree::ptree & treeB)
{
if(std::stod(treeA.get<std::string>("sortA","0")) < std::stod(treeB.get<std::string>("sortA","0"))
|| (std::stod(treeA.get<std::string>("sortA","0")) == std::stod(treeB.get<std::string>("sortA","0")) && std::stod(treeA.get<std::string>("sortB","0")) < std::stod(treeB.get<std::string>("sortB","0")))
)
return true;
return false;
});发布于 2019-06-28 20:00:07
我想我找到解决方案了
typedef std::pair< const Key, self_type > value_type;
unorderedPtree.sort([](const boost::property_tree::value_type& treeA, const boost::property_tree::value_type & treeB){
treeA.second.get<std::string>("sortB","0")) ...
}https://stackoverflow.com/questions/56792933
复制相似问题