title: How to forward a call to a member function template that can be const or non const depending on the template type?
body: <p>I have something similar to this (stripped down example to the relevant points)</p>
  <pre><code>struct Foo
  {
  
      template &lt;typename T&gt;
      constexpr std::enable_if&lt;someTrait&lt;T&gt;::value ,T&gt;::type&amp; get() const { return something(); }
  
      template &lt;typename T&gt;
      std::enable_if&lt;someOtherTrait&lt;T&gt;::value ,T&gt;::type&amp; get() { return somethingDifferent(); }
  
      class Nested
      {
      public:
          template &lt;typename T&gt;
          T&amp; get() { return foo.get&lt;T&gt;(); }
  
      private:
          Foo&amp; foo;
      }
  } 
  
  </code></pre>
  <p>e.g. <code>Foo::get</code> evaluates to a const constexpr function or something completely non-const depending on the template type.</p>
  <p>Now I want to be able to do this</p>
  <pre><code>class Bar : public Foo::Nested
  {
      void nonConstFn()
      {
           auto&amp; a = get&lt;TypeA&gt;();
           //...
      }
  
      void constFn() const // &lt;===== Won't compile
      {
           auto&amp; a = get&lt;TypeA&gt;();
           //...
      }
  }
  </code></pre>
  <p>It's obvious that <code>Bar::constFn</code> won't compile as it calls the non-const function <code>Foo::Nested::get&lt;TypeA&gt;</code> – even if <code>TypeA</code> would satisfy <code>someTrait</code> and call the const function <code>constexpr Foo::get&lt;TypeA&gt;() const</code> again in the end.</p>
  <p>Leaving the constexpr aside for now, how do I propagate the constness of the called function in my nested class' function template? I tried simply overloading it with a const and non-const version of <code>Nested::get</code> which solves it for clang on macOS but fails with MSVC in Visual Studio 2015 on Windows, which is unfortunately a required build target.</p>
  <p>Note that the original example contains a lot more than just two versions of <code>Foo::get</code> so I'd like to avoid repeating all versions in <code>Foo::Nested</code> but forward it with one or two function templates if possible</p>
  <p>Edit: I tried the proposal to use</p>
  <pre><code>template &lt;typename T&gt;
  constexpr auto get() const -&gt; decltype(foo.get&lt;T&gt;()) { return foo.get&lt;T&gt;(); }
  
  template &lt;typename T&gt;
  constexpr auto get() -&gt; decltype(foo.get&lt;T&gt;()) { return foo.get&lt;T&gt;(); }
  
  </code></pre>
  <p><a href="https://godbolt.org/z/jxehYq" rel="nofollow noreferrer">on godbolt.org</a> which seems to compile fine for current MSVC versions but fails with Visual Studio 2015 MSVC 19.0, so this is no option</p>