首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Boost Ptree自定义排序

Boost Ptree自定义排序
EN

Stack Overflow用户
提问于 2019-06-27 22:09:19
回答 1查看 294关注 0票数 0

我想使用这个函数并创建一个自定义排序函数,但我不知道Compare函数是如何工作的,也不知道lambda是如何工作的。

有没有人能给我一个使用它的工作示例?

代码语言:javascript
复制
/* 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

代码语言:javascript
复制
  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;
    });
EN

回答 1

Stack Overflow用户

发布于 2019-06-28 20:00:07

我想我找到解决方案了

代码语言:javascript
复制
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")) ...
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56792933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档