Topic: type deduction in constructors


Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 11 Feb 2015 08:33:28 -0800 (PST)
Raw View
------=_Part_242_1275444934.1423672408434
Content-Type: multipart/alternative;
 boundary="----=_Part_243_221241384.1423672408434"

------=_Part_243_221241384.1423672408434
Content-Type: text/plain; charset=UTF-8

Often we want to construct an object B from an object A where both B and A
are templates using the same underlying type.

vector<int> v;
array_view<int> av = v;

Here we have to specify the type int twice. It's would be much better to
use type deduction instead. The only way to do this currently is to write a
free function.

//This can be made more generic, but for now this example serves the point
template <typename T>
array_view<T> make_av(vector<T>& v) { return { v.begin(), v.end() }; }

void foo() {
  vector<int> v;
  auto av = make_av(v); //type is array_view<int>
}

While the above solution is good enough, it means we have to write free
functions for every time we want to do template argument type deduction
when creating one object from another.

One way to solve this problem would be to allow the use of auto when
specifying types:

std::vector<int> v;
array_view<auto> av1 = v; //Type is array_view<int>
auto av2 = array_view<auto>(v); //Type is array_view<int>
auto cv_view = array_view<const volatile auto>(v); //Type is
array_view<const volatile int>

Enabling this feature would require some kind of specification syntax in
the constructor declaration, telling the compiler how to deduce T from the
input arguments.

template <typename T>
class array_view {
  public:
    //This constructor needs help to determine how to deduce T from
ContiguousRange
    template <typename ContigouousRange>
      array_view<T=remove_pointer_t<decltype(ContiguousRange().data())>>(
ContiguousRange& c);

    //T appears in the argument list, so we can deduce easily just like
template free functions
    array_view(T* ptr, size_t sz);

    //Another possibility leveraging delegating constructors. The compiler
can use the call to array_view(T*,size_t) to do type deduction.
    template <typename ContigRange>
      array_view(ContigRange& c) : array_view(c.data(), c.size()) {}

};

When the compiler sees auto in the type specification, it has to lookup all
possible constructors, including any specializations and first determine
which constructors fit the arguments using overloading rules, and then try
to deduce T from the input arguments, failing if it cannot.

The next logical step of course is non-type template arguments.
Particularly for types like std::array. This feature would require support
from not only constructors, but also builtin support for aggregate
initialization.
auto a = make_array(1, 2, 3);
auto b = array<auto>(1, 2, 3); //Type is array<int,3>

We don't have a nice keyword like auto to replace the size parameter but
maybe we don't need one. For type deduction its nice to use the auto
keyword because its symmetrical with other uses of auto and we can add cv
qualifiers.

Have there been discussions in the past about such a feature?

--

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

<div dir=3D"ltr">Often we want to construct an object B from an object A wh=
ere both B and A are templates using the same underlying type. <br><br><div=
 class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); borde=
r-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-w=
rap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"=
><span style=3D"color: #000;" class=3D"styled-by-prettify">vector</span><sp=
an style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&gt;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> v</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>array_view</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"> av </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> v</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>Here we have to specify th=
e type int twice. It's would be much better to use type deduction instead. =
The only way to do this currently is to write a free function.<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-wr=
ap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #800;" class=3D"styled-by-prettify">//This can be mad=
e more generic, but for now this example serves the point</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">template</span><span style=3D"colo=
r: #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-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>array_view</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">&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> make_a=
v</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</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-prettify">T</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&gt;&amp;</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> v</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">return<=
/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: #000;" class=3D"styled-by-prettify"> v</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">begin</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(),</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> v</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">.</span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>end</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: #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;" cla=
ss=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> foo</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; vec=
tor</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"> v</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">auto</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> av </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> make_av</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">v</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: #800;" class=3D"styled-by-prettify">//=
type is array_view&lt;int&gt;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span></div></code></div><br>While the above solution is good enou=
gh, it means we have to write free functions for every time we want to do t=
emplate argument type deduction when creating one object from another.<br><=
br>One way to solve this problem would be to allow the use of auto when spe=
cifying types:<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">std</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">vecto=
r</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&g=
t;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> v</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>array_view</span><spa=
n style=3D"color: #080;" class=3D"styled-by-prettify">&lt;auto&gt;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> av1 </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> v</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">//Type is array_view&lt;int&gt;</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> av2 </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> array_view</span><span style=3D"color: #080;" class=3D"st=
yled-by-prettify">&lt;auto&gt;</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">v</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: #800;" class=3D"styled-by-prettify">//Type is array=
_view&lt;int&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> cv_vi=
ew </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> array_view</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">volatile</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">auto</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">v</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">//Type=
 is array_view&lt;const volatile int&gt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span></div></code></div><br>Enabling th=
is feature would require some kind of specification syntax in the construct=
or declaration, telling the compiler how to deduce T from the input argumen=
ts. <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: #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><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> array_view </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">public</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; &nbsp; </span><span style=3D"color: #800;" class=3D"=
styled-by-prettify">//This constructor needs help to determine how to deduc=
e T from ContiguousRange</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">template</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Co=
ntigouousRange</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> &=
nbsp;<br>&nbsp; &nbsp; &nbsp; array_view</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"style=
d-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">remove_pointer_t</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">decltype</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Con=
tiguousRange</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">())&gt;&gt;=
(</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Contiguou=
sRange</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> c</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br>&nb=
sp; &nbsp; </span><span style=3D"color: #800;" class=3D"styled-by-prettify"=
>//T appears in the argument list, so we can deduce easily just like templa=
te free functions</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>&nbsp; &nbsp; array_view</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> p=
tr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> size_t sz</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </s=
pan><span style=3D"color: #800;" class=3D"styled-by-prettify">//Another pos=
sibility leveraging delegating constructors. The compiler can use the call =
to array_view(T*,size_t) to do type deduction.</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">template</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styl=
ed-by-prettify">ContigRange</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br>&nbsp; &nbsp; &nbsp; array_view</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" cl=
ass=3D"styled-by-prettify">ContigRange</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> c</span><span style=3D"color: #660;" class=3D"styl=
ed-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"> array_view=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">c</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;" clas=
s=3D"styled-by-prettify"> c</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">size</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">())</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </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: #660;" class=3D"styled-by-prettify">};</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><b=
r>When the compiler sees auto in the type specification, it has to lookup a=
ll possible constructors, including any specializations and first determine=
 which constructors fit the arguments using overloading rules, and then try=
 to deduce T from the input arguments, failing if it cannot.<br><br>The nex=
t logical step of course is non-type template arguments. Particularly for t=
ypes like std::array. This feature would require support from not only cons=
tructors, but also builtin support for aggregate initialization. <br><div c=
lass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-=
color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wra=
p: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><=
span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span s=
tyle=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"> make_array</span><span style=3D"color=
: #660;" 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"=
styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify=
">2</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: #066;" class=3D"styled-by-prettify">3</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> b </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> array</span><span style=3D"color: #080;" class=3D"styled-by-prettif=
y">&lt;auto&gt;</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</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: #066;" class=3D"styled-by-prettify">2</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"sty=
led-by-prettify">3</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: #800;" class=3D"styled-by-prettify">//Type is=
 array&lt;int,3&gt;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span></div></code></div><br>We don't have a nice keyword lik=
e auto to replace the size parameter but maybe we don't need one. For type =
deduction its nice to use the auto keyword because its symmetrical with oth=
er uses of auto and we can add cv qualifiers. <br><br>Have there been discu=
ssions in the past about such a feature?<br><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 />

------=_Part_243_221241384.1423672408434--
------=_Part_242_1275444934.1423672408434--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 11 Feb 2015 19:08:25 +0200
Raw View
On 11 February 2015 at 18:33, Matthew Fioravante <fmatthew5876@gmail.com> wrote:
> One way to solve this problem would be to allow the use of auto when
> specifying types:
> std::vector<int> v;
> array_view<auto> av1 = v; //Type is array_view<int>
> auto av2 = array_view<auto>(v); //Type is array_view<int>
> auto cv_view = array_view<const volatile auto>(v); //Type is
> array_view<const volatile int>
> Have there been discussions in the past about such a feature?


As far as I understand, that feature is included in the Concepts TS.

--

---
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: Jens Maurer <Jens.Maurer@gmx.net>
Date: Wed, 11 Feb 2015 18:22:00 +0100
Raw View
On 02/11/2015 06:08 PM, Ville Voutilainen wrote:
> On 11 February 2015 at 18:33, Matthew Fioravante <fmatthew5876@gmail.com> wrote:
>> One way to solve this problem would be to allow the use of auto when
>> specifying types:
>> std::vector<int> v;
>> array_view<auto> av1 = v; //Type is array_view<int>

My understanding is that this is supported by the concepts TS.

>> auto av2 = array_view<auto>(v); //Type is array_view<int>
>> auto cv_view = array_view<const volatile auto>(v); //Type is
>> array_view<const volatile int>

Support for these is news to me. (The part about "auto" in the
function-style type conversion.)

>> Have there been discussions in the past about such a feature?
>
>
> As far as I understand, that feature is included in the Concepts TS.

Partly, as far as I understand.

Jens



--

---
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: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 11 Feb 2015 09:30:26 -0800 (PST)
Raw View
------=_Part_6512_1363892816.1423675826792
Content-Type: multipart/alternative;
 boundary="----=_Part_6513_706110434.1423675826793"

------=_Part_6513_706110434.1423675826793
Content-Type: text/plain; charset=UTF-8


On Wednesday, February 11, 2015 at 12:22:05 PM UTC-5, Jens Maurer wrote:
>
> On 02/11/2015 06:08 PM, Ville Voutilainen wrote:
> > On 11 February 2015 at 18:33, Matthew Fioravante <fmatth...@gmail.com
> <javascript:>> wrote:
> >> One way to solve this problem would be to allow the use of auto when
> >> specifying types:
> >> std::vector<int> v;
> >> array_view<auto> av1 = v; //Type is array_view<int>
>
> My understanding is that this is supported by the concepts TS.
>
> >> auto av2 = array_view<auto>(v); //Type is array_view<int>
> >> auto cv_view = array_view<const volatile auto>(v); //Type is
> >> array_view<const volatile int>
>
> Support for these is news to me. (The part about "auto" in the
> function-style type conversion.)
>
> >> Have there been discussions in the past about such a feature?
> >
> >
> > As far as I understand, that feature is included in the Concepts TS.
>
> Partly, as far as I understand.
>
> Jens
>
>
How about non-type template argument deduction as in the array example? If
that's the case then we might not need the proposal for std::make_array().

--

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

<div dir=3D"ltr"><br>On Wednesday, February 11, 2015 at 12:22:05 PM UTC-5, =
Jens Maurer wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 02/11/201=
5 06:08 PM, Ville Voutilainen wrote:
<br>&gt; On 11 February 2015 at 18:33, Matthew Fioravante &lt;<a href=3D"ja=
vascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"OID8uW-iFJAJ" rel=3D"=
nofollow" onmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D=
"this.href=3D'javascript:';return true;">fmatth...@gmail.com</a>&gt; wrote:
<br>&gt;&gt; One way to solve this problem would be to allow the use of aut=
o when
<br>&gt;&gt; specifying types:
<br>&gt;&gt; std::vector&lt;int&gt; v;
<br>&gt;&gt; array_view&lt;auto&gt; av1 =3D v; //Type is array_view&lt;int&=
gt;
<br>
<br>My understanding is that this is supported by the concepts TS.
<br>
<br>&gt;&gt; auto av2 =3D array_view&lt;auto&gt;(v); //Type is array_view&l=
t;int&gt;
<br>&gt;&gt; auto cv_view =3D array_view&lt;const volatile auto&gt;(v); //T=
ype is
<br>&gt;&gt; array_view&lt;const volatile int&gt;
<br>
<br>Support for these is news to me. (The part about "auto" in the
<br>function-style type conversion.)
<br>
<br>&gt;&gt; Have there been discussions in the past about such a feature?
<br>&gt;=20
<br>&gt;=20
<br>&gt; As far as I understand, that feature is included in the Concepts T=
S.
<br>
<br>Partly, as far as I understand.
<br>
<br>Jens
<br>
<br></blockquote><div><br>How about non-type template argument deduction as=
 in the array example? If that's the case then we might not need the propos=
al for std::make_array(). <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_6513_706110434.1423675826793--
------=_Part_6512_1363892816.1423675826792--

.