【发布时间】:2014-01-15 13:46:57
【问题描述】:
我正在尝试用 Boost.Assign 填充 boost::property_tree::ptree。所以,我得到了以下工作正常:
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");
但是,当我试图让这段代码看起来更好看时,它无法编译:
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");
错误信息是
SomeFile.cpp: 在函数'boost::assign::list_inserter<:property_tree::ptree boost::property_tree::string_path string boost::property_tree::id_translator> >&, const std::string&), boost::assign_detail::forward_n_arguments> put(boost::property_tree::ptree&)':
SomeFile.cpp:42: 错误:无法转换 'boost::_bi::bind_t<:property_tree::ptree boost::_mfi::mf2 boost::property_tree ::ptree const boost::property_tree::string_path boost::property_tree::id_translator> >&, const std::string&>, boost::_bi::list3
, boost::arg, boost::arg > >' to 'boost::property_tree::ptree& (boost::property_tree:: ptree::*)(const boost::property_tree::string_path<:string boost::property_tree::id_translator> >&, const std::string&)' 在初始化中
使代码正常工作的最佳方法是什么?
【问题讨论】:
标签: c++ boost boost-bind c++03 boost-propertytree