title: Concept and GCC implementation of std::vector
body: <p>Let's try to create a pointer-like type matching
  both the <a href="http://en.cppreference.com/w/cpp/concept/RandomAccessIterator" rel="nofollow">RandomAccessIterator</a>
  and the <a href="http://en.cppreference.com/w/cpp/concept/NullablePointer" rel="nofollow">NullablePointer</a> concepts.
  The goal here is to create a custom <a href="http://en.cppreference.com/w/cpp/concept/Allocator" rel="nofollow">Allocator</a>
  in order to use the std::vector with a our pointer-like type. You can found the snippet <a href="https://gist.github.com/Nemikolh/7263805" rel="nofollow">here</a></p>
  
  <p>The problem arises when trying to compile this code :</p>
  
  <pre class="lang-c prettyprint-override"><code>int main()
  {
       std::vector&lt;float, allocator&lt;float&gt;&gt; t {0.f, 0.f};
  }
  </code></pre>
  
  <p>We get the following error message :
  </p>
  
  <pre><code>/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_vector.h:173:6: error: 
    value of type 'pointer' (aka 'ptr_like&lt;int&gt;') is not contextually convertible
    to 'bool'
      if (__p)
  </code></pre>
  
  <p>Here we see that our type must be bool convertible. That's not hard to do,
  and if people have an instance of our pointer type, they're likely going to use it like this anyway.
  Thus let's do it and uncomment the following to our snippet :</p>
  
  <pre class="lang-c prettyprint-override"><code>// In detail::ptr_like we add :
  operator bool() const;
  </code></pre>
  
  <p>And we get the following error with clang :</p>
  
  <pre class="lang-bsh prettyprint-override"><code>/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_vector.h:168:25: error: 
    conditional expression is ambiguous; 'pointer' (aka 'ptr_like&lt;int&gt;') can be
    converted to 'int' and vice versa
    { return __n != 0 ? _M_impl.allocate(__n) : 0; }
  </code></pre>
  
  <p>Clang's error shows us exactly why we get into trouble here.
  Now the only viable solutions that I've found are the following :</p>
  
  <ul>
  <li>Replacing <code>0</code> with the c++11 keyword <code>nullptr</code> when c++11 is requested</li>
  <li>Replacing <code>0</code> by a cast to the pointer type <code>static_cast&lt;pointer&gt;(0)</code></li>
  <li>Updating the concept requirement for pointer in the Allocator concept.</li>
  <li>No using the constructor with <code>std::initializer_list</code> (sad)</li>
  </ul>
  
  <p>Is it wrong to defines custom pointers in C++ ?</p>
  
  <p>Is it a bug ?</p>