diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index 7950148..d65e363 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -76,8 +76,13 @@ namespace YAML } static bool decode(const Node& node, std::map& rhs) { + if(node.Type() != NodeType::Map) + return false; + rhs.clear(); - return false; + for(const_iterator it=node.begin();it!=node.end();++it) + rhs[it->first.as()] = it->second.as(); + return true; } }; diff --git a/include/yaml-cpp/node/detail/iterator.h b/include/yaml-cpp/node/detail/iterator.h index 13afb5d..9a6a619 100644 --- a/include/yaml-cpp/node/detail/iterator.h +++ b/include/yaml-cpp/node/detail/iterator.h @@ -23,7 +23,8 @@ namespace YAML iterator_base, node_iterator, V, - std::forward_iterator_tag> + std::forward_iterator_tag, + V> { private: template friend class iterator_base; diff --git a/test/new-api/nodetests.cpp b/test/new-api/nodetests.cpp index 921e983..60a36d8 100644 --- a/test/new-api/nodetests.cpp +++ b/test/new-api/nodetests.cpp @@ -148,6 +148,21 @@ namespace Test YAML_ASSERT(node["primes"].as >() == primes); return true; } + + TEST StdMap() + { + std::map squares; + squares[0] = 0; + squares[1] = 1; + squares[2] = 4; + squares[3] = 9; + squares[4] = 16; + + YAML::Node node; + node["squares"] = squares; + YAML_ASSERT((node["squares"].as >() == squares)); + return true; + } } void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) { @@ -182,6 +197,7 @@ namespace Test RunNodeTest(&Node::SimpleSubkeys, "simple subkey", passed, total); RunNodeTest(&Node::StdVector, "std::vector", passed, total); RunNodeTest(&Node::StdList, "std::list", passed, total); + RunNodeTest(&Node::StdMap, "std::map", passed, total); std::cout << "Node tests: " << passed << "/" << total << " passed\n"; return passed == total;