title: Is cbegin/cend not enough for a range based for loop?
body: <p>I have a class, let's call it ConstVector, that only defines cbegin/cend and not begin/end because I don't want to allow modifications to its members after construction. I tried to use the range based for loop like this:</p>
  
  <pre><code>ConstVector const_vector(1, 2, 3);
  for(const auto &amp;x : const_vector)
  ....
  </code></pre>
  
  <p>While the relevant part of the class looks like this:</p>
  
  <pre><code>template&lt;class T&gt;
  class ConstVector
  {
      public:
          ConstVector(std::initializer_list&lt;T&gt; values);
          typename std::vector&lt;T&gt;::const_iterator cbegin(void) const;
          typename std::vector&lt;T&gt;::const_iterator cend(void) const;
  
      private:
          std::vector&lt;T&gt; data;
  };
  
  template&lt;class T&gt;
  ConstVector::ConstVector(std::initializer_list&lt;T&gt; values)
      : data(values)
  {
  }
  
  template&lt;class T&gt;
  typename std::vector&lt;T&gt;::const_iterator ConstVector&lt;T&gt;::cbegin() const
  {
      return this-&gt;data.cbegin();
  }
  
  template&lt;class T&gt;
  typename std::vector&lt;T&gt;::const_iterator ConstVector&lt;T&gt;::cend() const
  {
      return this-&gt;data.cend();
  }
  </code></pre>
  
  <p>But my compiler complains:</p>
  
  <pre><code>‘begin’ was not declared in this scope
  </code></pre>
  
  <p>My question is: Do I have to implement begin/end? As far as I understood it, it should choose cbegin/cend if it's <code>const auto &amp;x</code> and not <code>auto &amp;x</code>. At least that's what would make sense to me. If I remove my range based for loop, everything compiles fine.</p>
  
  <p>I also tried pretty much everything suggested <a href="https://stackoverflow.com/q/15518894/7421666">here</a> to make it <code>const</code>, but that didn't help.</p>