Topic: make_array_view()


Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 12 Nov 2014 16:18:30 -0800 (PST)
Raw View
------=_Part_2430_1047223446.1415837910980
Content-Type: text/plain; charset=UTF-8

Currently with array_view, you have to repeat the type twice when you
create a temporary:

std::vector<SomeType> storage;
std::array_view<SomeType> view = storage;
std::carray_view<SomeType> const_view = storage;



We should have make functions to avoid this ambiguity:

template <typename T>
auto make_array_view(T& container) {
  return array_view<remove_pointer_t<decltype(container.data())>>(container
);
}


template <typename T>
auto make_carray_view(const T& container) {
 return carray_view<remove_pointer_t<decltype(container.data())>>(container
);
}

//also have C array overloads..

Where we can now use auto and avoid duplicating the type:

vector<SomeType> storage;
auto view = make_array_view(storage);
auto const_view = make_carray_view(storage);



--

---
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_2430_1047223446.1415837910980
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Currently with array_view, you have to repeat the typ=
e twice when you create a temporary:</div><div>&nbsp;</div><div style=3D"bo=
rder: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color=
: rgb(250, 250, 250);" class=3D"prettyprint"><code class=3D"prettyprint"><d=
iv class=3D"subprettyprint"><span style=3D"color: rgb(0, 0, 0);" class=3D"s=
tyled-by-prettify">std</span><span style=3D"color: rgb(102, 102, 0);" class=
=3D"styled-by-prettify">::</span><span style=3D"color: rgb(0, 0, 0);" class=
=3D"styled-by-prettify">vector</span><span style=3D"color: rgb(102, 102, 0)=
;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: rgb(102, 0=
, 102);" class=3D"styled-by-prettify">SomeType</span><span style=3D"color: =
rgb(102, 102, 0);" class=3D"styled-by-prettify">&gt;</span><span style=3D"c=
olor: rgb(0, 0, 0);" class=3D"styled-by-prettify"> storage</span><span styl=
e=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"><br>std</span><s=
pan style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify">array_v=
iew</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prett=
ify">&lt;</span><span style=3D"color: rgb(102, 0, 102);" class=3D"styled-by=
-prettify">SomeType</span><span style=3D"color: rgb(102, 102, 0);" class=3D=
"styled-by-prettify">&gt;</span><span style=3D"color: rgb(0, 0, 0);" class=
=3D"styled-by-prettify"> view </span><span style=3D"color: rgb(102, 102, 0)=
;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: rgb(0, 0, 0=
);" class=3D"styled-by-prettify"> storage</span><span style=3D"color: rgb(1=
02, 102, 0);" class=3D"styled-by-prettify">;</span><span style=3D"color: rg=
b(0, 0, 0);" class=3D"styled-by-prettify"><br>std</span><span style=3D"colo=
r: rgb(102, 102, 0);" class=3D"styled-by-prettify">::</span><span style=3D"=
color: rgb(0, 0, 0);" class=3D"styled-by-prettify">carray_view</span><span =
style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">&lt;</span>=
<span style=3D"color: rgb(102, 0, 102);" class=3D"styled-by-prettify">SomeT=
ype</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prett=
ify">&gt;</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-pre=
ttify"> const_view </span><span style=3D"color: rgb(102, 102, 0);" class=3D=
"styled-by-prettify">=3D</span><span style=3D"color: rgb(0, 0, 0);" class=
=3D"styled-by-prettify"> storage</span><span style=3D"color: rgb(102, 102, =
0);" class=3D"styled-by-prettify">;</span></div></code></div><div><br>&nbsp=
;</div><div>&nbsp;</div><div>We should have make functions to avoid this am=
biguity:</div><div>&nbsp;</div><div style=3D"border: 1px solid rgb(187, 187=
, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);" class=
=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettify">templat=
e</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> =
</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify=
">&lt;</span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-pret=
tify">typename</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-b=
y-prettify"> T</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styl=
ed-by-prettify">&gt;</span><span style=3D"color: rgb(0, 0, 0);" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: rgb(0, 0, 136);" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: rgb(0, 0, 0);" cla=
ss=3D"styled-by-prettify"> make_array_view</span><span style=3D"color: rgb(=
102, 102, 0);" class=3D"styled-by-prettify">(</span><span style=3D"color: r=
gb(0, 0, 0);" class=3D"styled-by-prettify">T</span><span style=3D"color: rg=
b(102, 102, 0);" class=3D"styled-by-prettify">&amp;</span><span style=3D"co=
lor: rgb(0, 0, 0);" class=3D"styled-by-prettify"> container</span><span sty=
le=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">)</span><span =
style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">{</span><spa=
n style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"><br>&nbsp; </=
span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettify">re=
turn</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify=
"> array_view</span><span style=3D"color: rgb(102, 102, 0);" class=3D"style=
d-by-prettify">&lt;</span><span style=3D"color: rgb(0, 0, 0);" class=3D"sty=
led-by-prettify">remove_pointer_t</span><span style=3D"color: rgb(102, 102,=
 0);" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: rgb(0, =
0, 136);" class=3D"styled-by-prettify">decltype</span><span style=3D"color:=
 rgb(102, 102, 0);" class=3D"styled-by-prettify">(</span><span style=3D"col=
or: rgb(0, 0, 0);" class=3D"styled-by-prettify">container</span><span style=
=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">.</span><span st=
yle=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify">data</span><span =
style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">())&gt;&gt;=
(</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify">c=
ontainer</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-=
prettify">);</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: rgb(102, 102, 0);" class=3D"styl=
ed-by-prettify">}</span><span style=3D"color: rgb(0, 0, 0);" class=3D"style=
d-by-prettify"><br><br><br></span><span style=3D"color: rgb(0, 0, 136);" cl=
ass=3D"styled-by-prettify">template</span><span style=3D"color: rgb(0, 0, 0=
);" class=3D"styled-by-prettify"> </span><span style=3D"color: rgb(102, 102=
, 0);" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: rgb(0,=
 0, 136);" class=3D"styled-by-prettify">typename</span><span style=3D"color=
: rgb(0, 0, 0);" class=3D"styled-by-prettify"> T</span><span style=3D"color=
: rgb(102, 102, 0);" class=3D"styled-by-prettify">&gt;</span><span style=3D=
"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettify">auto</span><span s=
tyle=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> make_carray_vie=
w</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-pretti=
fy">const</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-pre=
ttify"> T</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by=
-prettify">&amp;</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled=
-by-prettify"> container</span><span style=3D"color: rgb(102, 102, 0);" cla=
ss=3D"styled-by-prettify">)</span><span style=3D"color: rgb(0, 0, 0);" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: rgb(102, 102, 0);" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: rgb(0, 0, 0);" cl=
ass=3D"styled-by-prettify"><br>&nbsp;</span><span style=3D"color: rgb(0, 0,=
 136);" class=3D"styled-by-prettify">return</span><span style=3D"color: rgb=
(0, 0, 0);" class=3D"styled-by-prettify"> carray_view</span><span style=3D"=
color: rgb(102, 102, 0);" class=3D"styled-by-prettify">&lt;</span><span sty=
le=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify">remove_pointer_t</=
span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">=
&lt;</span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-pretti=
fy">decltype</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled=
-by-prettify">(</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-=
by-prettify">container</span><span style=3D"color: rgb(102, 102, 0);" class=
=3D"styled-by-prettify">.</span><span style=3D"color: rgb(0, 0, 0);" class=
=3D"styled-by-prettify">data</span><span style=3D"color: rgb(102, 102, 0);"=
 class=3D"styled-by-prettify">())&gt;&gt;(</span><span style=3D"color: rgb(=
0, 0, 0);" class=3D"styled-by-prettify">container</span><span style=3D"colo=
r: rgb(102, 102, 0);" class=3D"styled-by-prettify">);</span><span style=3D"=
color: rgb(0, 0, 0);" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">}<br><br>//also =
have C array overloads..</span></div></code><code class=3D"prettyprint"><fo=
nt face=3D"Arial"></font></code></div><code class=3D"prettyprint"><font fac=
e=3D"Arial"><div><code class=3D"prettyprint"><font face=3D"Arial"></font></=
code>&nbsp;</div></font><div class=3D"subprettyprint"></div></code><div cla=
ss=3D"subprettyprint">Where we can now use auto and avoid duplicating the t=
ype:</div><div>&nbsp;</div><div><div> </div><div style=3D"border: 1px solid=
 rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250,=
 250);" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"sub=
prettyprint"><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-pretti=
fy">vector</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-b=
y-prettify">&lt;</span><span style=3D"color: rgb(102, 0, 102);" class=3D"st=
yled-by-prettify">SomeType</span><span style=3D"color: rgb(102, 102, 0);" c=
lass=3D"styled-by-prettify">&gt;</span><span style=3D"color: rgb(0, 0, 0);"=
 class=3D"styled-by-prettify"> storage</span><span style=3D"color: rgb(102,=
 102, 0);" class=3D"styled-by-prettify">;</span><span style=3D"color: rgb(0=
, 0, 0);" class=3D"styled-by-prettify"><br></span><span style=3D"color: rgb=
(0, 0, 136);" class=3D"styled-by-prettify">auto</span><span style=3D"color:=
 rgb(0, 0, 0);" class=3D"styled-by-prettify"> view </span><span style=3D"co=
lor: rgb(102, 102, 0);" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> make_array_view</sp=
an><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">(<=
/span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify">sto=
rage</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-pret=
tify">);</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-=
prettify">auto</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-b=
y-prettify"> const_view </span><span style=3D"color: rgb(102, 102, 0);" cla=
ss=3D"styled-by-prettify">=3D</span><span style=3D"color: rgb(0, 0, 0);" cl=
ass=3D"styled-by-prettify"> make_carray_view</span><span style=3D"color: rg=
b(102, 102, 0);" class=3D"styled-by-prettify">(</span><span style=3D"color:=
 rgb(0, 0, 0);" class=3D"styled-by-prettify">storage</span><span style=3D"c=
olor: rgb(102, 102, 0);" class=3D"styled-by-prettify">);</span></div></code=
></div><br></div><div>&nbsp;</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_2430_1047223446.1415837910980--

.