Topic: [N4359] vector::release() - Missing symetric


Author: Dale Weiler <weilercdale@gmail.com>
Date: Sat, 14 Feb 2015 10:04:54 -0800 (PST)
Raw View
------=_Part_876_1831492138.1423937094100
Content-Type: multipart/alternative;
 boundary="----=_Part_877_2005250915.1423937094100"

------=_Part_877_2005250915.1423937094100
Content-Type: text/plain; charset=UTF-8

Having looked over this proposal I'm actually wondering if release should
return a pair of pointer and size.
I think this would be much better (and safer) since the size will often be
required and it will prevent strange
interface contracts; like grabbing the size before the call to release, as
the call invalidates the vector contents
(including size.)

So a minor modification I'd suggest

pair<T*, size_type> release() noexcept;

At least this way one could use this as such

vector<int> stuff;
getStuff(stuff);

auto p = stuff.release();
some_c_function(p.first, p.second); // some_c_function(int *, size_t)

Perhaps however it would be better to use a tuple of pointer, size and
allocator

tuple<T*, size_type, allocator_type> release() noexcept;

Then at least all the relevant information about the release can be grabbed
all at once when releasing the vector

vector<A> stuff;
getStuff(stuff);

auto p = stuff.release();

doStuffWith(std::get<0>(p), std::get<1>(p)); // doStuff(A *, size_t)

for (size_t i = 0; i < std::get<1>(p); i++) std::get<0>(p)[i].~A();

std::get<2>(p)().release(std::get<0>(p), std::get<1>(p));

However come to think of it, it may just be wiser (in general) to add
something like
vector_view
that contains all this information

template <typename T, typename A = allocator<T>>
struct vector_view {
  vector_view(vector<T, A> &&vec) {
    size_ = vec.size();
    allocator_ = vec.get_allocator();
    data_ = vec.data_; // vector<T, A> will have to friend vector_view
  }
  typedef typename vector<T, A>::value_type value_type;
  typedef typename vector<T, A>::allocator_type allocator_type;
  typedef typename vector<T, A>::reference reference;
  typedef typename vector<T, A>::const_reference const_reference;
  typedef typename vector<T, A>::pointer pointer;
  typedef typename vector<T, A>::const_pointer const_pointer;
  typedef typename vector<T, A>::iterator iterator;
  typedef typename vector<T, A>::const_iterator const_iterator;
  typedef typename vector<T, A>::size_type size_type;

  // Implements begin, end, size, empty, operator[], at, front, back, data,
get_allocator
  iterator begin() { return data_; }
  const_iterator begin() const { return data_; }
  iterator end() { return data_ + size_; }
  const_iterator end() const { return data_ + size_; }

  size_type size() const { return size_; }
  bool empty() const { return size_ == 0; }

  reference operator[](size_type n) { return data_[n]; }
  const_reference operator[](size_type n) const { return data_[n]; }
  reference at(size_type n) { if (n >= size_) throw std::out_of_range(
"vector_view::at"); return data_[n]; }
  const_reference at(size_type n) { if (n >= size_) throw throw std::
out_of_range("vector_view::at"); return data_[n]; }

  reference front() { return *data_; }
  const_reference front() const { return *data_; }
  reference back() { return data_[size_ - 1]; }
  const_reference back() const { return data_[size - 1]; }

  pointer data() noexcept { return data_; }
  const_pointer data() const noexcept { return data_; }

  allocator_type& get_allocator() const { return allocator_; }

private:
  value_type *data_;
  size_type size_;
  allocator_type& allocator_;
};

Then vector<T, A> could implement release as outputting one of these

vector_view<T, A> release() noexcept;

Then one could write the previous example as such

auto view = vec.release();
doStuffWith(&view[0], view.size());

for (auto &it : view) it.~A();
view.get_allocator().deallocate(view.data(), view.size());

Could even add a utility function to vector_view that does the deallocation
for you,
perhaps in the nature of allocator<T> we could call it deallocate.

template <typename T, typename A = allocator<T>>
struct vector_view {
  ...
  void deallocate() noexcept {
    for (auto &it : *this) {
      it.~value_type();
    }
    allocator_.deallocate(data_, size_);
  }
  ...
};


Then the full example becomes

vector<A> stuff;
getStuff(stuff);

auto view = stuff.release();

doStuffWith(&view[0] /* or view.data() */, view.size()); // doStuff(A *,
size_t)

view.deallocate();


--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_877_2005250915.1423937094100
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><font size=3D"2">Having looked over this proposal I'm actu=
ally wondering if release should return a pair of pointer and size.<br>I th=
ink this would be much better (and safer) since the size will often be requ=
ired and it will prevent strange<br>interface contracts; like grabbing the =
size before the call to release, as the call invalidates the vector content=
s<br>(including size.)<br><br>So a minor modification I'd suggest</font><br=
><br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 25=
0); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1p=
x; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpre=
ttyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">pair</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">*,</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> size_type</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> release</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> noexcept</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span></div></code></div><br>At least this way one coul=
d use this as such<br><br><div class=3D"prettyprint" style=3D"background-co=
lor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: so=
lid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"=
><div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled=
-by-prettify">vector</span><span style=3D"color: #080;" class=3D"styled-by-=
prettify">&lt;int&gt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> stuff</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>getStuff</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">stuff</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> p </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> stuff</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">release</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>some_c_function</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">p</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">first</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> p</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">second</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"sty=
led-by-prettify">// some_c_function(int *, size_t)</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br>P=
erhaps however it would be better to use a tuple of pointer, size and alloc=
ator<br><br><div class=3D"prettyprint" style=3D"background-color: rgb(250, =
250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-wi=
dth: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D=
"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">=
tuple</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">*,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> size_type</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> allocator_type</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> release</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> noexcept</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span></div></code></div><br>Then at least all the re=
levant information about the release can be grabbed all at once when releas=
ing the vector<br><br><div class=3D"prettyprint" style=3D"background-color:=
 rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid;=
 border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><di=
v class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-=
prettify">vector</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
A</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> stuff</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>getStuff</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">stuff</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> p </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> stuff</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">release<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>doStuffWit=
h</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">get</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #066;" =
class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&gt;(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">p</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">),</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> s=
td</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">get</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">1</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">p</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">));</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pr=
ettify">// doStuff(A *, size_t)</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">for</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">size_t=
 i </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> i </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">::</span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">get</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">p</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> i</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">++)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">::</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">get</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&lt;</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">p</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">)[</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">i</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">].~</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">A</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br><br>std</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">::</span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">get</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span style=3D"color: #066;" class=3D"styled-by-prettify">2</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">p</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)().</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">release</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">::</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">get</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&lt;</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">p</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">),</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">::</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">get</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&lt;</span><span style=3D"color: #066;" class=3D"styled-=
by-prettify">1</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&gt;(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">p=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">));</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div>=
</code></div><code class=3D"prettyprint"><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><span style=3D"font-family: arial,sans-serif;">=
However come to think of it, it may just be wiser (in general) to add somet=
hing like</span> <div class=3D"prettyprint" style=3D"background-color: rgb(=
250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bord=
er-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div cla=
ss=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">vector_view<br></span></div></code></div><span style=3D"font-family: a=
rial,sans-serif;">that contains all this information</span><br><br></span><=
/code><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 2=
50); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1=
px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpr=
ettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">templa=
te</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> A </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> allocator</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> vector_view </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; vector_view<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">vector</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> A</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&amp;&amp;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">vec</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; size_ </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> vec</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">size</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>&nbsp; &nbsp; allocator_ </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> vec</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">get_allocator</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>&nbsp; &nbsp; data_ </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> vec</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">data_</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// vecto=
r&lt;T, A&gt; will have to friend vector_view</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">typedef</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> vector</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> A</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&gt;::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">value_type value_type</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; </span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">typedef</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> vector</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> A</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&gt;::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
allocator_type allocator_type</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">typedef</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">t=
ypename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ve=
ctor</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&gt;::</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">reference reference</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">typedef</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> vector</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> A<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">const_reference=
 const_reference</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ty=
pedef</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> vector</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> A</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;::</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">pointer pointer</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br>&nbsp; </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">typedef</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">typename</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> vector</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&gt;::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">const_pointer const_pointer</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">typedef</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> vector</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> A</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&gt;::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">ite=
rator iterator</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&=
nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">type=
def</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> vector</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> A</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;::</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">const_iterator const_iterator</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">typedef</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> vector</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> A</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;::</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">size_type size_type</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; </span>=
<span style=3D"color: #800;" class=3D"styled-by-prettify">// Implements beg=
in, end, size, empty, operator[], at, front, back, data, get_allocator</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; iter=
ator </span><span style=3D"color: #008;" class=3D"styled-by-prettify">begin=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> data_</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>&nbsp; const_iterator </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">begin</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> data_</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>&nbsp; iterator </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">end</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> data_ </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">+</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> size_</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>&nbsp; const_iterator </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">end</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> data_ </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">+</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> size_</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; =
size_type size</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> size_</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">bo=
ol</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> empty</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> size_ </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">=3D=3D</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br>&nbsp; reference </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">[](</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">size_type n</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> data_</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">n</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">];</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br>&nbsp; const_reference </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">[](</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">size_type n</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> data_</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">n</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">];</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>&nbsp; reference at</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">size_type n</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">n </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&gt;=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> size_</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">throw</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">out_of_range</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #080;" class=3D"styled-by-prettify">"vector_view::at"</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> data_</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">[</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">n</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">];</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; =
const_reference at</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">s=
ize_type n</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">if</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">n </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&gt;=3D</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> size_</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">throw</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">throw</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">out_of_range</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span><span style=3D"color: #080;" class=3D"sty=
led-by-prettify">"vector_view::at"</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">return</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> data_</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">n</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">];</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br><br>&nbsp; reference front</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">data_</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>&nbsp; const_reference front</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">*<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">data_</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>&nbsp; reference back</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> data_</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">[</span><span style=3D"color: #000;" class=3D"styled-by-prettify">size_=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">-</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #066;" class=3D"styled-by-prettify">1</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">];</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>&nbsp; const_reference back</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> data_</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">size </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">];</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nb=
sp; pointer data</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> n=
oexcept </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> data_</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>&nbsp; const_pointer data</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> noexcept </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> da=
ta_</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; allocator_type</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> get_allocator</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> allocator_</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">private</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>&nbsp; value_type </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">data_</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>&nbsp; size_type size_</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>&nbsp; allocator_type</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> allocator_</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span></div></code></div><code class=3D"pret=
typrint"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><spa=
n style=3D"font-family: arial,sans-serif;">Then vector&lt;T, A&gt; could im=
plement release as outputting one of these<br></span><br><div class=3D"pret=
typrint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(1=
87, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-wor=
d;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">vector_view</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> A</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> release</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 noexcept</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
></div></code></div><br><span style=3D"font-family: arial,sans-serif;">Then=
 one could write the previous example as such</span><br><br><div class=3D"p=
rettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: rg=
b(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> view </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> vec</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">release</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>doStuffWith</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(&amp;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">view</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>[</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">],</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> view</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">size</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">());</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">for</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">a=
uto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">it </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> view</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> it</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">.~</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">A</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>vie=
w</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">get_allocator</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">().</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">deallocate</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">view</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">data</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(),</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> view</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">size</span><span style=3D"color: #660;" class=3D"styled-by-prettify">())=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n></div></code></div><br>Could even add a utility function to vector_view t=
hat does the deallocation for you,<br>perhaps in the nature of allocator&lt=
;T&gt; we could call it deallocate.<br><br><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187);=
 border-style: solid; border-width: 1px; word-wrap: break-word;"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;=
" class=3D"styled-by-prettify">template</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> A </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> allocator</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&gt;&gt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> vector_view </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>&nbsp; </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">...</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> deallocate</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> no=
except </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &=
nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">for<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">it </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">*</span><span style=3D"color: #008;" class=3D"styled-by-prettify">this</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; it</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">.~</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">value_type</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; allocator_</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">deallocate</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">data_</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> size_</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>&nbsp; </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br>&nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">...</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div=
></code></div><br><br><span style=3D"font-family: arial,sans-serif;">Then t=
he full example becomes</span><br></span></code><br><code class=3D"prettypr=
int"><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 25=
0); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1p=
x; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpre=
ttyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">vector<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">A</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> stuff</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>getStuff</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">stuff</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> view </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> stuff<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">release</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br>doStuffWith</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(&amp;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">view</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">]</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by=
-prettify">/* or view.data() */</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> view</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">si=
ze</span><span style=3D"color: #660;" class=3D"styled-by-prettify">());</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #800;" class=3D"styled-by-prettify">// doStuff(A *, size_t)=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>vi=
ew</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">deallocate</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code>=
</div><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></s=
pan></code></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_877_2005250915.1423937094100--
------=_Part_876_1831492138.1423937094100--

.


Author: Nevin Liber <nevin@eviloverlord.com>
Date: Sat, 14 Feb 2015 12:28:01 -0600
Raw View
--047d7beb910ac3c2af050f10856d
Content-Type: text/plain; charset=UTF-8

On 14 February 2015 at 12:04, Dale Weiler <weilercdale@gmail.com> wrote:

> Having looked over this proposal I'm actually wondering if release should
> return a pair of pointer and size.
> I think this would be much better (and safer) since the size will often be
> required and it will prevent strange
> interface contracts; like grabbing the size before the call to release, as
> the call invalidates the vector contents
> (including size.)
>

You need to return three things:

1.  Pointer to the data.
2.  Number of elements.
3.  Allocator.


>
> So a minor modification I'd suggest
>
> pair<T*, size_type> release() noexcept;
>

I much prefer returning things with names, to make things readable.  It
should return a dedicated class/struct instance.

Note:  do not consider this message to be an endorsement by me of this
proposal; I'm still thinking about it.
--
 Nevin ":-)" Liber  <mailto:nevin@eviloverlord.com>  (847) 691-1404

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--047d7beb910ac3c2af050f10856d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On 14 February 2015 at 12:04, Dale Weiler <span dir=3D"ltr=
">&lt;<a href=3D"mailto:weilercdale@gmail.com" target=3D"_blank">weilercdal=
e@gmail.com</a>&gt;</span> wrote:<br><div class=3D"gmail_extra"><div class=
=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><font>Havi=
ng looked over this proposal I&#39;m actually wondering if release should r=
eturn a pair of pointer and size.<br>I think this would be much better (and=
 safer) since the size will often be required and it will prevent strange<b=
r>interface contracts; like grabbing the size before the call to release, a=
s the call invalidates the vector contents<br>(including size.)<br></font><=
/div></blockquote><div><br></div><div>You need to return three things:</div=
><div><br></div><div>1.=C2=A0 Pointer to the data.</div><div>2.=C2=A0 Numbe=
r of elements.</div><div>3.=C2=A0 Allocator.</div><div>=C2=A0</div><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr"><font><br>So a minor modification I=
&#39;d suggest</font><br><br><div style=3D"background-color:rgb(250,250,250=
);border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wr=
ap:break-word"><code><div><span style=3D"color:#000">pair</span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><span style=
=3D"color:#660">*,</span><span style=3D"color:#000"> size_type</span><span =
style=3D"color:#660">&gt;</span><span style=3D"color:#000"> release</span><=
span style=3D"color:#660">()</span><span style=3D"color:#000"> noexcept</sp=
an><span style=3D"color:#660">;</span></div></code></div></div></blockquote=
><div><br></div><div>I much prefer returning things with names, to make thi=
ngs readable.=C2=A0 It should return a dedicated class/struct instance.</di=
v><div><br></div><div>Note: =C2=A0do not consider this message to be an end=
orsement by me of this proposal; I&#39;m still thinking about it.</div></di=
v>-- <br><div class=3D"gmail_signature">=C2=A0Nevin &quot;:-)&quot; Liber=
=C2=A0 &lt;mailto:<a href=3D"mailto:nevin@eviloverlord.com" target=3D"_blan=
k">nevin@eviloverlord.com</a>&gt;=C2=A0 (847) 691-1404</div>
</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--047d7beb910ac3c2af050f10856d--

.


Author: Dale Weiler <weilercdale@gmail.com>
Date: Sat, 14 Feb 2015 13:32:23 -0500
Raw View
--089e0115fad2f86775050f109282
Content-Type: text/plain; charset=UTF-8

@Nevin Liber
Expand my full post. I ended up designing such a construct (but google
groups decides to truncate it)

On Sat, Feb 14, 2015 at 1:28 PM, Nevin Liber <nevin@eviloverlord.com> wrote:

> On 14 February 2015 at 12:04, Dale Weiler <weilercdale@gmail.com> wrote:
>
>> Having looked over this proposal I'm actually wondering if release should
>> return a pair of pointer and size.
>> I think this would be much better (and safer) since the size will often
>> be required and it will prevent strange
>> interface contracts; like grabbing the size before the call to release,
>> as the call invalidates the vector contents
>> (including size.)
>>
>
> You need to return three things:
>
> 1.  Pointer to the data.
> 2.  Number of elements.
> 3.  Allocator.
>
>
>>
>> So a minor modification I'd suggest
>>
>> pair<T*, size_type> release() noexcept;
>>
>
> I much prefer returning things with names, to make things readable.  It
> should return a dedicated class/struct instance.
>
> Note:  do not consider this message to be an endorsement by me of this
> proposal; I'm still thinking about it.
> --
>  Nevin ":-)" Liber  <mailto:nevin@eviloverlord.com>  (847) 691-1404
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--089e0115fad2f86775050f109282
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">@<span name=3D"Nevin Liber" class=3D"">Nevin Liber<br></sp=
an>Expand my full post. I ended up designing such a construct (but google g=
roups decides to truncate it)<br></div><div class=3D"gmail_extra"><br><div =
class=3D"gmail_quote">On Sat, Feb 14, 2015 at 1:28 PM, Nevin Liber <span di=
r=3D"ltr">&lt;<a href=3D"mailto:nevin@eviloverlord.com" target=3D"_blank">n=
evin@eviloverlord.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr"><span class=3D"">On 14 February 2015 at 12:04, Dale Wei=
ler <span dir=3D"ltr">&lt;<a href=3D"mailto:weilercdale@gmail.com" target=
=3D"_blank">weilercdale@gmail.com</a>&gt;</span> wrote:<br></span><div clas=
s=3D"gmail_extra"><div class=3D"gmail_quote"><span class=3D""><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;=
padding-left:1ex"><div dir=3D"ltr"><font>Having looked over this proposal I=
&#39;m actually wondering if release should return a pair of pointer and si=
ze.<br>I think this would be much better (and safer) since the size will of=
ten be required and it will prevent strange<br>interface contracts; like gr=
abbing the size before the call to release, as the call invalidates the vec=
tor contents<br>(including size.)<br></font></div></blockquote><div><br></d=
iv></span><div>You need to return three things:</div><div><br></div><div>1.=
=C2=A0 Pointer to the data.</div><div>2.=C2=A0 Number of elements.</div><di=
v>3.=C2=A0 Allocator.</div><span class=3D""><div>=C2=A0</div><blockquote cl=
ass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><div dir=3D"ltr"><font><br>So a minor modification I&#39;d=
 suggest</font><br><br><div style=3D"background-color:rgb(250,250,250);bord=
er-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:bre=
ak-word"><code><div><span style=3D"color:#000">pair</span><span style=3D"co=
lor:#660">&lt;</span><span style=3D"color:#000">T</span><span style=3D"colo=
r:#660">*,</span><span style=3D"color:#000"> size_type</span><span style=3D=
"color:#660">&gt;</span><span style=3D"color:#000"> release</span><span sty=
le=3D"color:#660">()</span><span style=3D"color:#000"> noexcept</span><span=
 style=3D"color:#660">;</span></div></code></div></div></blockquote><div><b=
r></div></span><div>I much prefer returning things with names, to make thin=
gs readable.=C2=A0 It should return a dedicated class/struct instance.</div=
><div><br></div><div>Note: =C2=A0do not consider this message to be an endo=
rsement by me of this proposal; I&#39;m still thinking about it.</div></div=
><span class=3D"HOEnZb"><font color=3D"#888888">-- <br><div>=C2=A0Nevin &qu=
ot;:-)&quot; Liber=C2=A0 &lt;mailto:<a href=3D"mailto:nevin@eviloverlord.co=
m" target=3D"_blank">nevin@eviloverlord.com</a>&gt;=C2=A0 <a href=3D"tel:%2=
8847%29%20691-1404" value=3D"+18476911404" target=3D"_blank">(847) 691-1404=
</a></div>
</font></span></div></div><div class=3D"HOEnZb"><div class=3D"h5">

<p></p>

-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--089e0115fad2f86775050f109282--

.


Author: =?UTF-8?Q?Klaim_=2D_Jo=C3=ABl_Lamotte?= <mjklaim@gmail.com>
Date: Sat, 14 Feb 2015 20:09:28 +0100
Raw View
--001a11347b3ea0acb3050f111783
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

=E2=80=8BA type owning a dynamically allocated array is not a "view"...

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--001a11347b3ea0acb3050f111783
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br>=E2=80=8BA type owning a dynamically allocated array i=
s not a &quot;view&quot;...<div><br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11347b3ea0acb3050f111783--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Sat, 14 Feb 2015 11:10:04 -0800
Raw View
On Saturday 14 February 2015 12:28:01 Nevin Liber wrote:
> You need to return three things:
>
> 1.  Pointer to the data.
> 2.  Number of elements.
> 3.  Allocator.

Make it 4:

1. Pointer to the data
2. Number of elements
3. Pointer to be passed to the allocator to be freed
4. Allocator

std::vector may allocate a a block of data that is bigger than the actual
array and it may store some book-keeping information at the beginning of such
a block. Example:

template <typename T, typanem Allocator>
struct vector_data
{
 size_t count;
 size_t capacity;
 Allocator allocator;
 T array[0];  // compiler extension support
};

template <class T, class Allocator = allocator<T> >
class vector
{
 vector_data<T, Allocator> data;
 [...]
};

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Howard Hinnant <howard.hinnant@gmail.com>
Date: Sat, 14 Feb 2015 14:15:32 -0500
Raw View
This is decent anecdotal evidence that the proposal places unreasonably err=
or prone responsibilities on the caller of release().  I=E2=80=99ve yet to =
see a correct handling of the vector=E2=80=99s buffer, either in the paper,=
 or here, even if I assume that the allocator is std::allocator, much less =
an arbitrary user-supplied allocator.

By the time you correctly dispose of this buffer, you=E2=80=99ve gone a lon=
g way towards re-implementing std::vector.

(update) Just saw Thiago=E2=80=99s post! :-)  That=E2=80=99s the closest ye=
t! :-)

Howard

On Feb 14, 2015, at 1:32 PM, Dale Weiler <weilercdale@gmail.com> wrote:

> @Nevin Liber
> Expand my full post. I ended up designing such a construct (but google gr=
oups decides to truncate it)
>=20
>> On Sat, Feb 14, 2015 at 1:28 PM, Nevin Liber <nevin@eviloverlord.com> wr=
ote:
>> On 14 February 2015 at 12:04, Dale Weiler <weilercdale@gmail.com> wrote:
>> Having looked over this proposal I'm actually wondering if release shoul=
d return a pair of pointer and size.
>> I think this would be much better (and safer) since the size will often =
be required and it will prevent strange
>> interface contracts; like grabbing the size before the call to release, =
as the call invalidates the vector contents
>> (including size.)
>>=20
>> You need to return three things:
>>=20
>> 1.  Pointer to the data.
>> 2.  Number of elements.
>> 3.  Allocator.
>> =20
>>=20
>> So a minor modification I'd suggest
>>=20
>> pair<T*, size_type> release() noexcept;
>>=20
>> I much prefer returning things with names, to make things readable.  It =
should return a dedicated class/struct instance.
>>=20
>> Note:  do not consider this message to be an endorsement by me of this p=
roposal; I'm still thinking about it.
>> --=20

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.


Author: Miro Knejp <miro.knejp@gmail.com>
Date: Sat, 14 Feb 2015 20:28:38 +0100
Raw View
Am 14.02.2015 um 20:10 schrieb Thiago Macieira:
> On Saturday 14 February 2015 12:28:01 Nevin Liber wrote:
>> You need to return three things:
>>
>> 1.  Pointer to the data.
>> 2.  Number of elements.
>> 3.  Allocator.
> Make it 4:
>
> 1. Pointer to the data
> 2. Number of elements
> 3. Pointer to be passed to the allocator to be freed
> 4. Allocator
5. Total capacity of the allocated block for further shenanigans

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Howard Hinnant <howard.hinnant@gmail.com>
Date: Sat, 14 Feb 2015 14:38:32 -0500
Raw View
On Feb 14, 2015, at 2:28 PM, Miro Knejp <miro.knejp@gmail.com> wrote:

>=20
> Am 14.02.2015 um 20:10 schrieb Thiago Macieira:
>> On Saturday 14 February 2015 12:28:01 Nevin Liber wrote:
>>> You need to return three things:
>>>=20
>>> 1.  Pointer to the data.
>>> 2.  Number of elements.
>>> 3.  Allocator.
>> Make it 4:
>>=20
>> 1. Pointer to the data
>> 2. Number of elements
>> 3. Pointer to be passed to the allocator to be freed
>> 4. Allocator
> 5. Total capacity of the allocated block for further shenanigans

<nod>

And you can=E2=80=99t traffic in T* as the proposal says.  You must dealloc=
ate vector<T>::pointer which may not be a T*.  And you can=E2=80=99t call ~=
T() directly.  And to be consistent, you probably shouldn=E2=80=99t call al=
locator.deallocate() directly either, though I can see a rationale that say=
s there=E2=80=99s no way to get into trouble if you do (a very subtle point=
).  And when calling allocator_traits<Allocator>::destroy, you must correct=
ly convert vector<T>::pointer to a T*.  And please don=E2=80=99t do any of =
this in a way that could compromise basic exception safety.

Howard

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.


Author: Howard Hinnant <howard.hinnant@gmail.com>
Date: Sat, 14 Feb 2015 16:49:42 -0500
Raw View
On Feb 14, 2015, at 2:38 PM, Howard Hinnant <howard.hinnant@gmail.com> wrot=
e:

>=20
> On Feb 14, 2015, at 2:28 PM, Miro Knejp <miro.knejp@gmail.com> wrote:
>=20
>>=20
>> Am 14.02.2015 um 20:10 schrieb Thiago Macieira:
>>> On Saturday 14 February 2015 12:28:01 Nevin Liber wrote:
>>>> You need to return three things:
>>>>=20
>>>> 1.  Pointer to the data.
>>>> 2.  Number of elements.
>>>> 3.  Allocator.
>>> Make it 4:
>>>=20
>>> 1. Pointer to the data
>>> 2. Number of elements
>>> 3. Pointer to be passed to the allocator to be freed
>>> 4. Allocator
>> 5. Total capacity of the allocated block for further shenanigans
>=20
> <nod>
>=20
> And you can=E2=80=99t traffic in T* as the proposal says.  You must deall=
ocate vector<T>::pointer which may not be a T*.  And you can=E2=80=99t call=
 ~T() directly.  And to be consistent, you probably shouldn=E2=80=99t call =
allocator.deallocate() directly either, though I can see a rationale that s=
ays there=E2=80=99s no way to get into trouble if you do (a very subtle poi=
nt).  And when calling allocator_traits<Allocator>::destroy, you must corre=
ctly convert vector<T>::pointer to a T*.  And please don=E2=80=99t do any o=
f this in a way that could compromise basic exception safety.

It occurs to me that one way to rescue this proposal is to follow the spiri=
t of:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3586.pdf

1.  Introduce a nested type vector<T, A>::node_ptr.

2.  node_ptr is an alias for unique_ptr<T[], allocator_deleter<T, A>>.

3.  allocator_deleter<T, A> looks something like:

    template <class T, class Allocator>
    class allocator_deleter
    {
    public:
        using value_type     =3D T;
        using allocator_type =3D Allocator;
        using traits         =3D std::allocator_traits<allocator_type>;
        using pointer        =3D typename traits::pointer;
        using size_type      =3D typename traits::size_type;
    private:
        std::tuple<allocator_type, size_type, size_type> data_;
    public:
        allocator_deleter(allocator_type const& a, size_type size,
                          size_type capacity) noexcept
            : data_(a, size, capacity)
            {}

        void operator()(pointer p) noexcept
        {
            for (pointer e =3D p + std::get<1>(data_); p !=3D e;)
                traits::destroy(std::get<0>(data_), std::addressof(*--e));
            traits::deallocate(std::get<0>(data_), p, std::get<2>(data_));
        }

        allocator_type get_allocator() const noexcept {return std::get<0>(d=
ata_);}
        size_type size()               const noexcept {return std::get<1>(d=
ata_);}
        size_type capacity()           const noexcept {return std::get<2>(d=
ata_);}

        static_assert((std::is_same<value_type, typename allocator_type::va=
lue_type>::value),
                      "Invalid allocator::value_type");
    };

3a.  If allocator_deleter needs to do anything fancier than this to handle =
details such as those Thiago alludes to, it is up to the author of vector t=
o put those details into allocator_deleter.

3b.  allocator_deleter is not necessarily a user-accessible name.  Clients =
should reach for vector<T, A>::node_ptr::deleter_type if they need a name f=
or this type.

4.  Introduce to vector<T, A>:

    template <class T, class A>
    typename vector<T, A>::node_ptr
    release();

5.  Introduce an explicit vector<T, A> constructor:

    template <class T, class A>
    vector<T, A>::vector(node_ptr&& np);

Example use:

    int
    main()
    {
        std::vector<X> v;
        for (int i =3D 0; i < 3; ++i)
            v.push_back(X(i));
        auto up =3D v.release();
        for (auto i =3D 0; i < up.get_deleter().size(); ++i)
            std::cout << up[i] << '\n';
    }

Open questions (at least for me).

1.  This was fun to create.  But does it have sufficient use cases to justi=
fy standardization?  Combined with a custom allocator built on malloc/free =
it *might* enable the memory ownership transfer with legacy code capability=
 alluded to in N4359.

2.  Is the API of allocator_deleter sufficiently general to serve the use c=
ases it needs to?  One possibility would be to add another pointer to its A=
PI to allow the first element to begin at a non-zero offset with respect to=
 the allocated pointer.  This *might* allow ownership transfer between vect=
or and user-defined containers such as a =E2=80=9Csliding buffer=E2=80=9D (=
untested).

3.  Is the error-proneness sufficiently reduced?  I=E2=80=99m too biased to=
 answer that question myself.

At any rate, I think this at least addresses the technical problems with th=
e proposal.  Please feel free to take this and run with it.  At this point =
I=E2=80=99m not planning on proposing it.

Howard

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.


Author: inkwizytoryankes@gmail.com
Date: Sun, 15 Feb 2015 06:05:06 -0800 (PST)
Raw View
------=_Part_40_1741966592.1424009106296
Content-Type: multipart/alternative;
 boundary="----=_Part_41_587952193.1424009106296"

------=_Part_41_587952193.1424009106296
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I think your approach is best, it will allow handling raw vectors with very=
=20
low chance of error. This will be exactly error prone like current=20
`unique_ptr` release with custom deleter.
Overall in some simple cases this approach allow simple syntax:=20
`f(vec.release().release())`, I think this is feature because you need type=
=20
more to have dangerous effect.

Another thing is that some people wanted raw/uninitialized elements in=20
vector:
https://groups.google.com/a/isocpp.org/forum/?fromgroups#!searchin/std-prop=
osals/vector/std-proposals/d6WYvULWZCo/zuEo_CXCBpoJ
https://groups.google.com/a/isocpp.org/forum/?fromgroups=3D#!searchin/std-p=
roposals/push_back_/std-proposals/5BnNHEr07QM/i8lb7fqKSWkJ

This proposal will allow handling them without breaking vector invariants.

If `std::string` will have similar proposal then transferring data between=
=20
them will be easy (if its your version):
std::string s =3D std::string{ vec.release() };






On Saturday, February 14, 2015 at 10:49:44 PM UTC+1, Howard Hinnant wrote:
>
> On Feb 14, 2015, at 2:38 PM, Howard Hinnant <howard....@gmail.com=20
> <javascript:>> wrote:=20
>
> >=20
> > On Feb 14, 2015, at 2:28 PM, Miro Knejp <miro....@gmail.com=20
> <javascript:>> wrote:=20
> >=20
> >>=20
> >> Am 14.02.2015 um 20:10 schrieb Thiago Macieira:=20
> >>> On Saturday 14 February 2015 12:28:01 Nevin Liber wrote:=20
> >>>> You need to return three things:=20
> >>>>=20
> >>>> 1.  Pointer to the data.=20
> >>>> 2.  Number of elements.=20
> >>>> 3.  Allocator.=20
> >>> Make it 4:=20
> >>>=20
> >>> 1. Pointer to the data=20
> >>> 2. Number of elements=20
> >>> 3. Pointer to be passed to the allocator to be freed=20
> >>> 4. Allocator=20
> >> 5. Total capacity of the allocated block for further shenanigans=20
> >=20
> > <nod>=20
> >=20
> > And you can=E2=80=99t traffic in T* as the proposal says.  You must dea=
llocate=20
> vector<T>::pointer which may not be a T*.  And you can=E2=80=99t call ~T(=
)=20
> directly.  And to be consistent, you probably shouldn=E2=80=99t call=20
> allocator.deallocate() directly either, though I can see a rationale that=
=20
> says there=E2=80=99s no way to get into trouble if you do (a very subtle =
point).=20
>  And when calling allocator_traits<Allocator>::destroy, you must correctl=
y=20
> convert vector<T>::pointer to a T*.  And please don=E2=80=99t do any of t=
his in a=20
> way that could compromise basic exception safety.=20
>
> It occurs to me that one way to rescue this proposal is to follow the=20
> spirit of:=20
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3586.pdf=20
>
> 1.  Introduce a nested type vector<T, A>::node_ptr.=20
>
> 2.  node_ptr is an alias for unique_ptr<T[], allocator_deleter<T, A>>.=20
>
> 3.  allocator_deleter<T, A> looks something like:=20
>
>     template <class T, class Allocator>=20
>     class allocator_deleter=20
>     {=20
>     public:=20
>         using value_type     =3D T;=20
>         using allocator_type =3D Allocator;=20
>         using traits         =3D std::allocator_traits<allocator_type>;=
=20
>         using pointer        =3D typename traits::pointer;=20
>         using size_type      =3D typename traits::size_type;=20
>     private:=20
>         std::tuple<allocator_type, size_type, size_type> data_;=20
>     public:=20
>         allocator_deleter(allocator_type const& a, size_type size,=20
>                           size_type capacity) noexcept=20
>             : data_(a, size, capacity)=20
>             {}=20
>
>         void operator()(pointer p) noexcept=20
>         {=20
>             for (pointer e =3D p + std::get<1>(data_); p !=3D e;)=20
>                 traits::destroy(std::get<0>(data_), std::addressof(*--e))=
;=20
>             traits::deallocate(std::get<0>(data_), p, std::get<2>(data_))=
;=20
>         }=20
>
>         allocator_type get_allocator() const noexcept {return=20
> std::get<0>(data_);}=20
>         size_type size()               const noexcept {return=20
> std::get<1>(data_);}=20
>         size_type capacity()           const noexcept {return=20
> std::get<2>(data_);}=20
>
>         static_assert((std::is_same<value_type, typename=20
> allocator_type::value_type>::value),=20
>                       "Invalid allocator::value_type");=20
>     };=20
>
> 3a.  If allocator_deleter needs to do anything fancier than this to handl=
e=20
> details such as those Thiago alludes to, it is up to the author of vector=
=20
> to put those details into allocator_deleter.=20
>
> 3b.  allocator_deleter is not necessarily a user-accessible name.  Client=
s=20
> should reach for vector<T, A>::node_ptr::deleter_type if they need a name=
=20
> for this type.=20
>
> 4.  Introduce to vector<T, A>:=20
>
>     template <class T, class A>=20
>     typename vector<T, A>::node_ptr=20
>     release();=20
>
> 5.  Introduce an explicit vector<T, A> constructor:=20
>
>     template <class T, class A>=20
>     vector<T, A>::vector(node_ptr&& np);=20
>
> Example use:=20
>
>     int=20
>     main()=20
>     {=20
>         std::vector<X> v;=20
>         for (int i =3D 0; i < 3; ++i)=20
>             v.push_back(X(i));=20
>         auto up =3D v.release();=20
>         for (auto i =3D 0; i < up.get_deleter().size(); ++i)=20
>             std::cout << up[i] << '\n';=20
>     }=20
>
> Open questions (at least for me).=20
>
> 1.  This was fun to create.  But does it have sufficient use cases to=20
> justify standardization?  Combined with a custom allocator built on=20
> malloc/free it *might* enable the memory ownership transfer with legacy=
=20
> code capability alluded to in N4359.=20
>
> 2.  Is the API of allocator_deleter sufficiently general to serve the use=
=20
> cases it needs to?  One possibility would be to add another pointer to it=
s=20
> API to allow the first element to begin at a non-zero offset with respect=
=20
> to the allocated pointer.  This *might* allow ownership transfer between=
=20
> vector and user-defined containers such as a =E2=80=9Csliding buffer=E2=
=80=9D (untested).=20
>
> 3.  Is the error-proneness sufficiently reduced?  I=E2=80=99m too biased =
to answer=20
> that question myself.=20
>
> At any rate, I think this at least addresses the technical problems with=
=20
> the proposal.  Please feel free to take this and run with it.  At this=20
> point I=E2=80=99m not planning on proposing it.=20
>
> Howard=20
>
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_41_587952193.1424009106296
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I think your approach is best, it will allow handling raw =
vectors with very low chance of error. This will be exactly error prone lik=
e current `unique_ptr` release with custom deleter.<br>Overall in some simp=
le cases this approach allow simple syntax: `f(vec.release().release())`, I=
 think this is feature because you need type more to have dangerous effect.=
<br><br>Another thing is that some people wanted raw/uninitialized elements=
 in vector:<br>https://groups.google.com/a/isocpp.org/forum/?fromgroups#!se=
archin/std-proposals/vector/std-proposals/d6WYvULWZCo/zuEo_CXCBpoJ<br>https=
://groups.google.com/a/isocpp.org/forum/?fromgroups=3D#!searchin/std-propos=
als/push_back_/std-proposals/5BnNHEr07QM/i8lb7fqKSWkJ<br><br>This proposal =
will allow handling them without breaking vector invariants.<br><br>If `std=
::string` will have similar proposal then transferring data between them wi=
ll be easy (if its your version):<br><div class=3D"prettyprint" style=3D"ba=
ckground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); borde=
r-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"p=
rettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">::</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">string</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> s </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">string</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> vec</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">release</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span></div></code></div><br><br><br><br><br><br>On Saturday, February =
14, 2015 at 10:49:44 PM UTC+1, Howard Hinnant wrote:<blockquote class=3D"gm=
ail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc soli=
d;padding-left: 1ex;">On Feb 14, 2015, at 2:38 PM, Howard Hinnant &lt;<a hr=
ef=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"twhEhEvOA9IJ"=
 rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';return true;" on=
click=3D"this.href=3D'javascript:';return true;">howard....@gmail.com</a>&g=
t; wrote:
<br>
<br>&gt;=20
<br>&gt; On Feb 14, 2015, at 2:28 PM, Miro Knejp &lt;<a href=3D"javascript:=
" target=3D"_blank" gdf-obfuscated-mailto=3D"twhEhEvOA9IJ" rel=3D"nofollow"=
 onmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.hre=
f=3D'javascript:';return true;">miro....@gmail.com</a>&gt; wrote:
<br>&gt;=20
<br>&gt;&gt;=20
<br>&gt;&gt; Am 14.02.2015 um 20:10 schrieb Thiago Macieira:
<br>&gt;&gt;&gt; On Saturday 14 February 2015 12:28:01 Nevin Liber wrote:
<br>&gt;&gt;&gt;&gt; You need to return three things:
<br>&gt;&gt;&gt;&gt;=20
<br>&gt;&gt;&gt;&gt; 1. &nbsp;Pointer to the data.
<br>&gt;&gt;&gt;&gt; 2. &nbsp;Number of elements.
<br>&gt;&gt;&gt;&gt; 3. &nbsp;Allocator.
<br>&gt;&gt;&gt; Make it 4:
<br>&gt;&gt;&gt;=20
<br>&gt;&gt;&gt; 1. Pointer to the data
<br>&gt;&gt;&gt; 2. Number of elements
<br>&gt;&gt;&gt; 3. Pointer to be passed to the allocator to be freed
<br>&gt;&gt;&gt; 4. Allocator
<br>&gt;&gt; 5. Total capacity of the allocated block for further shenaniga=
ns
<br>&gt;=20
<br>&gt; &lt;nod&gt;
<br>&gt;=20
<br>&gt; And you can=E2=80=99t traffic in T* as the proposal says. &nbsp;Yo=
u must deallocate vector&lt;T&gt;::pointer which may not be a T*. &nbsp;And=
 you can=E2=80=99t call ~T() directly. &nbsp;And to be consistent, you prob=
ably shouldn=E2=80=99t call allocator.deallocate() directly either, though =
I can see a rationale that says there=E2=80=99s no way to get into trouble =
if you do (a very subtle point). &nbsp;And when calling allocator_traits&lt=
;Allocator&gt;::<wbr>destroy, you must correctly convert vector&lt;T&gt;::p=
ointer to a T*. &nbsp;And please don=E2=80=99t do any of this in a way that=
 could compromise basic exception safety.
<br>
<br>It occurs to me that one way to rescue this proposal is to follow the s=
pirit of:
<br>
<br><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n358=
6.pdf" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http:=
//www.google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21=
%2Fdocs%2Fpapers%2F2013%2Fn3586.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNEgAD=
w4uO6g1FOsDjYh0rPHH9b-tA';return true;" onclick=3D"this.href=3D'http://www.=
google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdoc=
s%2Fpapers%2F2013%2Fn3586.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNEgADw4uO6g=
1FOsDjYh0rPHH9b-tA';return true;">http://www.open-std.org/jtc1/<wbr>sc22/wg=
21/docs/papers/2013/<wbr>n3586.pdf</a>
<br>
<br>1. &nbsp;Introduce a nested type vector&lt;T, A&gt;::node_ptr.
<br>
<br>2. &nbsp;node_ptr is an alias for unique_ptr&lt;T[], allocator_deleter&=
lt;T, A&gt;&gt;.
<br>
<br>3. &nbsp;allocator_deleter&lt;T, A&gt; looks something like:
<br>
<br>&nbsp; &nbsp; template &lt;class T, class Allocator&gt;
<br>&nbsp; &nbsp; class allocator_deleter
<br>&nbsp; &nbsp; {
<br>&nbsp; &nbsp; public:
<br>&nbsp; &nbsp; &nbsp; &nbsp; using value_type &nbsp; &nbsp; =3D T;
<br>&nbsp; &nbsp; &nbsp; &nbsp; using allocator_type =3D Allocator;
<br>&nbsp; &nbsp; &nbsp; &nbsp; using traits &nbsp; &nbsp; &nbsp; &nbsp; =
=3D std::allocator_traits&lt;<wbr>allocator_type&gt;;
<br>&nbsp; &nbsp; &nbsp; &nbsp; using pointer &nbsp; &nbsp; &nbsp; &nbsp;=
=3D typename traits::pointer;
<br>&nbsp; &nbsp; &nbsp; &nbsp; using size_type &nbsp; &nbsp; &nbsp;=3D typ=
ename traits::size_type;
<br>&nbsp; &nbsp; private:
<br>&nbsp; &nbsp; &nbsp; &nbsp; std::tuple&lt;allocator_type, size_type, si=
ze_type&gt; data_;
<br>&nbsp; &nbsp; public:
<br>&nbsp; &nbsp; &nbsp; &nbsp; allocator_deleter(allocator_<wbr>type const=
&amp; a, size_type size,
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; size_type capacity) noexcept
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : data_(a, size, capacity)
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {}
<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; void operator()(pointer p) noexcept
<br>&nbsp; &nbsp; &nbsp; &nbsp; {
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (pointer e =3D p + std::g=
et&lt;1&gt;(data_); p !=3D e;)
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; traits::destroy=
(std::get&lt;0&gt;(<wbr>data_), std::addressof(*--e));
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; traits::deallocate(std::get&l=
t;0&gt;<wbr>(data_), p, std::get&lt;2&gt;(data_));
<br>&nbsp; &nbsp; &nbsp; &nbsp; }
<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; allocator_type get_allocator() const noexce=
pt {return std::get&lt;0&gt;(data_);}
<br>&nbsp; &nbsp; &nbsp; &nbsp; size_type size() &nbsp; &nbsp; &nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; const noexcept {return std::get&lt;1&gt;(data_);}
<br>&nbsp; &nbsp; &nbsp; &nbsp; size_type capacity() &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; const noexcept {return std::get&lt;2&gt;(data_);}
<br>
<br>&nbsp; &nbsp; &nbsp; &nbsp; static_assert((std::is_same&lt;<wbr>value_t=
ype, typename allocator_type::value_type&gt;::<wbr>value),
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; "Invalid allocator::value_type");
<br>&nbsp; &nbsp; };
<br>
<br>3a. &nbsp;If allocator_deleter needs to do anything fancier than this t=
o handle details such as those Thiago alludes to, it is up to the author of=
 vector to put those details into allocator_deleter.
<br>
<br>3b. &nbsp;allocator_deleter is not necessarily a user-accessible name. =
&nbsp;Clients should reach for vector&lt;T, A&gt;::node_ptr::deleter_type i=
f they need a name for this type.
<br>
<br>4. &nbsp;Introduce to vector&lt;T, A&gt;:
<br>
<br>&nbsp; &nbsp; template &lt;class T, class A&gt;
<br>&nbsp; &nbsp; typename vector&lt;T, A&gt;::node_ptr
<br>&nbsp; &nbsp; release();
<br>
<br>5. &nbsp;Introduce an explicit vector&lt;T, A&gt; constructor:
<br>
<br>&nbsp; &nbsp; template &lt;class T, class A&gt;
<br>&nbsp; &nbsp; vector&lt;T, A&gt;::vector(node_ptr&amp;&amp; np);
<br>
<br>Example use:
<br>
<br>&nbsp; &nbsp; int
<br>&nbsp; &nbsp; main()
<br>&nbsp; &nbsp; {
<br>&nbsp; &nbsp; &nbsp; &nbsp; std::vector&lt;X&gt; v;
<br>&nbsp; &nbsp; &nbsp; &nbsp; for (int i =3D 0; i &lt; 3; ++i)
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v.push_back(X(i));
<br>&nbsp; &nbsp; &nbsp; &nbsp; auto up =3D v.release();
<br>&nbsp; &nbsp; &nbsp; &nbsp; for (auto i =3D 0; i &lt; up.get_deleter().=
size(); ++i)
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; std::cout &lt;&lt; up[i] &lt;=
&lt; '\n';
<br>&nbsp; &nbsp; }
<br>
<br>Open questions (at least for me).
<br>
<br>1. &nbsp;This was fun to create. &nbsp;But does it have sufficient use =
cases to justify standardization? &nbsp;Combined with a custom allocator bu=
ilt on malloc/free it *might* enable the memory ownership transfer with leg=
acy code capability alluded to in N4359.
<br>
<br>2. &nbsp;Is the API of allocator_deleter sufficiently general to serve =
the use cases it needs to? &nbsp;One possibility would be to add another po=
inter to its API to allow the first element to begin at a non-zero offset w=
ith respect to the allocated pointer. &nbsp;This *might* allow ownership tr=
ansfer between vector and user-defined containers such as a =E2=80=9Cslidin=
g buffer=E2=80=9D (untested).
<br>
<br>3. &nbsp;Is the error-proneness sufficiently reduced? &nbsp;I=E2=80=99m=
 too biased to answer that question myself.
<br>
<br>At any rate, I think this at least addresses the technical problems wit=
h the proposal. &nbsp;Please feel free to take this and run with it. &nbsp;=
At this point I=E2=80=99m not planning on proposing it.
<br>
<br>Howard
<br>
<br></blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_41_587952193.1424009106296--
------=_Part_40_1741966592.1424009106296--

.


Author: gmisocpp@gmail.com
Date: Tue, 17 Feb 2015 05:37:57 -0800 (PST)
Raw View
------=_Part_2509_368091990.1424180277934
Content-Type: multipart/alternative;
 boundary="----=_Part_2510_1769172570.1424180277935"

------=_Part_2510_1769172570.1424180277935
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I think the concept behind this proposal has a whole heap (groan) of merit.

I was recently doing something that made me want the OP's proposal already.

That sent me on the look out for something appropriate and I saw others=20
before me felt the same, see this:
http://www.codesynthesis.com/~boris/blog/2011/08/09/do-we-need-std-buffer/
Notice the Detach method. I think the demand for memory interop is high.

vector is a starting point, but that begs the question of string too, as=20
someone else already pointed out.

But more new / malloc  free / delete interoperability would be something=20
worth exploring deeply in my opinion.
Now that C++ has move semantics, maybe a C++ renew ability to match realloc=
=20
makes sense too.
And generally more ability to gain more precise control over memory would=
=20
be good if it is reasonably possible.

I think C style interfaces will not lessen in value, just gain more C++ on=
=20
the inside of them as well as outside, so if C++ can support that better=20
without totally compromising itself, then I think that would be a good=20
thing for both languages. It seems the analysis needs to go beyond just=20
vector.

Maybe a C++ memory transfer / compatibility Study Group is appropriate here=
?

On Sunday, February 15, 2015 at 4:17:00 AM UTC+13, Klaim - Jo=C3=ABl Lamott=
e=20
wrote:

> While reading N4359 it occured to me that while a release()  operation
> would be useful for the same reasons than unique_ptr's release() operatio=
n
> is useful, vector do not have a way to acquire ownership
> of a manually provided array of data.
>
> That is, if an array is released from a vector, it cannot be inserted in=
=20
> another vector
> without copying it.
>
> It seems to me that this is a missed opportunity in cases where=20
> you get a dynamically allocated array from one API and you want=20
> to manage it in as a vector in your code. That is, you want to keep the
> growing behaviour of vector (otherwise you would use a unique_pointer wit=
h=20
> array)
> but you also want to avoid an array copy and delete when getting an array=
=20
> from
> a C api for example.
>
> Ownership acquisition would be implemented as a constructor (maybe tagged=
=20
> by a parametter to help clarity)
> and an member function.
> I exclude assignment operator overloads because there is a need to provid=
e=20
> the size=20
> and and maybe a (polymophic?) allocator to the vector.
>
> Of course this ownership acquisition would be less safe than the current=
=20
> copy behaviour
> but it would be useful for high performance applications in contexts=20
> described as before.
>
>
> Any thoughts on this?
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_2510_1769172570.1424180277935
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I think the concept behind this proposal has&nbsp;a w=
hole heap (groan)&nbsp;of merit.</div><div><br></div><div>I was recently do=
ing something that made me want the OP's&nbsp;proposal already.</div><div><=
br></div><div>That&nbsp;sent me on the look out for something appropriate a=
nd I saw others before me felt the same, see this:</div><div><a href=3D"htt=
p://www.codesynthesis.com/~boris/blog/2011/08/09/do-we-need-std-buffer/">ht=
tp://www.codesynthesis.com/~boris/blog/2011/08/09/do-we-need-std-buffer/</a=
></div><div>Notice the Detach method.&nbsp;I think the demand&nbsp;for memo=
ry&nbsp;interop&nbsp;is high.</div><div><br></div><div>vector is a starting=
 point, but that begs the question of string too,&nbsp;as someone else alre=
ady pointed out.</div><div><br></div><div>But more new / malloc&nbsp; free =
/ delete&nbsp;interoperability would be&nbsp;something worth exploring deep=
ly in my opinion.</div><div>Now that C++ has move semantics, maybe a C++ re=
new ability to match realloc makes sense too.</div><div>And generally more =
ability to gain more precise control over&nbsp;memory would be good if it i=
s reasonably possible.</div><div><br></div><div>I think C style interfaces =
will not lessen in value, just gain more&nbsp;C++ on the inside of them as =
well as&nbsp;outside, so if C++ can&nbsp;support&nbsp;that better without t=
otally compromising itself, then I think that would be a good thing for bot=
h languages. It seems the analysis needs to go beyond just vector.</div><di=
v><br></div><div><div>Maybe&nbsp;a C++&nbsp;memory transfer / compatibility=
 Study Group is appropriate here?</div></div><div><br>On Sunday, February 1=
5, 2015 at 4:17:00 AM UTC+13, Klaim - Jo=C3=ABl Lamotte wrote:</div><blockq=
uote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left=
: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; borde=
r-left-style: solid;"><div dir=3D"ltr">While reading N4359 it occured to me=
 that while a release() &nbsp;operation<div>would be useful for the same re=
asons than unique_ptr's release() operation</div><div>is useful, vector do =
not have a way to acquire ownership</div><div>of a manually provided array =
of data.</div><div><br></div><div>That is, if an array is released from a v=
ector, it cannot be inserted in another vector</div><div>without copying it=
..</div><div><br></div><div>It seems to me that this is a missed opportunity=
 in cases where&nbsp;</div><div>you get a dynamically allocated array from =
one API and you want&nbsp;</div><div>to manage it in as a vector in your co=
de. That is, you want to keep the</div><div>growing behaviour of vector (ot=
herwise you would use a unique_pointer with array)</div><div>but you also w=
ant to avoid an array copy and delete when getting an array from</div><div>=
a C api for example.</div><div><br></div><div>Ownership acquisition would b=
e implemented as a constructor (maybe tagged by a parametter to help clarit=
y)</div><div>and an member function.<br></div><div>I exclude assignment ope=
rator overloads because there is a need to provide the size&nbsp;</div><div=
>and and maybe a (polymophic?) allocator to the vector.</div><div><br></div=
><div>Of course this ownership acquisition would be less safe than the curr=
ent copy behaviour</div><div>but it would be useful for high performance ap=
plications in contexts described as before.</div><div><br></div><div><br></=
div><div>Any thoughts on this?</div></div>
</blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2510_1769172570.1424180277935--
------=_Part_2509_368091990.1424180277934--

.


Author: Jeremy Maitin-Shepard <jeremy@jeremyms.com>
Date: Thu, 19 Feb 2015 08:59:26 -0800 (PST)
Raw View
------=_Part_4699_1783464917.1424365166944
Content-Type: multipart/alternative;
 boundary="----=_Part_4700_118115193.1424365166944"

------=_Part_4700_118115193.1424365166944
Content-Type: text/plain; charset=UTF-8

On Saturday, February 14, 2015 at 1:49:44 PM UTC-8, Howard Hinnant wrote:
>
>
> It occurs to me that one way to rescue this proposal is to follow the
> spirit of:
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3586.pdf
>
> 1.  Introduce a nested type vector<T, A>::node_ptr.
>
> 2.  node_ptr is an alias for unique_ptr<T[], allocator_deleter<T, A>>.
>
> 3.  allocator_deleter<T, A> looks something like:
> [snip]
>

I think we have to consider what the underlying goal is.  One thing that a
lot of people would like to do is use std::vector as a generic buffer
interface.  Release without attach doesn't seem very useful.  I am having
trouble understanding in what circumstance this "node_ptr" would actually
be useful, rather than just using std::vector itself.  A shared_ptr
representing the contents of a vector is already possible by moving the
vector into the deleter.

The real problem, I think, is that without standardizing exactly how
std::vector uses the allocator, release and attach don't make a lot of
sense.  If we standardize that std::vector does the obvious thing with the
allocator, and doesn't do any tricks like putting a header at the start of
the allocated memory, then it starts to be a very powerful thing.  The
default allocator would work for buffers allocated with new [], a
malloc/free allocator could be defined for memory obtain via malloc, and
std::vector would be the generic buffer interface.  We just need to add a
few more methods to allow users to directly manipulate the size without
invoking any constructors/destructors.  I don't think there is any
advantage in having a separate type to hold the released data, as it woulld
really be equivalent to std::vector itself.

There is the question of whether any implementation does anything fancy
with the allocator that would conflict with these new requirements.
Hopefully not.  Potentially this would be a good time to finally blow away
vector<bool>.

Alternatively, to avoid ABI breaks, a new class std::buffer or something
could be defined with these requirements, and std::vector could be
deprecated.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_4700_118115193.1424365166944
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Saturday, February 14, 2015 at 1:49:44 PM UTC-8, Howard=
 Hinnant wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br>It occurs t=
o me that one way to rescue this proposal is to follow the spirit of:
<br>
<br><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n358=
6.pdf" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http:=
//www.google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21=
%2Fdocs%2Fpapers%2F2013%2Fn3586.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNEgAD=
w4uO6g1FOsDjYh0rPHH9b-tA';return true;" onclick=3D"this.href=3D'http://www.=
google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdoc=
s%2Fpapers%2F2013%2Fn3586.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNEgADw4uO6g=
1FOsDjYh0rPHH9b-tA';return true;">http://www.open-std.org/jtc1/<wbr>sc22/wg=
21/docs/papers/2013/<wbr>n3586.pdf</a>
<br>
<br>1. &nbsp;Introduce a nested type vector&lt;T, A&gt;::node_ptr.
<br>
<br>2. &nbsp;node_ptr is an alias for unique_ptr&lt;T[], allocator_deleter&=
lt;T, A&gt;&gt;.
<br>
<br>3. &nbsp;allocator_deleter&lt;T, A&gt; looks something like:
<br>
[snip]<br></blockquote><div><br>I think we have to consider what the underl=
ying goal is.&nbsp; One thing that a lot of people would like to do is use =
std::vector as a generic buffer interface.&nbsp; Release without attach doe=
sn't seem very useful.&nbsp; I am having trouble understanding in what circ=
umstance this "node_ptr" would actually be useful, rather than just using s=
td::vector itself.&nbsp; A shared_ptr representing the contents of a vector=
 is already possible by moving the vector into the deleter.<br><br>The real=
 problem, I think, is that without standardizing exactly how std::vector us=
es the allocator, release and attach don't make a lot of sense.&nbsp; If we=
 standardize that std::vector does the obvious thing with the allocator, an=
d doesn't do any tricks like putting a header at the start of the allocated=
 memory, then it starts to be a very powerful thing.&nbsp; The default allo=
cator would work for buffers allocated with new [], a malloc/free allocator=
 could be defined for memory obtain via malloc, and std::vector would be th=
e generic buffer interface.&nbsp; We just need to add a few more methods to=
 allow users to directly manipulate the size without invoking any construct=
ors/destructors.&nbsp; I don't think there is any advantage in having a sep=
arate type to hold the released data, as it woulld really be equivalent to =
std::vector itself.<br><br>There is the question of whether any implementat=
ion does anything fancy with the allocator that would conflict with these n=
ew requirements.&nbsp; Hopefully not.&nbsp; Potentially this would be a goo=
d time to finally blow away vector&lt;bool&gt;.<br><br>Alternatively, to av=
oid ABI breaks, a new class std::buffer or something could be defined with =
these requirements, and std::vector could be deprecated.<br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_4700_118115193.1424365166944--
------=_Part_4699_1783464917.1424365166944--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 19 Feb 2015 19:26:06 +0200
Raw View
On 19 February 2015 at 18:59, Jeremy Maitin-Shepard <jeremy@jeremyms.com> wrote:
> There is the question of whether any implementation does anything fancy with
> the allocator that would conflict with these new requirements.  Hopefully
> not.  Potentially this would be a good time to finally blow away
> vector<bool>.

Well, if there is a superior replacement, such "blowing away" might be
considered..

> Alternatively, to avoid ABI breaks, a new class std::buffer or something
> could be defined with these requirements, and std::vector could be
> deprecated.

...but there are some things that don't make sense to deprecate even if you
come up with a superior replacement. If you want to extend vector with new
capabilities, the next version of the standard library might perhaps be a good
place for such a thing, *if* we end up not making it fully compatible.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: gmisocpp@gmail.com
Date: Thu, 19 Feb 2015 20:04:59 -0800 (PST)
Raw View
------=_Part_319_435404472.1424405099993
Content-Type: multipart/alternative;
 boundary="----=_Part_320_1366175575.1424405099993"

------=_Part_320_1366175575.1424405099993
Content-Type: text/plain; charset=UTF-8


>
>
> I think we have to consider what the underlying goal is.  One thing that a
> lot of people would like to do is use std::vector as a generic buffer
> interface.  Release without attach doesn't seem very useful.
>

Yes that's what I was getting at in my earlier post - vector having attach
and detach buffer functions like the Buffer class I linked to. Plus full
interchange between new malloc realloc and free and delete.

It would be useful to make string have the same facilities but if I'm
thinking clearly here small string optimization might make that
interface problematic as you would logically think that anytime you had a
string you could detach the buffer and use it as a char[] array, but if the
buffer was in the SSO area you would effectively be asking for an
allocation to Detach it and that might be a surprising point of
failure. You could give up SSO but I don't know if people would or should
vote for that. Or maybe their is another workable interface but
otherwise it could get a little fiddly. I don't know how viable any of this
is in reality. Maybe supporting this is too limiting for the types. But it
seems a worthwhile discussion to have though.

Ville talks about a new STL. Would people want this ability from a new STL
if it were possible? I believe I would, but I don't know what the costs of
getting it are. i.e. what will get more difficult or will I lose elsewhere
if I get this. If that cost turns out more than I expected, maybe I
wouldn't want this feature after all. But until then I know for sure,
it seems appealing.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_320_1366175575.1424405099993
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px=
 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); borde=
r-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr"><div><br>I t=
hink we have to consider what the underlying goal is.&nbsp; One thing that =
a lot of people would like to do is use std::vector as a generic buffer int=
erface.&nbsp; Release without attach doesn't seem very useful.&nbsp;</div><=
/div></blockquote><div><br></div><div>Yes that's what I was getting at in m=
y earlier post -&nbsp;vector having&nbsp;attach and&nbsp;detach buffer&nbsp=
;functions like the&nbsp;Buffer&nbsp;class&nbsp;I linked to.&nbsp;Plus full=
 interchange&nbsp;between new malloc realloc and free and delete.</div><div=
><br></div><div>It would be useful to make string have the same facilities =
but if I'm thinking clearly here&nbsp;small string optimization might make =
that interface&nbsp;problematic as you would logically think that anytime y=
ou&nbsp;had a string you could detach the buffer and use it as a char[] arr=
ay, but if the buffer was in the SSO area&nbsp;you would effectively be ask=
ing for an allocation to Detach it and that&nbsp;might be a surprising poin=
t of failure.&nbsp;You could give up SSO but I don't&nbsp;know if&nbsp;peop=
le would or should vote for that. Or maybe their is another workable interf=
ace but otherwise&nbsp;it could get&nbsp;a little fiddly. I don't know how =
viable any of this is in reality.&nbsp;Maybe&nbsp;supporting this&nbsp;is t=
oo limiting for the types. But it seems a worthwhile discussion to have tho=
ugh.</div><div><br></div><div>Ville talks about a new STL. Would people wan=
t this&nbsp;ability from&nbsp;a new STL if it were possible? I believe I wo=
uld, but I don't know what the costs of getting it are. i.e. what will get =
more difficult or will I lose elsewhere if I get this. If that cost turns o=
ut more than I expected, maybe I wouldn't want this feature after all. But =
until then&nbsp;I know for&nbsp;sure, it&nbsp;seems appealing.</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_320_1366175575.1424405099993--
------=_Part_319_435404472.1424405099993--

.


Author: Jeremy Maitin-Shepard <jeremy@jeremyms.com>
Date: Thu, 19 Feb 2015 20:11:57 -0800
Raw View
--001a11c3491cdc9921050f7d40ed
Content-Type: text/plain; charset=UTF-8

On Thu, Feb 19, 2015 at 9:26 AM, Ville Voutilainen <
ville.voutilainen@gmail.com> wrote:

> On 19 February 2015 at 18:59, Jeremy Maitin-Shepard <jeremy@jeremyms.com>
> wrote:
> > There is the question of whether any implementation does anything fancy
> with
> > the allocator that would conflict with these new requirements.  Hopefully
> > not.  Potentially this would be a good time to finally blow away
> > vector<bool>.
>
> Well, if there is a superior replacement, such "blowing away" might be
> considered..
>

It hardly needs to be repeated, but the main problem with vector<bool> is
its name.  Changing it to bitvector would at least solve much of the
problem.  I'm sure there is a lot that could be improved about its
interface, but just providing a way to reliably *avoid* it in generic code
would be a good start.


>
> > Alternatively, to avoid ABI breaks, a new class std::buffer or something
> > could be defined with these requirements, and std::vector could be
> > deprecated.
>
> ..but there are some things that don't make sense to deprecate even if you
> come up with a superior replacement. If you want to extend vector with new
> capabilities, the next version of the standard library might perhaps be a
> good
> place for such a thing, *if* we end up not making it fully compatible.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--001a11c3491cdc9921050f7d40ed
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Thu, Feb 19, 2015 at 9:26 AM, Ville Voutilainen <span d=
ir=3D"ltr">&lt;<a href=3D"mailto:ville.voutilainen@gmail.com" target=3D"_bl=
ank">ville.voutilainen@gmail.com</a>&gt;</span> wrote:<br><div class=3D"gma=
il_extra"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span c=
lass=3D"">On 19 February 2015 at 18:59, Jeremy Maitin-Shepard &lt;<a href=
=3D"mailto:jeremy@jeremyms.com">jeremy@jeremyms.com</a>&gt; wrote:<br>
&gt; There is the question of whether any implementation does anything fanc=
y with<br>
&gt; the allocator that would conflict with these new requirements.=C2=A0 H=
opefully<br>
&gt; not.=C2=A0 Potentially this would be a good time to finally blow away<=
br>
&gt; vector&lt;bool&gt;.<br>
<br>
</span>Well, if there is a superior replacement, such &quot;blowing away&qu=
ot; might be<br>
considered..<br></blockquote><div><br></div><div>It hardly needs to be repe=
ated, but the main problem with vector&lt;bool&gt; is its name.=C2=A0 Chang=
ing it to bitvector would at least solve much of the problem.=C2=A0 I&#39;m=
 sure there is a lot that could be improved about its interface, but just p=
roviding a way to reliably *avoid* it in generic code would be a good start=
..<br></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=3D""><br>
&gt; Alternatively, to avoid ABI breaks, a new class std::buffer or somethi=
ng<br>
&gt; could be defined with these requirements, and std::vector could be<br>
&gt; deprecated.<br>
<br>
</span>..but there are some things that don&#39;t make sense to deprecate e=
ven if you<br>
come up with a superior replacement. If you want to extend vector with new<=
br>
capabilities, the next version of the standard library might perhaps be a g=
ood<br>
place for such a thing, *if* we end up not making it fully compatible.=C2=
=A0=C2=A0</blockquote></div><br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11c3491cdc9921050f7d40ed--

.


Author: Jeremy Maitin-Shepard <jeremy@jeremyms.com>
Date: Thu, 19 Feb 2015 20:17:54 -0800
Raw View
--001a11342dfc27aa52050f7d56bf
Content-Type: text/plain; charset=UTF-8

I agree that supporting it for std::string would be very useful (and more
generally allowing inexpensive moving between string and vector).  In the
case that SSO is used, an allocation would be required, but that wouldn't
necessarily be a problem, since I imagine that most of the time release() a
heap buffer really is required and if there isn't already one, it would
have to be allocated.  The main issue here would be the same as with
vector: the precise way in which string uses the allocator would have to be
defined by the standard, and it is possible that this would mean an ABI
break for some implementations.


On Thu, Feb 19, 2015 at 8:04 PM, <gmisocpp@gmail.com> wrote:

>
>> I think we have to consider what the underlying goal is.  One thing that
>> a lot of people would like to do is use std::vector as a generic buffer
>> interface.  Release without attach doesn't seem very useful.
>>
>
> Yes that's what I was getting at in my earlier post - vector having attach
> and detach buffer functions like the Buffer class I linked to. Plus full
> interchange between new malloc realloc and free and delete.
>
> It would be useful to make string have the same facilities but if I'm
> thinking clearly here small string optimization might make that
> interface problematic as you would logically think that anytime you had a
> string you could detach the buffer and use it as a char[] array, but if the
> buffer was in the SSO area you would effectively be asking for an
> allocation to Detach it and that might be a surprising point of
> failure. You could give up SSO but I don't know if people would or should
> vote for that. Or maybe their is another workable interface but
> otherwise it could get a little fiddly. I don't know how viable any of this
> is in reality. Maybe supporting this is too limiting for the types. But it
> seems a worthwhile discussion to have though.
>
> Ville talks about a new STL. Would people want this ability from a new STL
> if it were possible? I believe I would, but I don't know what the costs of
> getting it are. i.e. what will get more difficult or will I lose elsewhere
> if I get this. If that cost turns out more than I expected, maybe I
> wouldn't want this feature after all. But until then I know for sure,
> it seems appealing.
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/a/isocpp.org/d/topic/std-proposals/H2-dd8sFAKA/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--001a11342dfc27aa52050f7d56bf
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I agree that supporting it for std::string would be v=
ery useful (and more generally allowing inexpensive moving between string a=
nd vector).=C2=A0 In the case that SSO is used, an allocation would be requ=
ired, but that wouldn&#39;t necessarily be a problem, since I imagine that =
most of the time release() a heap buffer really is required and if there is=
n&#39;t already one, it would have to be allocated.=C2=A0 The main issue he=
re would be the same as with vector: the precise way in which string uses t=
he allocator would have to be defined by the standard, and it is possible t=
hat this would mean an ABI break for some implementations.<br><br></div></d=
iv><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Thu, Feb 19=
, 2015 at 8:04 PM,  <span dir=3D"ltr">&lt;<a href=3D"mailto:gmisocpp@gmail.=
com" target=3D"_blank">gmisocpp@gmail.com</a>&gt;</span> wrote:<br><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr"><span class=3D""><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-=
left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">=
<div dir=3D"ltr"><div><br>I think we have to consider what the underlying g=
oal is.=C2=A0 One thing that a lot of people would like to do is use std::v=
ector as a generic buffer interface.=C2=A0 Release without attach doesn&#39=
;t seem very useful.=C2=A0</div></div></blockquote><div><br></div></span><d=
iv>Yes that&#39;s what I was getting at in my earlier post -=C2=A0vector ha=
ving=C2=A0attach and=C2=A0detach buffer=C2=A0functions like the=C2=A0Buffer=
=C2=A0class=C2=A0I linked to.=C2=A0Plus full interchange=C2=A0between new m=
alloc realloc and free and delete.</div><div><br></div><div>It would be use=
ful to make string have the same facilities but if I&#39;m thinking clearly=
 here=C2=A0small string optimization might make that interface=C2=A0problem=
atic as you would logically think that anytime you=C2=A0had a string you co=
uld detach the buffer and use it as a char[] array, but if the buffer was i=
n the SSO area=C2=A0you would effectively be asking for an allocation to De=
tach it and that=C2=A0might be a surprising point of failure.=C2=A0You coul=
d give up SSO but I don&#39;t=C2=A0know if=C2=A0people would or should vote=
 for that. Or maybe their is another workable interface but otherwise=C2=A0=
it could get=C2=A0a little fiddly. I don&#39;t know how viable any of this =
is in reality.=C2=A0Maybe=C2=A0supporting this=C2=A0is too limiting for the=
 types. But it seems a worthwhile discussion to have though.</div><div><br>=
</div><div>Ville talks about a new STL. Would people want this=C2=A0ability=
 from=C2=A0a new STL if it were possible? I believe I would, but I don&#39;=
t know what the costs of getting it are. i.e. what will get more difficult =
or will I lose elsewhere if I get this. If that cost turns out more than I =
expected, maybe I wouldn&#39;t want this feature after all. But until then=
=C2=A0I know for=C2=A0sure, it=C2=A0seems appealing.</div></div><div class=
=3D"HOEnZb"><div class=3D"h5">

<p></p>

-- <br>
<br>
--- <br>
You received this message because you are subscribed to a topic in the Goog=
le Groups &quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
a/isocpp.org/d/topic/std-proposals/H2-dd8sFAKA/unsubscribe" target=3D"_blan=
k">https://groups.google.com/a/isocpp.org/d/topic/std-proposals/H2-dd8sFAKA=
/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_blank">std-prop=
osals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11342dfc27aa52050f7d56bf--

.


Author: jerry.liangmysy@gmail.com
Date: Mon, 27 Apr 2015 02:33:22 -0700 (PDT)
Raw View
------=_Part_3967_1163274759.1430127202797
Content-Type: multipart/alternative;
 boundary="----=_Part_3968_467752225.1430127202797"

------=_Part_3968_467752225.1430127202797
Content-Type: text/plain; charset=UTF-8

I think we should be wiser, thinking that calling release definitely cause
losing of some information.
This imperfection should be introduced to solve a problem that we can't
solve yesterday. In many situations I need a release operation,so I access
the private field of a vector to achieve that but then I lose portability.

I would like to see the problem going away for some reason and we can
transfer the ownership of the internal array.
I would also like to see there is no such thing as release. If we have to
have a release, it should be simple, and not dangerous in most cases.


>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_3968_467752225.1430127202797
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I think we should be wiser, thinking that calling release =
definitely cause losing of some information.&nbsp;<div>This imperfection sh=
ould be introduced to solve a problem that we can't solve yesterday. In man=
y situations I need a release operation,so I access the private field of a =
vector to achieve that but then I lose portability.</div><div><br></div><di=
v>I would like to see the problem going away for some reason and we can tra=
nsfer the ownership of the internal array.</div><div>I would also like to s=
ee there is no such thing as release. If we have to have a release, it shou=
ld be simple, and not dangerous in most cases.</div><div><br><blockquote cl=
ass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px =
#ccc solid;padding-left: 1ex;"><br>
</blockquote></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3968_467752225.1430127202797--
------=_Part_3967_1163274759.1430127202797--

.


Author: Marc <marc.glisse@gmail.com>
Date: Mon, 27 Apr 2015 04:12:16 -0700 (PDT)
Raw View
------=_Part_183_1032320293.1430133136296
Content-Type: multipart/alternative;
 boundary="----=_Part_184_686780338.1430133136296"

------=_Part_184_686780338.1430133136296
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Le samedi 14 f=C3=A9vrier 2015 20:10:09 UTC+1, Thiago Macieira a =C3=A9crit=
 :

> std::vector may allocate a a block of data that is bigger than the actual=
=20
> array and it may store some book-keeping information at the beginning of=
=20
> such=20
> a block. Example:=20
>
> template <typename T, typanem Allocator>=20
> struct vector_data=20
> {=20
>         size_t count;=20
>         size_t capacity;=20
>         Allocator allocator;=20
>         T array[0];                // compiler extension support=20
> };=20
>
> template <class T, class Allocator =3D allocator<T> >=20
> class vector=20
> {=20
>         vector_data<T, Allocator> data;=20
>         [...]=20
> };=20
>

(data is probably a pointer to vector_data)
Not directly related to this thread, but do you know why none of the common=
=20
implementations of std::vector chose such a strategy? Mozilla has nsTArray=
=20
but restricted to POD types, std::string was like this in libstdc++, but I=
=20
don't see any real vector. In some applications, having a lot of empty=20
vectors can be very convenient, and if it only takes one pointer it is=20
actually efficient. So I am wondering if the choice was done for a small=20
speed-up when computing the size of a vector, or if there are=20
implementation difficulties (possibly due to allocators? Or because the=20
most efficient way to handle the empty vector is pointing to a singleton=20
object and windows still has issues with that across DLLs?).

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

------=_Part_184_686780338.1430133136296
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Le samedi 14 f=C3=A9vrier 2015 20:10:09 UTC+1, Thiago Maci=
eira a =C3=A9crit&nbsp;:<br><blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">st=
d::vector may allocate a a block of data that is bigger than the actual=20
<br>array and it may store some book-keeping information at the beginning o=
f such=20
<br>a block. Example:
<br>
<br>template &lt;typename T, typanem Allocator&gt;=20
<br>struct vector_data
<br>{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size_t count;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size_t capacity;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Allocator allocator;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T array[0];&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;// compiler extension support
<br>};
<br>
<br>template &lt;class T, class Allocator =3D allocator&lt;T&gt; &gt;
<br>class vector
<br>{
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vector_data&lt;T, Alloc=
ator&gt; data;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[...]
<br>};
<br></blockquote><div><br>(data is probably a pointer to vector_data)<br>No=
t directly related to this thread, but do you know why none of the common i=
mplementations of std::vector chose such a strategy? Mozilla has nsTArray b=
ut restricted to POD types, std::string was like this in libstdc++, but I d=
on't see any real vector. In some applications, having a lot of empty vecto=
rs can be very convenient, and if it only takes one pointer it is actually =
efficient. So I am wondering if the choice was done for a small speed-up wh=
en computing the size of a vector, or if there are implementation difficult=
ies (possibly due to allocators? Or because the most efficient way to handl=
e the empty vector is pointing to a singleton object and windows still has =
issues with that across DLLs?).<br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_184_686780338.1430133136296--
------=_Part_183_1032320293.1430133136296--

.