<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1042: Provide ContiguousStorage concept and apply it to corresponding containers</title>
<meta property="og:title" content="Issue 1042: Provide ContiguousStorage concept and apply it to corresponding containers">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1042.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#NAD">NAD</a> status.</em></p>
<h3 id="1042"><a href="lwg-closed.html#1042">1042</a>. Provide <code>ContiguousStorage</code> concept and apply it to corresponding containers</h3>
<p><b>Section:</b> 23.3 <a href="https://wg21.link/sequences">[sequences]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Alisdair Meredith <b>Opened:</b> 2009-03-12 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#sequences">issues</a> in [sequences].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>

<p><b>Addresses UK 244 [CD1]</b></p>

<p>
The validity of the expression <code>&amp;a[n] == &amp;a[0] + n</code> is contingent on
<code>operator&amp;</code> doing the "right thing" (as captured by the <code>CopyConstructible</code>
requirements in table 30 in C++2003). However this constraint has been
lost in the Concepts of C++0x. This applies to <code>vector</code> and <code>array</code> (it
actually applies to <code>string</code> also, but that's a different chapter, so I'll
file a separate comment there and cross-reference).
</p>

<p>
Suggested solution:
</p>

<p>
Define a <code>ContiguousStorage</code> and apply it to
<code>vector</code>, <code>array</code> and <code>string</code>.
</p>

<p><i>[
Summit:
]</i></p>


<blockquote><p>
Agree with the issue but not the details of the proposed solution. Walter to
provide wording for the new concept.
</p></blockquote>

<p><i>[
Post Summit Alisdair adds:
]</i></p>


<blockquote><p>
Another LWG subgroup wondered if this concept should extend to <code>complex&lt;T&gt;</code>, 
and so not be built on the container concept at all?
</p></blockquote>

<p><i>[
2009-07 post-Frankfurt:
]</i></p>


<blockquote><p>
Leave Open, pending a post-Concepts Working Draft.
</p></blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Mark issue 1042 as NAD, in rationale state that this was solved by removal of concepts.
</p></blockquote>



<p id="res-1042"><b>Proposed resolution:</b></p>
<p>
Add to <code>&lt;container_concepts&gt;</code> synopsis in  [container.concepts]
</p>

<blockquote><pre>
<ins>concept&lt; typename C &gt; ContiguousStorageContainer <i>see below</i>;</ins>
</pre></blockquote>

<p>
Add a new section to the end of  [container.concepts]
</p>

<blockquote>
<p>
23.1.6.x ContiguousStorageContainer concept [container.concepts.contiguous]
</p>

<pre>
concept ContiguousStorageContainer&lt; typename C &gt;
  : Container&lt;C&gt;
{
  value_type* data(C&amp;);

  axiom Contiguity(C&amp; c, size_type i) {
    if( i &lt; size(c) ) {
         addressof( * (data(c) + i) )
      == addressof( * advance(data(c), i) );
    }
  }
}
</pre>

<p>
The <code>ContiguousStorageContainer</code> concept describes a container whose elements
are allocated in a single region of memory, and are stored sequentially
without intervening padding other than to meet alignment requirements.
For example, the elements may be stored in a
single array of suitable length.
</p>

<pre>
value_type * data( C&amp; );
</pre>

<blockquote><p>
<i>Returns:</i> a pointer to the first element in the region of storage.
Result is unspecified for an empty container.
</p></blockquote>

</blockquote>

<p>
Change 23.3.3 <a href="https://wg21.link/array">[array]</a> p1:
</p>

<blockquote><p>
-1- The header <code>&lt;array&gt;</code> defines a class template for
storing fixed-size sequences of objects. An <code>array</code> supports
random access iterators. An instance of <code>array&lt;T, N&gt;</code>
stores <code>N</code> elements of type <code>T</code>, so that <code>size() ==
N</code> is an invariant. The elements of an <code>array</code> are stored
contiguously, meaning that <del>if <code>a</code> is</del> an
<code>array&lt;T, N&gt;</code> <del>then it obeys the identity <code>&amp;a[n]
== &amp;a[0] + n</code> for all <code>0 &lt;= n &lt; N</code></del>
<ins>satisfies the concept <code>ContiguousStorageContainer&lt; array&lt;T,
N&gt;&gt;</code></ins>.
</p></blockquote>

<p>
Add to the synopsis in 23.3.3 <a href="https://wg21.link/array">[array]</a>:
</p>

<blockquote><pre>
    ...
    T * data(); 
    const T * data() const; 
  };

  <ins>template&lt; typename T, size_t N &gt;</ins>
    <ins>concept_map ContiguousStorageContainer&lt; array&lt;T, N&gt;&gt; {};</ins>
} 
</pre></blockquote>

<p>
Change 23.3.13 <a href="https://wg21.link/vector">[vector]</a> p1:
</p>

<blockquote><p>
A <code>vector</code> is a sequence container that supports random access
iterators. In addition, it supports (amortized) constant time insert and
erase operations at the end; insert and erase in the middle take linear
time. Storage management is handled automatically, though hints can be
given to improve efficiency. The elements of a vector are stored
contiguously, meaning that <del>if <code>v</code> is</del> a
<code>vector&lt;T, Alloc&gt;</code> <ins>(</ins>where <code>T</code> is some
type other than <code>bool</code><ins>)</ins><del>, then it obeys the
identity <code>&amp;v[n] == &amp;v[0] + n</code> for all <code>0 &lt;= n &lt;
v.size()</code></del> <ins>satisfies the concept <code>ContiguousStorageContainer&lt;
vector&lt; T, Alloc&gt;&gt;</code></ins>.
</p></blockquote>

<p>
Add at the end of the synopsis in 23.3.13 <a href="https://wg21.link/vector">[vector]</a> p2:
</p>

<blockquote><pre>
<ins>template&lt; typename T, typename A &gt;
  requires !SameType&lt; T, bool &gt;
  concept_map ContiguousStorageContainer&lt; vector&lt;T, A&gt;&gt; {};</ins>
</pre></blockquote>



<p><b>Rationale:</b></p>
<p>Solved by removal of concepts.</p>





</body>
</html>
