0

I want to use this Function and make a custom sorting function, but I don't know how the Compare Function works or with a lambda.

Could someone be so kind to give me a working example for using it.

/* 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);

The predicate is passed the whole pair of key and child.

Is this a pair of key/ptree? I don't know how what the datatype is.

Im searching something like a lambda function equal for lists

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

1 Answers1

1

I think i got the Solution

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")) ...
}
MarcelIsi
  • 19
  • 4