Boost logo

Boost Users :

Subject: [Boost-users] [PropertyTree] Using with std algorithms
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2011-05-19 10:56:16


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?

Thanks,

- Rob.

#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;

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

> g++ ptree.cpp

ptree.cpp: In function ‘int main()’:
ptree.cpp:15: error: invalid static_cast from type ‘<unresolved overloaded
function type>’ to type ‘boost::property_tree::ptree&
(boost::property_tree::basic_ptree<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::less<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >::*)(const std::string&, unsigned int)’



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