Boost logo

Boost Users :

Subject: Re: [Boost-users] [PropertyTree] Using with std algorithms
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2011-05-19 13:00:11


On 19.05.2011, at 10:52, Robert Jones wrote:

> On Thu, May 19, 2011 at 5:24 PM, Sebastian Redl <sebastian.redl_at_[hidden]> wrote:
>
> On 19.05.2011, at 08:56, Robert Jones wrote:
>
>> Hi All
>>
>> Is it possible and practical to use the put and get methods of Boost.PropertyTree with std
>> algorithms?
>>
>> I've written this snippet, which doesn't compile, which I think is because I have not correctly
>> expressed the return type of "put()". Is it possible to do this?
>
> Yes, the put() overloads all return the affected tree node.
>
>> for_each( boost::begin( v ), boost::end( v ),
>> bind( static_cast<void (ptree::*)( const std::string &, unsigned )>( & ptree::put ), boost::ref( tree ), "Values.value", _1 ) );
>
> Try this:
>> static_cast<ptree& (ptree::*)(...)>
>
>
> Hi Sebstian
>
> Thanks for that, I thought that should work too, but seems there's still an overload problem!
>
> #include <algorithm>
> #include <vector>
> #include <boost/range.hpp>
> #include <boost/bind.hpp>
> #include <boost/property_tree/ptree.hpp>
>
> int main( )
> {
> using boost::property_tree::ptree;
>
> std::vector<unsigned> v;
> ptree tree;
>
> ptree & ( ptree::*myput )( const std::string &, unsigned ) = & ptree::put;

The first argument should be a ptree::path_type (= string_path<char>), not std::string.

Sebastian



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net