void write_ini(std::basic_ostream< typename Ptree::key_type::value_type > &stream, const Ptree &pt, int flags = 0) { using detail::check_dupes; typedef typename Ptree::key_type::value_type Ch; typedef std::basic_string<Ch> Str; BOOST_ASSERT(validate_flags(flags)); (void)flags; if (!pt.data().empty()) BOOST_PROPERTY_TREE_THROW(ini_parser_error( "ptree has data on root", "", 0)); check_dupes(pt); for (typename Ptree::const_iterator it = pt.begin(), end = pt.end(); it != end; ++it) { check_dupes(it->second); if (it->second.empty()) { stream << it->first << Ch('=') << it->second.template get_value< std::basic_string<Ch> >() << Ch('\n'); } else { if (!it->second.data().empty()) BOOST_PROPERTY_TREE_THROW(ini_parser_error( "mixed data and children", "", 0)); stream << Ch('[') << it->first << Ch(']') << Ch('\n'); for (typename Ptree::const_iterator it2 = it->second.begin(), end2 = it->second.end(); it2 != end2; ++it2) { if (!it2->second.empty()) BOOST_PROPERTY_TREE_THROW(ini_parser_error( "ptree is too deep", "", 0)); stream << it2->first << Ch('=') << it2->second.template get_value< std::basic_string<Ch> >() << Ch('\n'); } } } }