I'm trying to fill boost::property_tree::ptree with Boost.Assign. So, I got the following worked fine:
namespace bpt = boost::property_tree;
bpt::ptree pt;
boost::assign::make_list_inserter
(boost::bind(&bpt::ptree::put<std::string>, pt, _1, _2))
("one.two.three", "four")
("one.two.five", "six");
However, when I trying to make this code better looking, it fails to compile:
typedef bpt::ptree& (bpt::ptree::*PutType)
(const bpt::path_of<std::string>::type&, const std::string &);
PutType Put = &bpt::ptree::put<std::string>;
inline boost::assign::list_inserter<PutType> put(bpt::ptree &pt) {
PutType putFunction = boost::bind(Put, pt, _1, _2); // !!! compile error
return boost::assign::make_list_inserter(putFunction);
}
//and use it like:
put(pt)
("one.two.three", "four")
("one.two.five", "six");
Error message is
SomeFile.cpp: In function ‘boost::assign::list_inserter<boost::property_tree::ptree& (boost::property_tree::ptree::*)(const boost::property_tree::string_path<std::string, boost::property_tree::id_translator<std::string > >&, const std::string&), boost::assign_detail::forward_n_arguments> put(boost::property_tree::ptree&)’:
SomeFile.cpp:42: error: cannot convert ‘boost::_bi::bind_t<boost::property_tree::ptree&, boost::_mfi::mf2<boost::property_tree::ptree&, boost::property_tree::ptree, const boost::property_tree::string_path<std::string, boost::property_tree::id_translator<std::string > >&, const std::string&>, boost::_bi::list3<boost::_bi::value<boost::property_tree::ptree >, boost::arg<1>, boost::arg<2> > >’ to ‘boost::property_tree::ptree& (boost::property_tree::ptree::*)(const boost::property_tree::string_path<std::string, boost::property_tree::id_translator<std::string > >&, const std::string&)’ in initialization
What is best way to make it code worked?