0

我想使用这个函数并制作一个自定义排序函数,但我不知道比较函数是如何工作的或使用 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 函数

  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;
    });
4

1 回答 1

1

我想我得到了解决方案

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")) ...
}
于 2019-06-28T12:00:07.340 回答