<html>
<head>
<title>N4132: Contiguous Iterators</title>

<style type="text/css">
  ins { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .new { text-decoration:none; font-weight:bold; background-color:#D0FFD0 }
  del { text-decoration:line-through; background-color:#FFA0A0 }  
  strong { font-weight: inherit; color: #2020ff }
</style>
</head>

<body>
N4132<br/>
Jens Maurer<br/>
2014-09-10<br/>

<h1>N4132: Contiguous Iterators</h1>

<h2>Introduction</h2>

There are <strong>four</strong> containers in the standard library
that guarantee contiguous storage: <code>vector</code>,
<code>string</code>, <strong><code>valarray</code></strong>, and
<code>array</code>.  In the Library Fundamentals TS, there is also
<code>string_view</code>.  This paper introduces the term "contiguous
iterator" as a refinement of random-access iterator, without
introducing a corresponding <code>contiguous_iterator_tag</code>,
which was found to break code during the Issaquah discussions of Nevin
Liber's paper <a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3884.pdf">N3884</a>
"Contiguous Iterators: A Refinement of Random Access Iterators".



<h2>Wording Changes</h2>

<strong>Change in 24.2.1 [iterator.requirements.general] paragraph 2
and adjust the table accordingly:</strong>

<blockquote>
... This International Standard defines <del>five</del> <ins>six</ins>
categories of iterators, according to the operations defined on them:
<em>input iterators</em>, <em>output iterators</em>, <em>forward
iterators</em>, <em>bidirectional iterators</em><ins>,</ins>
<del>and</del> <em>random access iterators</em><ins>, and <em>contiguous
iterators</em></ins>, as shown in Table 105.

</blockquote>


Add a new subsection 24.2.8 [contiguous.iterators]:

<blockquote class="new">
<b>24.2.8 Contiguous iterators [contiguous.iterators]</b>

<p>

A class or pointer type <code>X</code> satisfies the requirements of a
contiguous iterator if, in addition to satisfying the requirements for
random access iterators, for dereferenceable <code>a</code>
and <code>(a + n)</code>, <code>*(a + n)</code> is equivalent to
<code>*(std::addressof(*a) + n)</code>. [ Note: For a valid
iterator range [a, b) with dereferenceable <code>a</code>, the
corresponding range denoted by pointers is
[<code>std::addressof(*a)</code>, <code>std::addressof(*a) +
(b-a)</code> ); <code>b</code> might not be dereferenceable. -- end
note ]

</blockquote>


Change in 21.4 [basic.string] paragraph 3:

<blockquote>
The iterators supported by <code>basic_string</code> are random access
iterators (24.2.7 [random.access.iterators]). <ins>In addition, the
member types <code>iterator</code> and <code>const_iterator</code> are
contiguous iterators (24.2.8 [contiguous.iterators]).

</blockquote>

Delete in 21.4.1 [string.require] paragraph 4:

<blockquote>
<del>The char-like objects in a <code>basic_string</code> object shall be
stored contiguously. That is, for any <code>basic_string</code> object
s, the identity <code>&*(s.begin() + n) == &*s.begin() + n</code>
shall hold for all values of n such that <code>0 <= n <
s.size()</code>.</del>

</blockquote>


Change in 23.3.2.1 [array.overview] paragraph 1:

<blockquote>
... An array supports random access iterators <ins>(24.2.7
[random.access.iterators]). In addition, the member types
<code>iterator</code> and <code>const_iterator</code> are contiguous
iterators (24.2.8 [contiguous.iterators])</ins>. ... <del>The elements
of an array are stored contiguously, meaning that if a is an
array&lt;T, N> then it obeys the identity <code>&a[n] == &a[0] +
n</code> for all <code>0 <= n < N.</code>

</blockquote>


Change in 23.3.6.1 [vector.overview] paragraph 1:

<blockquote>
A vector is a sequence container that supports random access iterators
<ins>(24.2.7 [random.access.iterators]).  In addition, the member types
<code>iterator</code> and <code>const_iterator</code> are contiguous
iterators (24.2.8 [contiguous.iterators])</ins>. ...  <del>The elements
of a vector are stored contiguously, meaning that if v is a vector<T,
Allocator> where T is some type otherthan bool, then it obeys the
identity <code>&v[n] == &v[0] + n for all 0 <= n <
v.size()</code>.</del>

</blockquote>

<strong>Change in 26.6.10 [valarray.range] paragraph 1:</strong>

<blockquote>
In the <code>begin</code> and <code>end</code> function templates that
follow, <em>unspecified1</em> is a type that meets the requirements of
a mutable <del>random access iterator (24.2.7
[random.access.iterators])</del> <ins>contiguous iterator (24.2.8
[contiguous.iterators])</ins> whose <code>value_type</code> is the
template parameter T and whose reference type is
T&. <em>unspecified2</em> is a type that meets the requirements of a
constant <del>random access iterator (24.2.7
[random.access.iterators])</del> <ins>contiguous iterator (24.2.8
[contiguous.iterators])</ins> whose <code>value_type</code> is the
template parameter T and whose reference type is const T&.

</blockquote>


<em>[ Drafting note: In the library fundamentals TS, section 7.4, replace</em>

<blockquote>
<pre>typedef implementation-defined const_iterator;</pre>

A constant <del>random-access</del> <ins>contiguous</ins> iterator
type<del> such that, for a const_iterator it, if &*(it+N) is valid,
then it is equal to (&*it)+N</del>.

</blockquote>
<em>]</em>

</body>
</html>
