title: Passing a std::shared_ptr<T> to a function that takes a std::shared_ptr<const T>?
body: <p>I have a function that needs to take shared ownership of an argument, but does not modify it.
  I have made the argument a shared_ptr&lt;const T&gt; to clearly convey this intent.</p>
  <pre><code>template &lt;typename T&gt;
  void func(std::shared_ptr&lt;const T&gt; ptr){}
  </code></pre>
  <p>I would like to call this function with a shared_ptr to a non-const T. For example:</p>
  <pre><code>auto nonConstInt = std::make_shared&lt;int&gt;();
  func(nonConstInt);
  </code></pre>
  <p>However this generates a compile error on VC 2017:</p>
  <pre><code>error C2672: 'func': no matching overloaded function found
  error C2784: 'void func(std::shared_ptr&lt;const _Ty&gt;)': could not deduce template argument for 'std::shared_ptr&lt;const _Ty&gt;' from 'std::shared_ptr&lt;int&gt;'
  note: see declaration of 'func'
  </code></pre>
  <p>Is there a way to make this work without:</p>
  <ul>
  <li>Modifying the calls to func.  This is part of a larger code refactoring, and I would prefer not to have to use std::const_pointer_cast at every call site.</li>
  <li>Defining multiple overloads of func as that seems redundant.</li>
  </ul>
  <p>We are currently compiling against the C++14 standard, with plans to move to c++17 soon, if that helps.</p>