certik / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Overloaded Node subscript operator returns copy instead of reference. #215

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Linux 0.5.1 version complains of returning a temporary reference in a method 
that does this:

const YAML::Node* f( const std::string& key, const YAML::Node& node )
{
   return &node[key];
}

Since the node is passed by reference, I would expect an index into that to 
return a reference and not a copy ( i.e. const Node& operator[] signature).

Original issue reported on code.google.com by rls...@gmail.com on 25 Jul 2013 at 9:16

GoogleCodeExporter commented 9 years ago
Node is a reference type, so you're supposed to copy them. They're cheap to 
copy (since they just copy a pointer).

Original comment by jbe...@gmail.com on 24 Jan 2015 at 11:37