title: C++ 11: smart pointer and input parameters - reference or pointer?
body: <p>i'm using the new smart-pointer from C++ 11. I'm now confused what's the best way to pass and input value to an function.</p>
  <p>The standard rule for method/function signatures is</p>
  <blockquote>
  <p>inputs: prefer const reference and pointer where you must (f.e. nullptr is a legal input)</p>
  <p>outputs:  should b e pointers.</p>
  </blockquote>
  <p>But with smart-pointer things are more &quot;complicated&quot;.</p>
  <p>I understand that you should not pass the input as ...</p>
  <ul>
  <li><strong>unique_ptr</strong> where the ownership is not transfered</li>
  <li><strong>shared_ptr</strong> where the object should not be share the ownership.</li>
  </ul>
  <p>... and use referece or pointer instead.</p>
  <p>For me the problem with the standard rule is that the developer who is using the function must dereference the pointer from the smart-pointer and he should always check if the result is not nullptr, so there is an &quot;always&quot; manual checking code.</p>
  <pre><code>void foo(const MyClass&amp; obj)
  {
      ...
  }
  
  void main()
  {
      auto a = make_unique&lt;MyClass&gt;();
      if(*a) // always check dereference
      {
          foo(*a);
      }
  }
  </code></pre>
  <p>Instead, passing the input as const pointer, the usability is easier, but nullptr would be an &quot;legal&quot; value.</p>
  <pre><code>void foo(const MyClass* obj)
  {
      ...
  }
  
  void main()
  {
      auto a = make_unique&lt;MyClass&gt;();
      foo(a.get()); //easier to use, but nullptr is a &quot;legal&quot; value
  }
  </code></pre>
  <p>Can anybody share his opinion when you use pointer, when references and how do you deal with deref's in that case.</p>
  <p>Thanks in advance</p>