title: Customization point with user-defined implementation within a designated namespace
body: <p>Is it possible to provide a customized implementation within a user-defined namespace?
  For example, I want a user to implement customization points within a specific namespace, for example <code>namespace custom</code>.</p>
  <p>This is an example that works, but not the way I would like to have it:</p>
  <pre><code>#include &lt;iostream&gt;
  
  namespace custom
  {
      // this does not help. Will result in undefined symbol
      template &lt;typename T&gt;
      void print(const T&amp;);
  }
  
  namespace eld
  {
      namespace detail
      {
          template&lt;typename T&gt;
          void print(const T &amp;)
          {
              std::cout &lt;&lt; &quot;Generic version&quot; &lt;&lt; std::endl;
          }
  
          struct print_fn
          {
              template&lt;typename T&gt;
              void operator()(const T &amp;t) const
              {
                  // using custom::print; // this will result in undefined symbol
                  print(t);
              }
          };
  
          template&lt;typename T&gt;
          struct static_constexpr
          {
              static constexpr T value{};
          };
  
          template&lt;typename T&gt;
          constexpr T static_constexpr&lt;T&gt;::value;
      }
  
      namespace
      {
          constexpr const auto &amp;print = detail::static_constexpr&lt;detail::print_fn&gt;::value;
      }
  }
  
  struct foo
  {
  };
  
  namespace custom
  {
      // this will never be called
      void print(foo) { std::cout &lt;&lt; &quot;Custom Implementation for foo&quot; &lt;&lt; std::endl; }
  
      struct bar{};
  
      void print(bar)
      {
          std::cout &lt;&lt; &quot;Custom implementation with ADL for custom::bar&quot; &lt;&lt; std::endl;
      }
  }
  
  // this will be called
  void print(foo) { std::cout &lt;&lt; &quot;Implementation for foo&quot; &lt;&lt; std::endl; }
  
  int main(int, char **)
  {
      eld::print(4);
      eld::print(foo());
      eld::print(custom::bar());
  
      return 0;
  }
  </code></pre>
  <p>The output:</p>
  <pre><code>Generic version
  Implementation for foo
  Custom implementation with ADL for custom::bar
  </code></pre>
  <p>What I <strong>want</strong> is for <code>custom::print(foo)</code> to be used. It is a preferred way, since some other functions with the same name may be visible in a global namespace. I might use some name prefixes to circumvent this problem, but I'd rather use a designated namespace. Is it possible? (11, 14, 17 Standard)</p>
  <hr />
  <p>This is an approach I use now, which works but has some inconveniences:</p>
  <ul>
  <li>a user must &quot;copy-paste&quot; forward declaration of a class template in order to customize it, if a header with implementation is used as a standalone header.</li>
  </ul>
  <pre><code>#include &lt;iostream&gt;
  
  namespace eld
  {
      namespace custom
      {
          template &lt;typename T&gt;
          struct print
          {
              void operator()(const T&amp;)
              {
                  std::cout &lt;&lt; &quot;Generic version&quot; &lt;&lt; std::endl;
              }
          };
      }
  
      template &lt;typename T&gt;
      void print(const T&amp; t)
      {
          eld::custom::print&lt;T&gt;{}(t);
      }
  }
  
  struct foo
  {
  };
  
  template &lt;&gt;
  struct eld::custom::print&lt;foo&gt;
  {
      void operator()(const foo&amp;)
      {
          std::cout &lt;&lt; &quot;Custom Implementation for foo&quot; &lt;&lt; std::endl;
      }
  };
  
  int main(int, char **)
  {
      eld::print(4);
      eld::print(foo());
  
      return 0;
  }
  </code></pre>
  <p><a href="https://godbolt.org/z/jb5rbbY7a" rel="nofollow noreferrer">https://godbolt.org/z/jb5rbbY7a</a></p>