Yes it does. The real change here is std::make_pair
.
C++11 changed std::pair
conversion rules, as well as the make_pair
convenience function, which was made move-aware.
Analyzing It
Property Tree allows construction like this:
ptree pt("data");
to construct a tree with only value data and no child nodes. However, the indirect conversion for the second
member of the pair doesn't apply in c++11 mode:
std::pair<std::string, ptree> v = std::make_pair("a", "b");
This line would have compiled in c++03, but no longer compiles in c++11
Isolating It
To find out whether it might be a libstdc++ or compiler bug, I isolated it into this minimal sample:
#include <utility>
#include <string>
struct X {
X(std::string){}
};
int main() {
std::pair<std::string, X> v = std::make_pair("a", "b");
}
Note the subtle point that it doesn't matter that the constructor isn't explicit
like with the ptree(data_type const&)
constructor. The additional implicit conversion char const(&)[] -> std::string
required is enough to cause c++11 to reject the call.
This compiles in c++03 but fails in c++11 under GCC with libstdc++.
Just to check, clang agrees even when using libc++ instead of libstdc++.
At I bet this is by design and probably a result of making std::make_pair
more precise and aware of move-semantics.
How To Fix
The workarounds are manifold. Convert explicitly:
b.push_back(std::make_pair("a", ptree("b")));
Making types explicit always helps:
b.push_back(ptree::value_type {"a", "b"});
Uniform initialization removes some cruft:
b.push_back({"a", ptree{"b"}});
For completeness, non-explicit constructors are more flexible:
b.push_back({"a", {}});
Or you can avoid the pair<>
(value_type
) interface altogether:
b.add_child("a", ptree{"b"});
b.add_child("a", {}).put_value("b");
But the real key here is that value nodes cannot have children. Why not just put the value?
b.add("a", "b");
This is my RECOMMENDATION. I feel std::pair<>
is an implementation detail only useful to interoperate with other generic code. It hurts readability.
Live Demo
All the workarounds happily living together Live On Coliru
Prints
<?xml version="1.0" encoding="utf-8"?>
<a>b</a>
<a>b</a>
<a>b</a>
<a/>
<a>b</a>
<a>b</a>
<a>b</a>