How to force class template argument deduction when constructing a class in its own member functions? : <p>Consider following code:</p>

<pre><code>struct A {};

template &lt;typename T&gt; struct B
{
    B(T) {}
    auto foo() {return B(A{});} // error: no matching function for call to 'B&lt;int&gt;::B(A)'
};

auto foo() {return B(A{});} // compiles

int main()
{
    foo();
    B b(0);
    b.foo();
}
</code></pre>

<p><kbd><a href="https://godbolt.org/g/f1sRuk" rel="noreferrer">Try it live</a></kbd></p>

<p>I understand why <code>B::foo()</code> doesn't compile: Inside of <code>struct B&lt;T&gt;</code>, <code>B</code> (as an injected-class-name) means <code>B&lt;T&gt;</code> unless it's explicitly used as a template. Which in this case prevents class template argument deduction.</p>

<p>Let's say I can't do <code>auto foo() {return B&lt;A&gt;(A{});}</code> since my actual code relies on slightly elaborate user-provided deduction guides.</p>

<p>The question is: How do I force class template argument deduction when constructing <code>B</code> inside of <code>B::foo</code>?</p>

<p><sub>I hope I'm not missing something obvious.</sub></p>
