title: What is going on with __vector_base_common?
body: <p>I wanted to see at how C++ vector is made. I found this,
  Implementation is LLVM compiler <a href="https://llvm.org/svn/llvm-project/libcxx/trunk/src/vector.cpp" rel="nofollow noreferrer">https://llvm.org/svn/llvm-project/libcxx/trunk/src/vector.cpp</a> appleclang</p>
  
  <p>src/vector.cpp:</p>
  
  <pre><code>#include "vector"
  
  _LIBCPP_BEGIN_NAMESPACE_STD
  
  template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __vector_base_common&lt;true&gt;;
  
  _LIBCPP_END_NAMESPACE_STD
  </code></pre>
  
  <p>Implementation <a href="https://llvm.org/svn/llvm-project/libcxx/trunk/include/vector" rel="nofollow noreferrer">https://llvm.org/svn/llvm-project/libcxx/trunk/include/vector</a> appleclang LLVM.</p>
  
  <p>include/vector:</p>
  
  <pre><code>// .. deleted code
  
  template &lt;bool&gt;
  class __vector_base_common
  {
  protected:
      _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
      _LIBCPP_NORETURN void __throw_length_error() const;
      _LIBCPP_NORETURN void __throw_out_of_range() const;
  };
  
  template &lt;bool __b&gt;
  void
  __vector_base_common&lt;__b&gt;::__throw_length_error() const
  {
      _VSTD::__throw_length_error("vector");
  }
  
  template &lt;bool __b&gt;
  void
  __vector_base_common&lt;__b&gt;::__throw_out_of_range() const
  {
      _VSTD::__throw_out_of_range("vector");
  }
  
  _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common&lt;true&gt;)
  
  // .. deleted code
  
  template &lt;class _Tp, class _Allocator&gt;
  class __vector_base
      : protected __vector_base_common&lt;true&gt;
  
  // .. deleted code
  
  class _LIBCPP_TEMPLATE_VIS vector
      : private __vector_base&lt;_Tp, _Allocator&gt;
  
  // .. deleted code
  </code></pre>
  
  <p>I have many questions how a vector is made.. it feel embarrassing to ask even one.. but.. why is __vector_base_common taking bool template parameter? It doesn't seem to use it, and I verified only use in code is <code>__vector_base_common&lt;true&gt;</code>, the <code>false</code> value is not used.</p>
  
  <p><em>Edit:</em> There have been multiple suggestion relating <code>vector&lt;bool&gt;</code> to this. Only one specialisation of the above bool parameter is used (<code>true</code>). This is what vector special looks like</p>
  
  <pre><code>template &lt;class _Allocator&gt;
  class _LIBCPP_TEMPLATE_VIS vector&lt;bool, _Allocator&gt;
      : private __vector_base_common&lt;true&gt;
  </code></pre>
  
  <p>The difference looks between private versus protected... Is this a space optimisation for vector not needing those throwing member functions? Still I have question why <code>__vector_base_common</code> needs a template parameter. Is this C++ pattern with a name?</p>