title: Yaml-cpp (new API): Problems mixing maps and scalars in a sequence
body: <p>I have a very simple problem parsing a yaml file of this form:</p>
  
  <pre><code>- Foo
  - Bar:
     b1: 5
  </code></pre>
  
  <p>I would like to parse the top level keys as strings namely "Foo" and "Bar".
  As you can see the first entry in the sequence is a scalar and the second is a map containing one key/value pair.  Let's say I've loaded this YAML text into a node called config.  I iterate over config in the following way:</p>
  
  <pre><code>YAML::Node::const_iterator n_it = config.begin();
  for (; n_it != config.end(); n_it++) {
      std::string name;
      if (n_it-&gt;Type() == YAML::NodeType::Scalar)
          name = n_it-&gt;as&lt;std::string&gt;();
      else if (n_it-&gt;Type() == YAML::NodeType::Map) {
          name = n_it-&gt;first.as&lt;std::string&gt;();
      }
  }
  </code></pre>
  
  <p>The problem is parsing the second "Bar" entry.  I get the following yaml-cpp exception telling me I'm trying to access the key from a sequence iterator n_it.</p>
  
  <pre><code>YAML::InvalidNode: yaml-cpp: error at line 0, column 0: invalid node; this may result from using a map iterator as a sequence iterator, or vice-versa
  </code></pre>
  
  <p>If I change the access to this:</p>
  
  <pre><code>name = n_it-&gt;as&lt;std::string&gt;();
  </code></pre>
  
  <p>I get a different yaml-cpp exception which I guess is due to the fact that I'm trying to access the whole map as a std::string</p>
  
  <pre><code>YAML::TypedBadConversion&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; &gt;: yaml-cpp: error at line 0, column 0: bad conversion
  </code></pre>
  
  <p>Can somebody please explain to me what's going wrong?</p>
  
  <p><strong>Edit: new problems</strong>
  I'm still having problems with this api's handling of maps vs sequences.  Now say I have the following structure:</p>
  
  <pre><code>foo_map["f1"] = "one";
  foo_map["f2"] = "two";
  bar_map["b1"] = "one";
  bar_map["b2"] = "two";
  </code></pre>
  
  <p>I want this to be converted to the following YAML file:</p>
  
  <pre><code>Node: 
      - Foo:
        f1 : one
        f2 : two
      - Bar:
        b1 : one
        b2 : two
  </code></pre>
  
  <p>I would do so by doing:</p>
  
  <pre><code>node.push_back("Foo");
  node["Foo"]["b1"] = "one";
  ...
  node.push_back("Bar");
  </code></pre>
  
  <p>However at the last line node has now been converted from a sequence to a map and I get an exception.  The only way I can do this is by outputting a map of maps:</p>
  
  <pre><code>Node:
      Foo:
        f1 : one
        f2 : two
      Bar:
        b1 : one
        b2 : two
  </code></pre>
  
  <p>The problem with this is if I cannot read back such files.  If I iterate over Node, I'm unable to even get the type of the node iterator without getting an exception.</p>
  
  <pre><code>YAML::Node::const_iterator n_it = node.begin();
  
  for (; n_it != config.end(); n_it++) {
          if (n_it-&gt;Type() == YAML::NodeType::Scalar) {
              // throws exception
          }
      }
  </code></pre>
  
  <p>This should be very simple to handle but has been driving me crazy!</p>