title: Is there a canonical way to allow implicit conversion of a non-const template argument type to a const one?
body: <p>I have a function that takes arguments of a specific template type; a simplified version might look like:</p>
  
  <pre><code>#include &lt;type_traits&gt;
  
  template &lt;typename T&gt;
  struct foo
  {
      // default constructor
      foo() { }
  
      // simple copy constructor that can construct a foo&lt;T&gt; from a foo&lt;T&gt;
      // or foo&lt;const T&gt;
      foo(const foo&lt;typename std::remove_const&lt;T&gt;::type&gt; &amp;) { }
  };
  </code></pre>
  
  <p>Functionally, <code>foo</code> behaves similar to a <code>shared_ptr&lt;T&gt;</code>, with some other addon functionality that isn't relevant to this question. The semantics of the function dictate that it prefers to take in a <code>foo&lt;const T&gt;</code>. <code>foo&lt;const T&gt;</code> is implicitly constructible from <code>foo&lt;T&gt;</code>, so I would like to be able to do something like the following:</p>
  
  <pre><code>template &lt;typename T&gt;
  void bar(foo&lt;const T&gt; f) { }
  
  int main()
  {
      bar(foo&lt;const int&gt;()); // fine
      bar(foo&lt;int&gt;());       // compile error
  }
  </code></pre>
  
  <p>This fails because there are no matching overloads for <code>bar</code> that take a <code>foo&lt;int&gt;</code> (even though a <code>foo&lt;const int&gt;</code> could be implicitly constructed from a <code>foo&lt;int&gt;</code>, the overload resolution in concert with template instantiation seems to be stricter than that.</p>
  
  <p>Is there a canonical way to accomplish this? I know that I could introduce a second overload for <code>bar()</code> that takes a <code>foo&lt;T&gt;</code> and dispatches manually to <code>bar(foo&lt;const T&gt;)</code>, but I'd like to avoid the duplication if possible.</p>