title: Calling a free function instead of a method if it doesn't exist
body: <p>Suppose you have a family of type-unrelated classes implementing a common concept by means of a given method returning a value:</p>
  
  <pre><code>class A { public: int val() const { ... } };
  class B { public: int val() const { ... } };
  </code></pre>
  
  <p>suppose you need a generic free function taking a <code>T</code> returning a conventional value for whatever type NOT implementing the <code>val</code> method or calling the <code>val</code> method for ALL the types that has one:</p>
  
  <pre><code>template&lt;class T&gt; int val_of(const T&amp; t) { return 0; }
  template&lt;class T&gt; int val_of(const T&amp; t) { return t.val(); }
  </code></pre>
  
  <p>Consider that A and B are just samples: you don't know how many types will ever exist implementing <code>val</code>, and how many types will exist not implementing it (hence explicit specialization won't scale).</p>
  
  <p>Is there a simple way, based on the C++ standards, to come to a way to statically select the <code>val_of</code> version? </p>
  
  <p>I was thinking to a <code>std::conditional</code> or <code>std::enable_if</code>, but I didn't find a simple way to express the condition.</p>