title: About using directives in namespace in header files
body: <p>(This is kind of related to a <a href="https://stackoverflow.com/questions/69158170/alleviate-long-qualifications-in-header-files/69182472#69182472">previous question</a>.)</p>
  <p>Core guideline <a href="http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rs-using-directive" rel="nofollow noreferrer">SF.7</a> gives a good motivation for avoiding to put <code>using namespace</code> directives at global scope in a header file.</p>
  <p>However, even writing <code>using namespace</code> in a non-global namespace can be problematic. For example:</p>
  <ul>
  <li><code>header1.hpp</code>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;boost/hana/transform.hpp&gt;
  namespace ab {
      using namespace boost::hana;
      inline constexpr auto a = transform;
  }
  </code></pre>
  </li>
  <li><code>header2.hpp</code>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;range/v3/view/transform.hpp&gt;
  namespace ab {
      using namespace ranges::views;
      inline constexpr auto b = transform;
  }
  </code></pre>
  </li>
  <li><code>main.cpp</code>
  <pre><code>#include &quot;header1.hpp&quot;
  #include &quot;header2.hpp&quot;
  // here ab::b is ambiguous
  int main() {
  }
  </code></pre>
  with error (from clang)
  <pre><code>In included file: reference to 'transform' is ambiguous
  /home/enrico/header2.hpp:4:31:
  note: error occurred here
  /usr/include/boost/hana/fwd/transform.hpp:53:27:
  note: candidate found by name lookup is 'boost::hana::transform'
  :567:46:
  note: candidate found by name lookup is 'ranges::views::transform'
  </code></pre>
  </li>
  </ul>
  <p>Is there a reason why the guidelines don't mention this?</p>
  <p>Should we entirely avoid <code>using namespace n;</code>/<code>using n::x;</code>/<code>namespace n = m;</code> at namespace scope?</p>
  <hr />
  <h1>Related</h1>
  <p>In <a href="https://stackoverflow.com/q/69158170/5825294">this question of mine</a> I have self-answerd with a way to use those directives when defining an object in a header file, but without cluttering anything, by wrapping all RHS of assignment in a <code>void</code>-to-<code><i>desired-object</i></code> lambda called in place.</p>