majintao0131 / yaml-cpp

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

The templated operator >> should not compile (SFINAE) if there is no Convert() function #126

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

struct A {};
struct B: public A {};

void operator >> (const YAML::Node& node, A& a) {}

int main()
{
  YAML::Node node;
  A a;
  node >> a;
  B b;
  node >> b;

  return 0;
}

What is the expected output? What do you see instead?

The above code does not compile. The error, on the line `node >> b`, is due to 
the `operator >> ` in node.h being an exact match, and hence better than the 
conversion `B&` to `A&`; but then there is no Convert() function for B, so 
compilation of *that* `operator >>` fails.

Instead, use SFINAE to cause the existing `operator >>` not to compile unless 
there is a Convert() function for it.

Original issue reported on code.google.com by jbe...@gmail.com on 1 Nov 2011 at 10:18

GoogleCodeExporter commented 9 years ago
Fixed, r52790a15757d.

Original comment by jbe...@gmail.com on 1 Nov 2011 at 10:19