I have the following code:
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <sstream>
#include <string>
int main()
{
std::string input("{\"foo\":\"bar\"}");
boost::property_tree::ptree pt;
std::stringstream stream;
stream << input;
boost::property_tree::read_json(stream, pt);
}
In MSVC-11.0 with boost 1.54 this code compiles fine, but in gcc 4.7.2 with boost 1.49 this code gives me the following errors:
In file included from /usr/include/boost/property_tree/json_parser.hpp:14:0, from main.cpp:1: /usr/include/boost/property_tree/detail/json_parser_read.hpp: In instantiation of ‘void boost::property_tree::json_parser::context::a_literal_val::operator()(boost::property_tree::json_parser::context::It, boost::property_tree::json_parser::context::It) const [with Ptree = boost::property_tree::basic_ptree, std::basic_string >; boost::property_tree::json_parser::context::It = __gnu_cxx::__normal_iterator > >]’: /usr/include/boost/spirit/home/classic/core/scanner/scanner.hpp:148:13: required from ‘static void boost::spirit::classic::attributed_action_policy::call(const ActorT&, boost::spirit::classic::nil_t, const IteratorT&, const IteratorT&) [with ActorT = boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val; IteratorT = __gnu_cxx::__normal_iterator > >]’ /usr/include/boost/spirit/home/classic/core/scanner/scanner.hpp:163:13: required from ‘void boost::spirit::classic::action_policy::do_action(const ActorT&, AttrT&, const IteratorT&, const IteratorT&) const [with ActorT = boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val; AttrT = boost::spirit::classic::nil_t; IteratorT = __gnu_cxx::__normal_iterator > >]’ /usr/include/boost/spirit/home/classic/core/composite/actions.hpp:116:17: required from ‘typename boost::spirit::classic::parser_result, ScannerT>::type boost::spirit::classic::action::parse(const ScannerT&) const [with ScannerT = boost::spirit::classic::scanner<__gnu_cxx::__normal_iterator > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme>
, boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >; ParserT = boost::spirit::classic::alternative > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >; ActionT = boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val; typename boost::spirit::classic::parser_result, ScannerT>::type = boost::spirit::classic::match]’ /usr/include/boost/spirit/home/classic/core/composite/alternative.hpp:67:59: recursively required from ‘typename boost::spirit::classic::parser_result, ScannerT>::type boost::spirit::classic::alternative::parse(const ScannerT&) const [with ScannerT = boost::spirit::classic::scanner<__gnu_cxx::__normal_iterator > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >; A = boost::spirit::classic::alternative > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::property_tree::json_parser::context, std::basic_string > >::a_string_val>, boost::spirit::classic::action > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val> >; B = boost::spirit::classic::rule > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>; typename boost::spirit::classic::parser_result, ScannerT>::type = boost::spirit::classic::match]’ /usr/include/boost/spirit/home/classic/core/composite/alternative.hpp:67:59: required from ‘typename boost::spirit::classic::parser_result, ScannerT>::type boost::spirit::classic::alternative::parse(const ScannerT&) const [with ScannerT = boost::spirit::classic::scanner<__gnu_cxx::__normal_iterator > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >; A = boost::spirit::classic::alternative > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::property_tree::json_parser::context, std::basic_string > >::a_string_val>, boost::spirit::classic::action > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val> >, boost::spirit::classic::rule > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t> >; B = boost::spirit::classic::rule > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>; typename boost::spirit::classic::parser_result, ScannerT>::type = boost::spirit::classic::match]’ /usr/include/boost/spirit/home/classic/core/non_terminal/impl/rule.ipp:240:36: required from ‘typename boost::spirit::classic::match_result::type boost::spirit::classic::impl::concrete_parser::do_parse_virtual(const ScannerT&) const [with ParserT = boost::spirit::classic::alternative > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::property_tree::json_parser::context, std::basic_string > >::a_string_val>, boost::spirit::classic::action > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val> >, boost::spirit::classic::rule > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t> >, boost::spirit::classic::rule > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t> >; ScannerT = boost::spirit::classic::scanner<__gnu_cxx::__normal_iterator > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >; AttrT = boost::spirit::classic::nil_t; typename boost::spirit::classic::match_result::type = boost::spirit::classic::match]’ main.cpp:16:1: required from here /usr/include/boost/property_tree/detail/json_parser_read.hpp:105:17: error: no matching function for call to ‘boost::property_tree::basic_ptree, std::basic_string ::push_back(std::pair, std::basic_string >)’ /usr/include/boost/property_tree/detail/json_parser_read.hpp:105:17: note: candidate is: In file included from /usr/include/boost/property_tree/ptree.hpp:516:0, from /usr/include/boost/property_tree/json_parser.hpp:13, from main.cpp:1: /usr/include/boost/property_tree/detail/ptree_implementation.hpp:362:9: note: boost::property_tree::basic_ptree::iterator boost::property_tree::basic_ptree::push_back(const value_type&) [with Key = std::basic_string; Data = std::basic_string; KeyCompare = std::less >; boost::property_tree::basic_ptree::value_type = std::pair, boost::property_tree::basic_ptree, std::basic_string > >] /usr/include/boost/property_tree/detail/ptree_implementation.hpp:362:9: note: no known conversion for argument 1 from ‘std::pair, std::basic_string >’ to ‘const value_type& {aka const std::pair, boost::property_tree::basic_ptree, std::basic_string > >&}’
What am I doing wrong? How can I fix it?