title: using declaration in header files
body: <p>I've been looking for some clarification for the usage of the <em>using-declarations</em> in header files (I was searching around but couldn't quite get the answer I'm looking for). What I my research concluded so far is, using them in the <em>non-global</em> scope is ok, while namespace directives are bad. That I understood (At least I hope so :)).</p>
  
  <p>So in my example I use <code>shared_ptr</code>s, but I need to support older compilers that do not have them in the <code>std::</code> namespace but in <code>std::tr1::</code> for example. Since every class using the <code>shared_ptr</code> needs the same <code>shared_ptr</code> defition, I would have to put the correct <code>#include</code> directive and using declaration in each of these header files. So I moved this part into a seperate header file so I have only one single file where I need to make changes. The decision on which <code>shared_ptr</code> to use, is made via a preprocessor directive <code>HAS_SHAREDPOINTER</code>, which is set if the user has a compiler that supports <code>std::shared_ptr</code>.</p>
  
  <p><strong>SharedPtr.h</strong>:</p>
  
  <pre><code>#ifndef SHAREDPTR_H_
  #define SHAREDPTR_H_
  
  #ifdef HAS_SHAREDPOINTER
  #include &lt;memory&gt;
  using std::shared_ptr;
  #else
  #include &lt;tr1/memory&gt;
  using std::tr1::shared_ptr;
  #endif
  
  #endif /* SHAREDPTR_H_ */
  </code></pre>
  
  <p>Now in every header file that uses the shared_ptr, I include this header file. For example in</p>
  
  <p><strong>ModelPar.h</strong>:</p>
  
  <pre><code>#ifndef MODELPAR_H_
  #define MODELPAR_H_
  
  #include &lt;string&gt;
  #include &lt;set&gt;
  
  #include "SharedPtr.h"
  
  class ModelPar {
    private:
      std::set&lt;shared_ptr&lt;ModelPar&gt; &gt; connections;
    ...
  };
  
  #endif /* MODELPAR_H_ */
  </code></pre>
  
  <p>Now I think the way I did it is wrong, since the user that includes any of my header file (using the <code>shared_ptr</code>s) also has the corresponding <strong>using declaration</strong> in his code. And that's the bad thing, as the user is not aware of this... etc. So I put my using declarations in the global scope. Or? I'm kind of stuck and confused on how to do this properly? Thanks in advance!</p>