title: Avoid compiling definition of inline function multiple times
body: <p>I have a non-template struct in a header file:</p>
  <pre class="lang-cpp prettyprint-override"><code>struct X {
      constexpr X() : /* ... */ { /* ... */ }
      constexpr void f() {
          // ...
      }
  };
  </code></pre>
  <p>With functions of varying size. This is used in a lot of different translation units, and each function appears in multiple object files for them to be discarded in the final executable.</p>
  <p>What I want is for the definitions to be in a single object file, and the other translation units can either inline the function or use an external definition (something like the <code>extern inline</code> semantics from C). How can I do that?</p>
  <p>It seems to work with templates and <code>extern template</code>:</p>
  <pre class="lang-cpp prettyprint-override"><code>namespace detail {
  
  template&lt;std::nullptr_t&gt;
  struct X_base {
      constexpr X_base() // ...
      constexpr void f() // ...
  };
  
  extern template struct X_base&lt;nullptr&gt;;
  
  }
  
  struct X : detail::X_base&lt;nullptr&gt; {
      using X_base::X_base;
  };
  
  // X.cpp
  #include &lt;X.hpp&gt;
  
  template struct detail::X_base&lt;nullptr&gt;;
  </code></pre>
  <p>But are there any major downsides to this (longer symbol names, confusing to read, needs documentation, etc.), or are there any easier ways to do this?</p>