title: Parse a YAML list of dictionaries in C++
body: <p>I have the following yaml (a simplified version of my case):</p>
  
  <pre><code>---
  my_list:
      - item1:
          name: name1
      - item2:
          name: name2
  </code></pre>
  
  <p>And then I am trying to parse it like this using C++ and YAML-CPP:</p>
  
  <pre><code>for (const auto &amp; p : node["my_list"]) {
      std::cout &lt;&lt; p.IsMap() &lt;&lt; std::endl;
      YAML::Node key = p.first;
      YAML::Node value = p.second;
  }
  </code></pre>
  
  <p>This apparently works (<code>IsMap()</code> returns 1), but as soon as I do: <code>p.first.as&lt;std::string&gt;();</code> it crashes. How should I parse this?</p>
  
  <p>On the contrary, if I do:</p>
  
  <pre><code>for (auto it = node.begin(); it != node.end(); ++it) {
      YAML::Node key = it-&gt;first;
      YAML::Node value = it-&gt;second;
      std::cout &lt;&lt; key.as&lt;std::string&gt;() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>And the output here is <code>my_list</code>, so I can continue the parsing.</p>
  
  <p>My question is: how can I parse using the <code>C++11</code> range for loop? Thanks</p>