yaml-cpp doesn't offer generic equality testing for nodes, which is why your initial solution (which would have the best bet of working) didn't work.
Instead, yaml-cpp relies on typed equality testing. E.g., node[5]
will convert all keys to integers to check key equality; it won't convert 5
to a node and then check equality that way. This is why your other solution will usually work - most of your keys are simple scalars, so they can match using std::string
equality.
It appears you really want to "merge" two nodes; this has been on the yaml-cpp issues list for a while: https://code.google.com/p/yaml-cpp/issues/detail?id=41, and there's some discussion there which explains why it's a hard problem.
As a possible workaround, if you know the type of each node, you can explicitly cast before doing your comparison, e.g.:
doc1[it->first.as<T>()] = it->second;