diff --git a/include/yaml-cpp/node/detail/iterator.h b/include/yaml-cpp/node/detail/iterator.h index 3a98911..dc699f4 100644 --- a/include/yaml-cpp/node/detail/iterator.h +++ b/include/yaml-cpp/node/detail/iterator.h @@ -30,6 +30,8 @@ namespace YAML template friend class iterator_base; struct enabler {}; typedef typename iterator_base::base_type base_type; + + public: typedef typename iterator_base::value_type value_type; public: diff --git a/include/yaml-cpp/node/node.h b/include/yaml-cpp/node/node.h index fd4561d..b6cc1c0 100644 --- a/include/yaml-cpp/node/node.h +++ b/include/yaml-cpp/node/node.h @@ -23,6 +23,9 @@ namespace YAML friend class detail::node_data; template friend class detail::iterator_base; template friend struct as_if; + + typedef iterator iterator; + typedef const_iterator const_iterator; Node(); explicit Node(NodeType::value type); diff --git a/test/new-api/nodetests.cpp b/test/new-api/nodetests.cpp index c74333f..0826174 100644 --- a/test/new-api/nodetests.cpp +++ b/test/new-api/nodetests.cpp @@ -1,5 +1,6 @@ #include "nodetests.h" #include "yaml-cpp/yaml.h" +#include #include namespace { @@ -324,6 +325,18 @@ namespace Test YAML_ASSERT(node[1].as() == YAML::Binary(reinterpret_cast("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.\n"), 270)); return true; } + + TEST ForEach() + { + YAML::Node node = YAML::Load("[1, 3, 5, 7]"); + int seq[] = {1, 3, 5, 7}; + int i = 0; + BOOST_FOREACH(const YAML::Node &item, node) { + int x = seq[i++]; + YAML_ASSERT(item.as() == x); + } + return true; + } } void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) { @@ -373,6 +386,7 @@ namespace Test RunNodeTest(&Node::FallbackValues, "fallback values", passed, total); RunNodeTest(&Node::NumericConversion, "numeric conversion", passed, total); RunNodeTest(&Node::Binary, "binary", passed, total); + RunNodeTest(&Node::ForEach, "for each", passed, total); std::cout << "Node tests: " << passed << "/" << total << " passed\n"; return passed == total;