Topic: Generalizing functions like make_pair and make_tuple.


Author: Scott Prager <splinterofchaos@gmail.com>
Date: Mon, 12 Nov 2012 08:19:48 -0800 (PST)
Raw View
------=_Part_67_28565072.1352737188631
Content-Type: text/plain; charset=ISO-8859-1

This idiom of creating a function that constructs an argument-dependent
type seems fairly useful and commonplace. I realized it could be generalize
like so:

template< template<class...> class T > struct construct_t {
    template< class ...X, class R = T< typename std::decay<X>::type... > >
    constexpr R operator () ( X&& ...x ) {
        return R( forward<X>(x)... );
    }
};

constexpr auto make_pair = construct_t<std::pair>();
constexpr auto make_tuple = construct_t<std::tuple>();


And the same is true for forwarding.

template< template<class...> class T > struct forward_t {
    template< class ...X, class R = T< type... > >
    constexpr R operator () ( X&& ...x ) {
        return R( forward<X>(x)... );
    }
};

constexpr auto forward_as_tuple = forward_t<std::tuple>();


And a version could be supplied for references and const refs too.

In terms of testing, One of the most commonly used functions in a library
I'm working on is a *make_** function. I was able to replaced the function
with this one liner and it caused no new bugs or even compiler warnings,
and it's one of the most commonly used functions.

I have found two limitations to this approach. The first is that one could
not write a *make_shared* or *make_unique* this way because, to my
knowledge, there is no way to explicitly specify a type in an operator
overload. The second is that would could use this pattern to write a *
make_vector*, however it is ambiguous as to whether that should construct a
vector containing the supplied arguments, or forward to the any of the
vector's constructors, which makes type deduction trickier.

I believe that if this were in the standard library, it would encourage the
use of the *make_** idiom, which would in turn encourage generic code by
making it easier (a one liner!) for both library writers and users to work
with dependent types, more accessible (as a standard, well-accepted
concept), and would benefit the C++ community at-large. I plan on writing a
proposal for this to be included in the standard and would greatly
appreciate feedback on the idea.

*P.S.: *I wrote a blog post about where this idea came from if anyone is
interested
(http://yapb-soc.blogspot.com/2012/11/generic-function-objects-or.html).

--




------=_Part_67_28565072.1352737188631
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

This idiom of creating a function that constructs an argument-dependent typ=
e seems fairly useful and commonplace. I realized it could be generalize li=
ke so:<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"><div class=
=3D"subprettyprint"><pre><div class=3D"line" id=3D"LC131"><span class=3D"k"=
><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span><=
/span><span class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&lt;</span></span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span class=3D"k"><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">template</span></span><span class=3D"o"><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span></span><span class=3D"n"=
><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span></sp=
an><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">...</span></span><span class=3D"o"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;</span></span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span class=3D"k"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">class</span></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span class=3D"nc"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">T</span></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"o"><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span></span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span clas=
s=3D"k"><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</s=
pan></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">construct_t</span></span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span class=3D"p"><span style=3D"color: #660;" class=3D"=
styled-by-prettify">{</span></span></div><div class=3D"line" id=3D"LC132"><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp;</sp=
an><span class=3D"k"><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">template</span></span><span class=3D"o"><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&lt;</span></span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span class=3D"k"><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">class</span></span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span class=3D"err"><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">...</span></span><span cl=
ass=3D"nc"><span style=3D"color: #000;" class=3D"styled-by-prettify">X</spa=
n></span><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-=
prettify">,</span></span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span class=3D"k"><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">class</span></span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span class=3D"nc"><span style=3D"color: #000;" =
class=3D"styled-by-prettify">R</span></span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span class=3D"o"><span style=3D"color: =
#660;" class=3D"styled-by-prettify">=3D</span></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">T</span></span><span class=
=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span=
></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span class=3D"k"><span style=3D"color: #008;" class=3D"styled-by-prettify">=
typename</span></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled=
-by-prettify">std</span></span><span class=3D"o"><span style=3D"color: #660=
;" class=3D"styled-by-prettify">::</span></span><span class=3D"n"><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">decay</span></span><span c=
lass=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</=
span></span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-=
by-prettify">X</span></span><span class=3D"o"><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&gt;::</span></span><span class=3D"n"><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">type</span></span><span c=
lass=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">...</s=
pan></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&gt;</span></span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span class=3D"o"><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&gt;</span></span></div><div class=3D"line" id=3D"LC133"><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp;</span><=
span class=3D"n"><span style=3D"color: #008;" class=3D"styled-by-prettify">=
constexpr</span></span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span class=3D"n"><span style=3D"color: #000;" class=3D"style=
d-by-prettify">R</span></span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span class=3D"k"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">operator</span></span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span class=3D"p"><span style=3D"color=
: #660;" class=3D"styled-by-prettify">()</span></span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span class=3D"p"><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">X</span></span><spa=
n class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;&amp;</span></span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-=
by-prettify">...</span></span><span class=3D"n"><span style=3D"color: #000;=
" class=3D"styled-by-prettify">x</span></span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span class=3D"p"><span style=3D"color=
: #660;" class=3D"styled-by-prettify">)</span></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span class=3D"p"><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span></span></div><div cl=
ass=3D"line" id=3D"LC134"><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> &nbsp; &nbsp; &nbsp; &nbsp;</span><span class=3D"k"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">return</span></span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"=
><span style=3D"color: #000;" class=3D"styled-by-prettify">R</span></span><=
span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">forward</span></span><span class=3D"o"><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&lt;</span></span><span class=3D"n"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">X</span></span><span class=
=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span=
></span><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span></span><span class=3D"n"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">x</span></span><span class=3D"p"><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)...</span></span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span class=3D"p"><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">);</span></span></div><d=
iv class=3D"line" id=3D"LC135"><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> &nbsp; &nbsp;</span><span class=3D"p"><span style=3D"color: =
#660;" class=3D"styled-by-prettify">}</span></span></div><div class=3D"line=
" id=3D"LC136"><span class=3D"p"><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> make_pair=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> construct_t</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">pair</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&gt;();</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">constexpr</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> make_tuple </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> construct_t</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">tuple</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;();</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></span></div=
></pre></div></code></div><br>And the same is true for forwarding.<br><br><=
div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bo=
rder-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wor=
d-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypri=
nt"><pre><div class=3D"line" id=3D"LC131"><span class=3D"k"><span style=3D"=
color: #008;" class=3D"styled-by-prettify">template</span></span><span clas=
s=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</spa=
n></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span class=3D"k"><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>template</span></span><span class=3D"o"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span></span><span class=3D"n"><span style=3D"=
color: #008;" class=3D"styled-by-prettify">class</span></span><span class=
=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">...</span>=
</span><span class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&gt;</span></span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span class=3D"k"><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">class</span></span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span class=3D"nc"><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">T</span></span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span class=3D"o"><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">&gt;</span></span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span class=3D"k"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">struct</span></span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"=
><span style=3D"color: #000;" class=3D"styled-by-prettify">forward_t</span>=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">{=
</span></span></div><div class=3D"line" id=3D"LC132"><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> &nbsp; &nbsp;</span><span class=3D"k">=
<span style=3D"color: #008;" class=3D"styled-by-prettify">template</span></=
span><span class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&lt;</span></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span class=3D"k"><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">class</span></span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span class=3D"err"><span style=3D"color: #660;" =
class=3D"styled-by-prettify">...</span></span><span class=3D"nc"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">X</span></span><span class=
=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span></=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n class=3D"k"><span style=3D"color: #008;" class=3D"styled-by-prettify">cla=
ss</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span class=3D"nc"><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">R</span></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span class=3D"o"><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D</span></span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span class=3D"n"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">T</span></span><span class=3D"o"><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&lt;</span></span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">type</span></span><span =
class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">...</=
span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&gt;</span></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span class=3D"o"><span style=3D"color: #660;" class=3D"styled=
-by-prettify">&gt;</span></span></div><div class=3D"line" id=3D"LC133"><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp;</span>=
<span class=3D"n"><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>constexpr</span></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span class=3D"n"><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">R</span></span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span class=3D"k"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">operator</span></span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span class=3D"p"><span style=3D"color=
: #660;" class=3D"styled-by-prettify">()</span></span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span class=3D"p"><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">X</span></span><spa=
n class=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;&amp;</span></span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-=
by-prettify">...</span></span><span class=3D"n"><span style=3D"color: #000;=
" class=3D"styled-by-prettify">x</span></span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span class=3D"p"><span style=3D"color=
: #660;" class=3D"styled-by-prettify">)</span></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span class=3D"p"><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span></span></div><div cl=
ass=3D"line" id=3D"LC134"><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> &nbsp; &nbsp; &nbsp; &nbsp;</span><span class=3D"k"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">return</span></span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span class=3D"n"=
><span style=3D"color: #000;" class=3D"styled-by-prettify">R</span></span><=
span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span class=3D"n"><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">forward</span></span><span class=3D"o"><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&lt;</span></span><span class=3D"n"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">X</span></span><span class=
=3D"o"><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span=
></span><span class=3D"p"><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span></span><span class=3D"n"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">x</span></span><span class=3D"p"><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)...</span></span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span class=3D"p"><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">);</span></span></div><d=
iv class=3D"line" id=3D"LC135"><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> &nbsp; &nbsp;</span><span class=3D"p"><span style=3D"color: =
#660;" class=3D"styled-by-prettify">}</span></span></div><div class=3D"line=
" id=3D"LC136"><span class=3D"p"><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> forward_a=
s_tuple </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> forwar=
d_t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">tuple</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&gt;();</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span></span></div></pre></div>=
</code></div><br>And a version could be supplied for references and const r=
efs too. <br><br>In terms of testing, One of the most commonly used functio=
ns in a library I'm working on is a <i>make_*</i> function. I was able to r=
eplaced the function with this one liner and it caused no new bugs or even =
compiler warnings, and it's one of the most commonly used functions.<br><br=
>I have found two limitations to this approach. The first is that one could=
 not write a <i>make_shared</i> or <i>make_unique</i> this way because, to =
my knowledge, there is no way to explicitly specify a type in an operator o=
verload. The second is that would could use this pattern to write a <i>make=
_vector</i>, however it is ambiguous as to whether that should construct a =
vector containing the supplied arguments, or forward to the any of the vect=
or's constructors, which makes type deduction trickier.<br><br>I believe th=
at if this were in the standard library, it would encourage the use of the =
<i>make_*</i> idiom, which would in turn encourage generic code by making i=
t easier (a one liner!) for both library writers and users to work with dep=
endent types, more accessible (as a standard, well-accepted concept), and w=
ould benefit the C++ community at-large. I plan on writing a proposal for t=
his to be included in the standard and would greatly appreciate feedback on=
 the idea.<br><br><b>P.S.:<i> </i></b>I wrote a blog post about where this =
idea came from if anyone is interested (http://yapb-soc.blogspot.com/2012/1=
1/generic-function-objects-or.html).<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_67_28565072.1352737188631--

.