Topic: Proposal a movable_initializer_list


Author: Hzj_jie@hotmail.com
Date: Wed, 11 Feb 2015 22:32:17 -0800 (PST)
Raw View
------=_Part_11_2073662236.1423722737271
Content-Type: multipart/alternative;
 boundary="----=_Part_12_529093289.1423722737271"

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

Currently, the initializer_list cannot tell the difference between l-value=
=20
and r-value, i.e.

vector<string>("abc", "bcd");

is using the same logic as

string a =3D "abc";
string b =3D "bcd";
vector<string>{a, b};

Meanwhile, initializer_list in the second paragraph will consume an extra=
=20
copy constructor.
Check the following code,


#include <vector>
#include <iostream>
using namespace std;

class C
{
public:
    C() { cout << "C()" << endl; }
    C(const C&) { cout << "C(const C&)" << endl; }
    C(C&&) { cout << "C(C&&)" << endl; }
};

int main()
{
    {
        vector<C> v{C(), C(), C()};
    }
    {
        C a, b, c;
        vector<C> v{a, b, c};
    }
}

The output is,

C()
C()
C()
C(const C&)
C(const C&)
C(const C&)
C()
C()
C()
C(const C&)
C(const C&)
C(const C&)
C(const C&)
C(const C&)
C(const C&)

I am considering if there could be a movable_initializer_list, which=20
accepts only r-value reference parameters, and the consumer of the=20
initializer_list can safely calling move-constructor but not=20
copy-constructor for each element.

So the proposal can be,
1. Changing initializer_list implementation by supporting=20
initializer_list<T&&>. Since there is no pointer to r-value reference,=20
using initializer_list<T&&> will trigger compiling error.

class V
{
public:
    V(initializer_list<C&&> i)
    {
        for(auto it =3D i.begin(); it !=3D i.end(); it++)
        {
            v.push_back(move(*it));
        }
    }
private:
    vector<C> v;
};

In file included from /usr/include/c++/4.8/bits/stl_vector.h:63:0,
                 from /usr/include/c++/4.8/vector:64,
                 from c.cpp:2:
/usr/include/c++/4.8/initializer_list: In instantiation of =E2=80=98class=
=20
std::initializer_list<C&&>=E2=80=99:
c.cpp:20:5:   required from here
/usr/include/c++/4.8/initializer_list:54:26: error: forming pointer to=20
reference type =E2=80=98C&&=E2=80=99
       typedef const _E*  iterator;
                          ^
/usr/include/c++/4.8/initializer_list:55:26: error: forming pointer to=20
reference type =E2=80=98C&&=E2=80=99
       typedef const _E*  const_iterator;
                          ^
c.cpp: In constructor =E2=80=98V::V(std::initializer_list<C&&>)=E2=80=99:
c.cpp:21:25: error: =E2=80=98class std::initializer_list<C&&>=E2=80=99 has =
no member named=20
=E2=80=98begin=E2=80=99
         for(auto it =3D i.begin(); it !=3D i.end(); it++)
                         ^
c.cpp:21:42: error: =E2=80=98class std::initializer_list<C&&>=E2=80=99 has =
no member named=20
=E2=80=98end=E2=80=99
         for(auto it =3D i.begin(); it !=3D i.end(); it++)

2. Or adding a new container of movable_initializer_list, which will just=
=20
move all the elements.

#pragma once
#include <vector>
#include <stdlib.h>
#include <initializer_list>
#include <utility>
#include <boost/predef.h>

namespace std {
template <typename T>
class movable_initializer_list
{
public:
    typedef T value_type;
    typedef T& reference;
    typedef const T& const_reference;
    typedef size_t size_type;
    typedef typename std::vector<T>::iterator iterator;
    typedef typename std::vector<T>::const_iterator const_iterator;
private:
    std::vector<T> v;

public:
#if BOOST_COMP_MSVC
    movable_initializer_list(initializer_list<T*> i)
#else
    movable_initializer_list(const initializer_list<T*>& i)
#endif
    {
        for(auto it =3D i.begin(); it !=3D i.end(); it++)
        {
            assert((*it) !=3D nullptr);
            v.push_back(move(**it));
            delete *it;
        }
    }

#if BOOST_COMP_MSVC
    movable_initializer_list(initializer_list<T> i)
#else
    movable_initializer_list(const initializer_list<T>& i)
#endif
    {
        for(auto it =3D i.begin(); it !=3D i.end(); it++)
            v.push_back(move(*it));
    }

    movable_initializer_list() =3D default;

    size_type size() const
    {
        return v.size();
    }

    iterator begin()
    {
        return v.begin();
    }

    const_iterator begin() const
    {
        return v.begin();
    }

    iterator end()
    {
        return v.end();
    }

    const_iterator end() const
    {
        return v.end();
    }
}; }

The way to use the movable_initializer_list should be like,

#pragma once
#include <vector>
#include <functional>
#include <initializer_list>
#include <utility>
#include "../formation/movable_initializer_list.hpp"
#include <boost/predef.h>

template <typename... Args>
class event
{
private:
    std::vector<std::function<void(Args...)>> v;

public:
    event() =3D default;

#if !BOOST_COMP_MSVC
    event(std::function<void(Args...)>&& f)
    {
        v.push_back(std::forward<std::function<void(Args...)>>(f));
    }
#endif

    event(const=20
std::movable_initializer_list<std::function<void(Args...)>>& s)
    {
        for(auto it =3D s.begin(); it !=3D s.end(); it++)
            v.push_back(std::move(*it));
    }

    void bind(std::function<void(Args...)>&& f)
    {
        v.push_back(std::move(f));
    }

    template <typename T>
    event& operator+(T&& f)
    {
        bind(std::forward<T>(f));
        return *this;
    }

    template <typename T>
    event& operator+=3D(T&& f)
    {
        bind(std::forward<T>(f));
        return *this;
    }

    void execute(Args&&... args)
    {
        for(auto it =3D v.begin(); it !=3D v.end(); it++)
            (*it)(std::forward<Args>(args)...);
    }
};

While the user only need to provide a set of r-values to the constructor.

#pragma once
#include "../../delegates/event.hpp"
#include "../../utt/icase.hpp"
#include "../../utt/utt_assert.hpp"
#include <functional>
#include <boost/predef.h>

class event_test : public icase
{
public:
    bool run() override
    {
        int x =3D 0;
        event<int> e({ [&](int) { x +=3D 1; },
                       [&](int i) { x +=3D i; } });
        event<int> e2({ new std::function<void(int)>([&](int) { x +=3D 1; }=
),
                        new std::function<void(int)>([&](int i) { x +=3D i;=
=20
})});
#if BOOST_COMP_MSVC
        event<> e3({[&]() { x +=3D 1; }});
#else
        event<> e3([&]() { x +=3D 1; });
#endif
        e.bind([&](int i) { x +=3D (i << 1); });
        utt_assert.equal(&(e +=3D [&](int i) { x +=3D (i << 2); }), &e);
        e.execute(2);
        e2.execute(2);
        e3.execute();
        // x =3D 1 + 2 + 1 + 2 + (2 << 1) + (2 << 2) + 1
        utt_assert.equal(x, 19);
        return true;
    }

    DEFINE_CASE(event_test);
};
REGISTER_CASE(event_test);

Any thought?

Thank you in advanced.

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

<div dir=3D"ltr">Currently, the initializer_list cannot tell the difference=
 between l-value and r-value, i.e.<div><br><div><div class=3D"prettyprint" =
style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backg=
round-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D=
"subprettyprint"><font color=3D"#660066"><span style=3D"color: #000;" class=
=3D"styled-by-prettify">vector</span><span style=3D"color: #080;" class=3D"=
styled-by-prettify">&lt;string&gt;</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #080;" class=3D"style=
d-by-prettify">"abc"</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: #080;" class=3D"styled-by-prettify">"bcd"</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></font></d=
iv></code></div><div><br></div>is using the same logic as<br></div><div><br=
></div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, =
187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><c=
ode class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">string</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> a </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-b=
y-prettify">"abc"</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></span><span style=3D"color: #008;" class=3D"styled-by-prettify">string</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> b </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #080;" class=3D"styled-by-prettify">"bcd"</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>vector</span><span style=3D"color: #080;" cla=
ss=3D"styled-by-prettify">&lt;string&gt;</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-b=
y-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> b</span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></=
div></code></div><div><br></div><div>Meanwhile, initializer_list in the sec=
ond paragraph will consume an extra copy constructor.</div><div>Check the f=
ollowing code,</div><div><br></div><div><div class=3D"prettyprint" style=3D=
"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-co=
lor: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subpret=
typrint"><div class=3D"subprettyprint"><font color=3D"#660066"><br>#include=
 &lt;vector&gt;</font></div><div class=3D"subprettyprint"><font color=3D"#6=
60066">#include &lt;iostream&gt;</font></div><div class=3D"subprettyprint">=
<font color=3D"#660066">using namespace std;</font></div><div class=3D"subp=
rettyprint"><font color=3D"#660066"><br></font></div><div class=3D"subprett=
yprint"><font color=3D"#660066">class C</font></div><div class=3D"subpretty=
print"><font color=3D"#660066">{</font></div><div class=3D"subprettyprint">=
<font color=3D"#660066">public:</font></div><div class=3D"subprettyprint"><=
font color=3D"#660066">&nbsp; &nbsp; C() { cout &lt;&lt; "C()" &lt;&lt; end=
l; }</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbs=
p; &nbsp; C(const C&amp;) { cout &lt;&lt; "C(const C&amp;)" &lt;&lt; endl; =
}</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; =
&nbsp; C(C&amp;&amp;) { cout &lt;&lt; "C(C&amp;&amp;)" &lt;&lt; endl; }</fo=
nt></div><div class=3D"subprettyprint"><font color=3D"#660066">};</font></d=
iv><div class=3D"subprettyprint"><font color=3D"#660066"><br></font></div><=
div class=3D"subprettyprint"><font color=3D"#660066">int main()</font></div=
><div class=3D"subprettyprint"><font color=3D"#660066">{</font></div><div c=
lass=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font></div=
><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp;=
 &nbsp; vector&lt;C&gt; v{C(), C(), C()};</font></div><div class=3D"subpret=
typrint"><font color=3D"#660066">&nbsp; &nbsp; }</font></div><div class=3D"=
subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font></div><div cl=
ass=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; =
C a, b, c;</font></div><div class=3D"subprettyprint"><font color=3D"#660066=
">&nbsp; &nbsp; &nbsp; &nbsp; vector&lt;C&gt; v{a, b, c};</font></div><div =
class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; }</font></di=
v><div class=3D"subprettyprint"><font color=3D"#660066">}</font></div></div=
></code></div></div></div><div><br></div><div>The output is,</div><div><br>=
</div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 1=
87, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><div class=3D"subpre=
ttyprint">C()</div><div class=3D"subprettyprint">C()</div><div class=3D"sub=
prettyprint">C()</div><div class=3D"subprettyprint">C(const C&amp;)</div><d=
iv class=3D"subprettyprint">C(const C&amp;)</div><div class=3D"subprettypri=
nt">C(const C&amp;)</div><div class=3D"subprettyprint">C()</div><div class=
=3D"subprettyprint">C()</div><div class=3D"subprettyprint">C()</div><div cl=
ass=3D"subprettyprint">C(const C&amp;)</div><div class=3D"subprettyprint">C=
(const C&amp;)</div><div class=3D"subprettyprint">C(const C&amp;)</div><div=
 class=3D"subprettyprint">C(const C&amp;)</div><div class=3D"subprettyprint=
">C(const C&amp;)</div><div class=3D"subprettyprint">C(const C&amp;)</div><=
/div></code></div><div><br></div><div>I am considering if there could be a =
movable_initializer_list, which accepts only r-value reference parameters, =
and the consumer of the initializer_list can safely calling move-constructo=
r but not copy-constructor for each element.<br></div></div><div><br></div>=
<div>So the proposal can be,</div><div>1. Changing initializer_list impleme=
ntation by supporting initializer_list&lt;T&amp;&amp;&gt;. Since there is n=
o pointer to r-value reference, using initializer_list&lt;T&amp;&amp;&gt; w=
ill trigger compiling error.</div><div><br></div><div><div class=3D"prettyp=
rint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word;=
 background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div cl=
ass=3D"subprettyprint"><div class=3D"subprettyprint">class V</div><div clas=
s=3D"subprettyprint">{</div><div class=3D"subprettyprint">public:</div><div=
 class=3D"subprettyprint">&nbsp; &nbsp; V(initializer_list&lt;C&amp;&amp;&g=
t; i)</div><div class=3D"subprettyprint">&nbsp; &nbsp; {</div><div class=3D=
"subprettyprint">&nbsp; &nbsp; &nbsp; &nbsp; for(auto it =3D i.begin(); it =
!=3D i.end(); it++)</div><div class=3D"subprettyprint">&nbsp; &nbsp; &nbsp;=
 &nbsp; {</div><div class=3D"subprettyprint">&nbsp; &nbsp; &nbsp; &nbsp; &n=
bsp; &nbsp; v.push_back(move(*it));</div><div class=3D"subprettyprint">&nbs=
p; &nbsp; &nbsp; &nbsp; }</div><div class=3D"subprettyprint">&nbsp; &nbsp; =
}</div><div class=3D"subprettyprint">private:</div><div class=3D"subprettyp=
rint">&nbsp; &nbsp; vector&lt;C&gt; v;</div><div class=3D"subprettyprint">}=
;</div><div><br><div>In file included from /usr/include/c++/4.8/bits/stl_ve=
ctor.h:63:0,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp; &nbsp;from /usr/include/c++/4.8/vector:64,</div><div>&nbsp; &nbsp; &nbs=
p; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from c.cpp:2:</div><div>/usr/in=
clude/c++/4.8/initializer_list: In instantiation of =E2=80=98class std::ini=
tializer_list&lt;C&amp;&amp;&gt;=E2=80=99:</div><div>c.cpp:20:5: &nbsp; req=
uired from here</div><div>/usr/include/c++/4.8/initializer_list:54:26: erro=
r: forming pointer to reference type =E2=80=98C&amp;&amp;=E2=80=99</div><di=
v>&nbsp; &nbsp; &nbsp; &nbsp;typedef const _E* &nbsp;iterator;</div><div>&n=
bsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; ^</div><div>/usr/include/c++/4.8/initializer_list:55:26: erro=
r: forming pointer to reference type =E2=80=98C&amp;&amp;=E2=80=99</div><di=
v>&nbsp; &nbsp; &nbsp; &nbsp;typedef const _E* &nbsp;const_iterator;</div><=
div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; ^</div><div>c.cpp: In constructor =E2=80=98V::V(std::in=
itializer_list&lt;C&amp;&amp;&gt;)=E2=80=99:</div><div>c.cpp:21:25: error: =
=E2=80=98class std::initializer_list&lt;C&amp;&amp;&gt;=E2=80=99 has no mem=
ber named =E2=80=98begin=E2=80=99</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp;for(auto it =3D i.begin(); it !=3D i.end(); it++)</div><div>&nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nb=
sp;^</div><div>c.cpp:21:42: error: =E2=80=98class std::initializer_list&lt;=
C&amp;&amp;&gt;=E2=80=99 has no member named =E2=80=98end=E2=80=99</div><di=
v>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(auto it =3D i.begin(); it !=3D i.en=
d(); it++)</div></div></div></code></div><br>2. Or adding a new container o=
f movable_initializer_list, which will just move all the elements.</div><di=
v><br></div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(=
187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250)=
;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><div class=3D"=
subprettyprint"><font color=3D"#660066">#pragma once</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">#include &lt;vector&gt;</font><=
/div><div class=3D"subprettyprint"><font color=3D"#660066">#include &lt;std=
lib.h&gt;</font></div><div class=3D"subprettyprint"><font color=3D"#660066"=
>#include &lt;initializer_list&gt;</font></div><div class=3D"subprettyprint=
"><font color=3D"#660066">#include &lt;utility&gt;</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">#include &lt;boost/predef.h&gt;=
</font></div><div class=3D"subprettyprint"><font color=3D"#660066"><br></fo=
nt></div><div class=3D"subprettyprint"><font color=3D"#660066">namespace st=
d {</font></div><div class=3D"subprettyprint"><font color=3D"#660066">templ=
ate &lt;typename T&gt;</font></div><div class=3D"subprettyprint"><font colo=
r=3D"#660066">class movable_initializer_list</font></div><div class=3D"subp=
rettyprint"><font color=3D"#660066">{</font></div><div class=3D"subprettypr=
int"><font color=3D"#660066">public:</font></div><div class=3D"subprettypri=
nt"><font color=3D"#660066">&nbsp; &nbsp; typedef T value_type;</font></div=
><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; typede=
f T&amp; reference;</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066">&nbsp; &nbsp; typedef const T&amp; const_reference;</font></di=
v><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; typed=
ef size_t size_type;</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066">&nbsp; &nbsp; typedef typename std::vector&lt;T&gt;::iterator =
iterator;</font></div><div class=3D"subprettyprint"><font color=3D"#660066"=
>&nbsp; &nbsp; typedef typename std::vector&lt;T&gt;::const_iterator const_=
iterator;</font></div><div class=3D"subprettyprint"><font color=3D"#660066"=
>private:</font></div><div class=3D"subprettyprint"><font color=3D"#660066"=
>&nbsp; &nbsp; std::vector&lt;T&gt; v;</font></div><div class=3D"subprettyp=
rint"><font color=3D"#660066"><br></font></div><div class=3D"subprettyprint=
"><font color=3D"#660066">public:</font></div><div class=3D"subprettyprint"=
><font color=3D"#660066">#if BOOST_COMP_MSVC</font></div><div class=3D"subp=
rettyprint"><font color=3D"#660066">&nbsp; &nbsp; movable_initializer_list(=
initializer_list&lt;T*&gt; i)</font></div><div class=3D"subprettyprint"><fo=
nt color=3D"#660066">#else</font></div><div class=3D"subprettyprint"><font =
color=3D"#660066">&nbsp; &nbsp; movable_initializer_list(const initializer_=
list&lt;T*&gt;&amp; i)</font></div><div class=3D"subprettyprint"><font colo=
r=3D"#660066">#endif</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066">&nbsp; &nbsp; {</font></div><div class=3D"subprettyprint"><fon=
t color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; for(auto it =3D i.begin(); =
it !=3D i.end(); it++)</font></div><div class=3D"subprettyprint"><font colo=
r=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; {</font></div><div class=3D"subpr=
ettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp=
; assert((*it) !=3D nullptr);</font></div><div class=3D"subprettyprint"><fo=
nt color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v.push_back(=
move(**it));</font></div><div class=3D"subprettyprint"><font color=3D"#6600=
66">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delete *it;</font></div><div =
class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp=
; }</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp=
; &nbsp; }</font></div><div class=3D"subprettyprint"><font color=3D"#660066=
"><br></font></div><div class=3D"subprettyprint"><font color=3D"#660066">#i=
f BOOST_COMP_MSVC</font></div><div class=3D"subprettyprint"><font color=3D"=
#660066">&nbsp; &nbsp; movable_initializer_list(initializer_list&lt;T&gt; i=
)</font></div><div class=3D"subprettyprint"><font color=3D"#660066">#else</=
font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nb=
sp; movable_initializer_list(const initializer_list&lt;T&gt;&amp; i)</font>=
</div><div class=3D"subprettyprint"><font color=3D"#660066">#endif</font></=
div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</=
font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nb=
sp; &nbsp; &nbsp; for(auto it =3D i.begin(); it !=3D i.end(); it++)</font><=
/div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &n=
bsp; &nbsp; &nbsp; &nbsp; v.push_back(move(*it));</font></div><div class=3D=
"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; }</font></div><div c=
lass=3D"subprettyprint"><font color=3D"#660066"><br></font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; movable_initializ=
er_list() =3D default;</font></div><div class=3D"subprettyprint"><font colo=
r=3D"#660066"><br></font></div><div class=3D"subprettyprint"><font color=3D=
"#660066">&nbsp; &nbsp; size_type size() const</font></div><div class=3D"su=
bprettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font></div><div clas=
s=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; re=
turn v.size();</font></div><div class=3D"subprettyprint"><font color=3D"#66=
0066">&nbsp; &nbsp; }</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066"><br></font></div><div class=3D"subprettyprint"><font color=3D"=
#660066">&nbsp; &nbsp; iterator begin()</font></div><div class=3D"subpretty=
print"><font color=3D"#660066">&nbsp; &nbsp; {</font></div><div class=3D"su=
bprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; return v.=
begin();</font></div><div class=3D"subprettyprint"><font color=3D"#660066">=
&nbsp; &nbsp; }</font></div><div class=3D"subprettyprint"><font color=3D"#6=
60066"><br></font></div><div class=3D"subprettyprint"><font color=3D"#66006=
6">&nbsp; &nbsp; const_iterator begin() const</font></div><div class=3D"sub=
prettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; ret=
urn v.begin();</font></div><div class=3D"subprettyprint"><font color=3D"#66=
0066">&nbsp; &nbsp; }</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066"><br></font></div><div class=3D"subprettyprint"><font color=3D"=
#660066">&nbsp; &nbsp; iterator end()</font></div><div class=3D"subprettypr=
int"><font color=3D"#660066">&nbsp; &nbsp; {</font></div><div class=3D"subp=
rettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; return v.en=
d();</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbs=
p; &nbsp; }</font></div><div class=3D"subprettyprint"><font color=3D"#66006=
6"><br></font></div><div class=3D"subprettyprint"><font color=3D"#660066">&=
nbsp; &nbsp; const_iterator end() const</font></div><div class=3D"subpretty=
print"><font color=3D"#660066">&nbsp; &nbsp; {</font></div><div class=3D"su=
bprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; return v.=
end();</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&n=
bsp; &nbsp; }</font></div><div class=3D"subprettyprint"><font color=3D"#660=
066">}; }<br></font></div></div></code></div><br>The way to use the movable=
_initializer_list should be like,</div><div><br></div><div><div class=3D"pr=
ettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-=
word; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><d=
iv class=3D"subprettyprint"><div class=3D"subprettyprint"><font color=3D"#6=
60066">#pragma once</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066">#include &lt;vector&gt;</font></div><div class=3D"subprettypri=
nt"><font color=3D"#660066">#include &lt;functional&gt;</font></div><div cl=
ass=3D"subprettyprint"><font color=3D"#660066">#include &lt;initializer_lis=
t&gt;</font></div><div class=3D"subprettyprint"><font color=3D"#660066">#in=
clude &lt;utility&gt;</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066">#include "../formation/movable_initializer_list.hpp"</font></d=
iv><div class=3D"subprettyprint"><font color=3D"#660066">#include &lt;boost=
/predef.h&gt;</font></div><div class=3D"subprettyprint"><font color=3D"#660=
066"><br></font></div><div class=3D"subprettyprint"><font color=3D"#660066"=
>template &lt;typename... Args&gt;</font></div><div class=3D"subprettyprint=
"><font color=3D"#660066">class event</font></div><div class=3D"subprettypr=
int"><font color=3D"#660066">{</font></div><div class=3D"subprettyprint"><f=
ont color=3D"#660066">private:</font></div><div class=3D"subprettyprint"><f=
ont color=3D"#660066">&nbsp; &nbsp; std::vector&lt;std::function&lt;void(Ar=
gs...)&gt;&gt; v;</font></div><div class=3D"subprettyprint"><font color=3D"=
#660066"><br></font></div><div class=3D"subprettyprint"><font color=3D"#660=
066">public:</font></div><div class=3D"subprettyprint"><font color=3D"#6600=
66">&nbsp; &nbsp; event() =3D default;</font></div><div class=3D"subprettyp=
rint"><font color=3D"#660066"><br></font></div><div class=3D"subprettyprint=
"><font color=3D"#660066">#if !BOOST_COMP_MSVC</font></div><div class=3D"su=
bprettyprint"><font color=3D"#660066">&nbsp; &nbsp; event(std::function&lt;=
void(Args...)&gt;&amp;&amp; f)</font></div><div class=3D"subprettyprint"><f=
ont color=3D"#660066">&nbsp; &nbsp; {</font></div><div class=3D"subprettypr=
int"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; v.push_back(std::f=
orward&lt;std::function&lt;void(Args...)&gt;&gt;(f));</font></div><div clas=
s=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; }</font></div><d=
iv class=3D"subprettyprint"><font color=3D"#660066">#endif</font></div><div=
 class=3D"subprettyprint"><font color=3D"#660066"><br></font></div><div cla=
ss=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; event(const std=
::movable_initializer_list&lt;std::function&lt;void(Args...)&gt;&gt;&amp; s=
)</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; =
&nbsp; {</font></div><div class=3D"subprettyprint"><font color=3D"#660066">=
&nbsp; &nbsp; &nbsp; &nbsp; for(auto it =3D s.begin(); it !=3D s.end(); it+=
+)</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v.push_back(std::move(*it));</font></di=
v><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; }</fo=
nt></div><div class=3D"subprettyprint"><font color=3D"#660066"><br></font><=
/div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; vo=
id bind(std::function&lt;void(Args...)&gt;&amp;&amp; f)</font></div><div cl=
ass=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font></div>=
<div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; =
&nbsp; v.push_back(std::move(f));</font></div><div class=3D"subprettyprint"=
><font color=3D"#660066">&nbsp; &nbsp; }</font></div><div class=3D"subprett=
yprint"><font color=3D"#660066"><br></font></div><div class=3D"subprettypri=
nt"><font color=3D"#660066">&nbsp; &nbsp; template &lt;typename T&gt;</font=
></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; =
event&amp; operator+(T&amp;&amp; f)</font></div><div class=3D"subprettyprin=
t"><font color=3D"#660066">&nbsp; &nbsp; {</font></div><div class=3D"subpre=
ttyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; bind(std::for=
ward&lt;T&gt;(f));</font></div><div class=3D"subprettyprint"><font color=3D=
"#660066">&nbsp; &nbsp; &nbsp; &nbsp; return *this;</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; }</font></div><di=
v class=3D"subprettyprint"><font color=3D"#660066"><br></font></div><div cl=
ass=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; template &lt;t=
ypename T&gt;</font></div><div class=3D"subprettyprint"><font color=3D"#660=
066">&nbsp; &nbsp; event&amp; operator+=3D(T&amp;&amp; f)</font></div><div =
class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font></di=
v><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp=
; &nbsp; bind(std::forward&lt;T&gt;(f));</font></div><div class=3D"subprett=
yprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; return *this;</=
font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nb=
sp; }</font></div><div class=3D"subprettyprint"><font color=3D"#660066"><br=
></font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; =
&nbsp; void execute(Args&amp;&amp;... args)</font></div><div class=3D"subpr=
ettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; for=
(auto it =3D v.begin(); it !=3D v.end(); it++)</font></div><div class=3D"su=
bprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &n=
bsp; (*it)(std::forward&lt;Args&gt;(args)...);</font></div><div class=3D"su=
bprettyprint"><font color=3D"#660066">&nbsp; &nbsp; }</font></div><div clas=
s=3D"subprettyprint"><font color=3D"#660066">};</font></div></div></code></=
div><div><br></div>While the user only need to provide a set of r-values to=
 the constructor.</div><div><br></div><div><div class=3D"prettyprint" style=
=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; background=
-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><div class=3D"subprettyprint"><font color=3D"#660066">#pragma o=
nce</font></div><div class=3D"subprettyprint"><font color=3D"#660066">#incl=
ude "../../delegates/event.hpp"</font></div><div class=3D"subprettyprint"><=
font color=3D"#660066">#include "../../utt/icase.hpp"</font></div><div clas=
s=3D"subprettyprint"><font color=3D"#660066">#include "../../utt/utt_assert=
..hpp"</font></div><div class=3D"subprettyprint"><font color=3D"#660066">#in=
clude &lt;functional&gt;</font></div><div class=3D"subprettyprint"><font co=
lor=3D"#660066">#include &lt;boost/predef.h&gt;</font></div><div class=3D"s=
ubprettyprint"><font color=3D"#660066"><br></font></div><div class=3D"subpr=
ettyprint"><font color=3D"#660066">class event_test : public icase</font></=
div><div class=3D"subprettyprint"><font color=3D"#660066">{</font></div><di=
v class=3D"subprettyprint"><font color=3D"#660066">public:</font></div><div=
 class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; bool run() =
override</font></div><div class=3D"subprettyprint"><font color=3D"#660066">=
&nbsp; &nbsp; {</font></div><div class=3D"subprettyprint"><font color=3D"#6=
60066">&nbsp; &nbsp; &nbsp; &nbsp; int x =3D 0;</font></div><div class=3D"s=
ubprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; event&lt=
;int&gt; e({ [&amp;](int) { x +=3D 1; },</font></div><div class=3D"subprett=
yprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[&amp;](int i) { x +=3D i; } });</f=
ont></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbs=
p; &nbsp; &nbsp; event&lt;int&gt; e2({ new std::function&lt;void(int)&gt;([=
&amp;](int) { x +=3D 1; }),</font></div><div class=3D"subprettyprint"><font=
 color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; new std::function&lt;void(int)&gt;([&amp;](int =
i) { x +=3D i; })});</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066">#if BOOST_COMP_MSVC</font></div><div class=3D"subprettyprint">=
<font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; event&lt;&gt; e3({[&amp=
;]() { x +=3D 1; }});</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066">#else</font></div><div class=3D"subprettyprint"><font color=3D=
"#660066">&nbsp; &nbsp; &nbsp; &nbsp; event&lt;&gt; e3([&amp;]() { x +=3D 1=
; });</font></div><div class=3D"subprettyprint"><font color=3D"#660066">#en=
dif</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp=
; &nbsp; &nbsp; &nbsp; e.bind([&amp;](int i) { x +=3D (i &lt;&lt; 1); });</=
font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nb=
sp; &nbsp; &nbsp; utt_assert.equal(&amp;(e +=3D [&amp;](int i) { x +=3D (i =
&lt;&lt; 2); }), &amp;e);</font></div><div class=3D"subprettyprint"><font c=
olor=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; e.execute(2);</font></div><div=
 class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbs=
p; e2.execute(2);</font></div><div class=3D"subprettyprint"><font color=3D"=
#660066">&nbsp; &nbsp; &nbsp; &nbsp; e3.execute();</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; // =
x =3D 1 + 2 + 1 + 2 + (2 &lt;&lt; 1) + (2 &lt;&lt; 2) + 1</font></div><div =
class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp=
; utt_assert.equal(x, 19);</font></div><div class=3D"subprettyprint"><font =
color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; return true;</font></div><div=
 class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; }</font></d=
iv><div class=3D"subprettyprint"><font color=3D"#660066"><br></font></div><=
div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; DEFINE_C=
ASE(event_test);</font></div><div class=3D"subprettyprint"><font color=3D"#=
660066">};</font></div><div class=3D"subprettyprint"><font color=3D"#660066=
">REGISTER_CASE(event_test);</font></div></div></code></div><br>Any thought=
?</div></div><div><br></div><div>Thank you in advanced.</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_12_529093289.1423722737271--
------=_Part_11_2073662236.1423722737271--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 12 Feb 2015 08:51:07 +0200
Raw View
On 12 February 2015 at 08:32,  <Hzj_jie@hotmail.com> wrote:
> Currently, the initializer_list cannot tell the difference between l-value
> and r-value, i.e.

http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4166.pdf

--

---
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: Zijie He <hzj_jie@hotmail.com>
Date: Wed, 11 Feb 2015 23:41:34 -0800 (PST)
Raw View
------=_Part_1675_777991566.1423726894387
Content-Type: multipart/alternative;
 boundary="----=_Part_1676_1687230951.1423726894393"

------=_Part_1676_1687230951.1423726894393
Content-Type: text/plain; charset=UTF-8

Thank you Ville. Looks good.

On Thursday, February 12, 2015 at 2:51:08 PM UTC+8, Ville Voutilainen wrote:
>
> On 12 February 2015 at 08:32,  <Hzj...@hotmail.com <javascript:>> wrote:
> > Currently, the initializer_list cannot tell the difference between
> l-value
> > and r-value, i.e.
>
> http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4166.pdf
>

--

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

<div dir=3D"ltr">Thank you Ville. Looks good.<br><br>On Thursday, February =
12, 2015 at 2:51:08 PM UTC+8, Ville Voutilainen wrote:<blockquote class=3D"=
gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc so=
lid;padding-left: 1ex;">On 12 February 2015 at 08:32, &nbsp;&lt;<a href=3D"=
javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"Rj_JnJmRCEMJ" rel=
=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';return true;" onclic=
k=3D"this.href=3D'javascript:';return true;">Hzj...@hotmail.com</a>&gt; wro=
te:
<br>&gt; Currently, the initializer_list cannot tell the difference between=
 l-value
<br>&gt; and r-value, i.e.
<br>
<br><a href=3D"http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4166.pd=
f" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://ww=
w.google.com/url?q\75http%3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%=
2Fpapers%2F2014%2Fn4166.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNHKK2WrlBgRhA=
VSx2He1ulABOYDUA';return true;" onclick=3D"this.href=3D'http://www.google.c=
om/url?q\75http%3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2=
F2014%2Fn4166.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNHKK2WrlBgRhAVSx2He1ulA=
BOYDUA';return true;">http://open-std.org/JTC1/SC22/<wbr>WG21/docs/papers/2=
014/n4166.<wbr>pdf</a>
<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_1676_1687230951.1423726894393--
------=_Part_1675_777991566.1423726894387--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 12 Feb 2015 10:13:13 +0200
Raw View
On 12 February 2015 at 09:41, Zijie He <hzj_jie@hotmail.com> wrote:
> Thank you Ville. Looks good.


That proposal hasn't been adopted. There are some expectations that the work
in the area will continue, but I'm not sure when.

--

---
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: David Krauss <potswa@gmail.com>
Date: Thu, 12 Feb 2015 17:18:07 +0800
Raw View
--Apple-Mail=_F14E6F59-047B-4B72-A8D0-B74DE11B1030
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9302=E2=80=9312, at 4:13 PM, Ville Voutilainen <ville.vouti=
lainen@gmail.com> wrote:
>=20
> On 12 February 2015 at 09:41, Zijie He <hzj_jie@hotmail.com> wrote:
>> Thank you Ville. Looks good.
>=20
> That proposal hasn't been adopted. There are some expectations that the w=
ork
> in the area will continue, but I'm not sure when.

I should be prototyping my own proposal, but I don=E2=80=99t have plans to =
start right now. I=E2=80=99d be happy to lend assistance if someone else tr=
ies, though.

Possibly I=E2=80=99ll have a whim to do it. The hurdle is that I suspect th=
e workings of initializer_list inside GCC to be fairly complicated. On the =
other hand, the proposal does not define much new compiler behavior. Mostly=
 it refines existing behaviors to select an alternative library hook. A goo=
d start would be to find where the compiler generates initializer_list obje=
cts and cause it to discriminate the cases of the bound array having the sa=
me lifetime, or a longer lifetime than the view object. (After that, there =
still remain details in template deduction and allowing the user to demand =
an initializer_list<T&&>.)

Besides convenience and correctness when initializing containers of move-on=
ly types, there=E2=80=99s a potential performance benefit for programs that=
 use initializer_lists of containers, e.g. std::vector< std::string >{ "hel=
lo", "world" }. It might help the proposal to benchmark its effect on a rea=
l-world program that does a lot of that sort of thing. This only requires t=
he =E2=80=9Cgood start,=E2=80=9D not the complete proposal.

Likewise, someone with such a program or library might be interested in pur=
suing the implementation.

--=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/.

--Apple-Mail=_F14E6F59-047B-4B72-A8D0-B74DE11B1030
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9302=
=E2=80=9312, at 4:13 PM, Ville Voutilainen &lt;<a href=3D"mailto:ville.vout=
ilainen@gmail.com" class=3D"">ville.voutilainen@gmail.com</a>&gt; wrote:</d=
iv><br class=3D"Apple-interchange-newline"><div class=3D"">On 12 February 2=
015 at 09:41, Zijie He &lt;<a href=3D"mailto:hzj_jie@hotmail.com" class=3D"=
">hzj_jie@hotmail.com</a>&gt; wrote:<br class=3D""><blockquote type=3D"cite=
" class=3D"">Thank you Ville. Looks good.<br class=3D""></blockquote><br cl=
ass=3D"">That proposal hasn't been adopted. There are some expectations tha=
t the work<br class=3D"">in the area will continue, but I'm not sure when.<=
br class=3D""></div></blockquote></div><br class=3D""><div class=3D"">I sho=
uld be prototyping my own proposal, but I don=E2=80=99t have plans to start=
 right now. I=E2=80=99d be happy to lend assistance if someone else tries, =
though.</div><div class=3D""><br class=3D""></div><div class=3D"">Possibly =
I=E2=80=99ll have a whim to do it. The hurdle is that I suspect the working=
s of <font face=3D"Courier" class=3D"">initializer_list</font> inside GCC t=
o be fairly complicated. On the other hand, the proposal does not define mu=
ch new compiler behavior. Mostly it refines existing behaviors to select an=
 alternative library hook. A good start would be to find where the compiler=
 generates <font face=3D"Courier" class=3D"">initializer_list</font> object=
s and cause it to discriminate the cases of the bound array having the same=
 lifetime, or a longer lifetime than the view object. (After that, there st=
ill remain details in template deduction and allowing the user to demand an=
 <font face=3D"Courier" class=3D"">initializer_list&lt;T&amp;&amp;&gt;</fon=
t>.)</div><div class=3D""><br class=3D""></div><div class=3D"">Besides conv=
enience and correctness when initializing containers of move-only types, th=
ere=E2=80=99s a potential performance benefit for programs that use <font f=
ace=3D"Courier" class=3D"">initializer_lists</font> of containers, e.g.&nbs=
p;<font face=3D"Courier" class=3D"">std::vector&lt; std::string &gt;{ "hell=
o", "world" }</font>. It might help the proposal to benchmark its effect on=
 a real-world program that does a lot of that sort of thing. This only requ=
ires the =E2=80=9Cgood start,=E2=80=9D not the complete proposal.</div><div=
 class=3D""><br class=3D""></div><div class=3D"">Likewise, someone with suc=
h a program or library might be interested in pursuing the implementation.<=
/div></body></html>

<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 />

--Apple-Mail=_F14E6F59-047B-4B72-A8D0-B74DE11B1030--

.


Author: zijiehe@google.com
Date: Thu, 12 Feb 2015 05:47:36 -0800 (PST)
Raw View
------=_Part_2033_531155068.1423748856633
Content-Type: multipart/alternative;
 boundary="----=_Part_2034_33707297.1423748856633"

------=_Part_2034_33707297.1423748856633
Content-Type: text/plain; charset=UTF-8

To the benefit, what I can imagine is to store the std::function(s) in a
container for *further* usage. i.e. you do not need to copy all the values
in the closure, just move them. Say,

class C
{
private:
    vector<function<void(void)>> vs;
public:
    C(initializer_list<function<void(void)>&&> i)
    {
        for(auto x : i)
        {
            vs.push_back(move(x));
        }
    }
};

Which will work better with lambda expression. Just as the cases I have
provided above.

To the implementation, we properly do not want to break anything existing,
since we will need to change the compiler to generate initializer_list<T&&>
according to the situation.
1. We will have an initializer_list<T&&>, which is initializer_list<T>,
i.e. inheritance.
2. We will have an initializer_list<T&&>, which can be converted to
initializer_list<T> implicitly. i.e. adding a new implicit constructor in
initializer_list<T>.
3. This is tricky, but I am also considering to avoid change to the
compiler, but just library. First, surely we need an initializer_list<T&&>.
The acceptable solution is to raise compiler error when the consumer type
accepts only initializer_list<T&&> instead of initializer_list<T>.
Which should be similar as,
#include <iostream>
#include <type_traits>
#include <utility>
#include <iostream>
#include <initializer_list>
using namespace std;

template <typename T>
class C
{
public:
    typedef typename remove_reference<T>::type rT;
    C(T&& x)
    {
        rT&& y = forward<T>(x);
        cout << y << endl;
    }
};

template <typename T>
C<T> create(T&& i)
{
    return C<T>(forward<T>(i));
}

int main()
{
    {
        auto x = create(1);
    }
    {
        auto x = create(10);
    }
    {
        int x = 100;
        auto y = create(move(x));
    }
    {
        int x = 1000;
        // auto y = create(x); // trigger build error
    }
}

The assumption is, initializer_list<T&&> will be preferred.
#include <iostream>
#include <utility>
using namespace std;

template <typename T>
class C
{
public:
    C(T&& x)
    {
        cout << "T" << endl;
    }
};

template <typename T>
class C<T&&>
{
public:
    C(T&& x)
    {
        cout << "T&&" << endl;
    }
};

template <typename T>
void F(T&& x)
{
    C<T&&> c(forward<T>(x));
}

int main()
{
    F(1);
    int x = 0;
    F(x);
}

So in the constructor of initializer_list<T&&>, we can assume all the
inputs are r-value, otherwise, just build error.

--

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

<div dir=3D"ltr">To the benefit, what I can imagine is to store the std::fu=
nction(s) in a container for *further* usage. i.e. you do not need to copy =
all the values in the closure, just move them. Say,<div><br><div class=3D"p=
rettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break=
-word; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> C<br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">private</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; vector=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">function</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><font c=
olor=3D"#000000"><span style=3D"color: #008;" class=3D"styled-by-prettify">=
void</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">)&gt;&gt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> vs</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span></font><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">public</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>&nbsp; &nbsp; C</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">initializer_list</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">function</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">void</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">void</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)&g=
t;&amp;&amp;&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> i</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; &nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">for</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> i</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; &nbsp; &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; &nbsp; &nbsp; =
&nbsp; &nbsp; vs</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">pus=
h_back</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">move</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">x</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; &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; </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">};</span></div></code></div><div><br><=
/div></div><div>Which will work better with lambda expression. Just as the =
cases I have provided above.</div><div><br></div><div>To the implementation=
, we properly do not want to break anything existing, since we will need to=
 change the compiler to generate initializer_list&lt;T&amp;&amp;&gt; accord=
ing to the situation.</div><div>1. We will have an initializer_list&lt;T&am=
p;&amp;&gt;, which is initializer_list&lt;T&gt;, i.e. inheritance.</div><di=
v>2. We will have an initializer_list&lt;T&amp;&amp;&gt;, which can be conv=
erted to initializer_list&lt;T&gt; implicitly. i.e. adding a new implicit c=
onstructor in initializer_list&lt;T&gt;.</div><div>3. This is tricky, but I=
 am also considering to avoid change to the compiler, but just library. Fir=
st, surely we need an initializer_list&lt;T&amp;&amp;&gt;.</div><div>The ac=
ceptable solution is to raise compiler error when the consumer type accepts=
 only initializer_list&lt;T&amp;&amp;&gt; instead of initializer_list&lt;T&=
gt;.</div><div>Which should be similar as,</div><div><div class=3D"prettypr=
int" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; =
background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div cla=
ss=3D"subprettyprint"><div class=3D"subprettyprint"><font color=3D"#660066"=
>#include &lt;iostream&gt;</font></div><div class=3D"subprettyprint"><font =
color=3D"#660066">#include &lt;type_traits&gt;</font></div><div class=3D"su=
bprettyprint"><font color=3D"#660066">#include &lt;utility&gt;</font></div>=
<div class=3D"subprettyprint"><font color=3D"#660066">#include &lt;iostream=
&gt;</font></div><div class=3D"subprettyprint"><font color=3D"#660066">#inc=
lude &lt;initializer_list&gt;</font></div><div class=3D"subprettyprint"><fo=
nt color=3D"#660066">using namespace std;</font></div><div class=3D"subpret=
typrint"><font color=3D"#660066"><br></font></div><div class=3D"subprettypr=
int"><font color=3D"#660066">template &lt;typename T&gt;</font></div><div c=
lass=3D"subprettyprint"><font color=3D"#660066">class C</font></div><div cl=
ass=3D"subprettyprint"><font color=3D"#660066">{</font></div><div class=3D"=
subprettyprint"><font color=3D"#660066">public:</font></div><div class=3D"s=
ubprettyprint"><font color=3D"#660066">&nbsp; &nbsp; typedef typename remov=
e_reference&lt;T&gt;::type rT;</font></div><div class=3D"subprettyprint"><f=
ont color=3D"#660066">&nbsp; &nbsp; C(T&amp;&amp; x)</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font></div><di=
v class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nb=
sp; rT&amp;&amp; y =3D forward&lt;T&gt;(x);</font></div><div class=3D"subpr=
ettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt=
; y &lt;&lt; endl;</font></div><div class=3D"subprettyprint"><font color=3D=
"#660066">&nbsp; &nbsp; }</font></div><div class=3D"subprettyprint"><font c=
olor=3D"#660066">};</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066"><br></font></div><div class=3D"subprettyprint"><font color=3D"=
#660066">template &lt;typename T&gt;</font></div><div class=3D"subprettypri=
nt"><font color=3D"#660066">C&lt;T&gt; create(T&amp;&amp; i)</font></div><d=
iv class=3D"subprettyprint"><font color=3D"#660066">{</font></div><div clas=
s=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; return C&lt;T&gt=
;(forward&lt;T&gt;(i));</font></div><div class=3D"subprettyprint"><font col=
or=3D"#660066">}</font></div><div class=3D"subprettyprint"><font color=3D"#=
660066"><br></font></div><div class=3D"subprettyprint"><font color=3D"#6600=
66">int main()</font></div><div class=3D"subprettyprint"><font color=3D"#66=
0066">{</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&=
nbsp; &nbsp; {</font></div><div class=3D"subprettyprint"><font color=3D"#66=
0066">&nbsp; &nbsp; &nbsp; &nbsp; auto x =3D create(1);</font></div><div cl=
ass=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; }</font></div>=
<div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font=
></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; =
&nbsp; &nbsp; auto x =3D create(10);</font></div><div class=3D"subprettypri=
nt"><font color=3D"#660066">&nbsp; &nbsp; }</font></div><div class=3D"subpr=
ettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; int=
 x =3D 100;</font></div><div class=3D"subprettyprint"><font color=3D"#66006=
6">&nbsp; &nbsp; &nbsp; &nbsp; auto y =3D create(move(x));</font></div><div=
 class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; }</font></d=
iv><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</f=
ont></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbs=
p; &nbsp; &nbsp; int x =3D 1000;</font></div><div class=3D"subprettyprint">=
<font color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; // auto y =3D create(x)=
; // trigger build error</font></div><div class=3D"subprettyprint"><font co=
lor=3D"#660066">&nbsp; &nbsp; }</font></div><div class=3D"subprettyprint"><=
font color=3D"#660066">}</font></div></div></code></div><br>The assumption =
is, initializer_list&lt;T&amp;&amp;&gt; will be preferred.</div><div><div c=
lass=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wr=
ap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"prett=
yprint"><div class=3D"subprettyprint"><div class=3D"subprettyprint"><font c=
olor=3D"#660066">#include &lt;iostream&gt;</font></div><div class=3D"subpre=
ttyprint"><font color=3D"#660066">#include &lt;utility&gt;</font></div><div=
 class=3D"subprettyprint"><font color=3D"#660066">using namespace std;</fon=
t></div><div class=3D"subprettyprint"><font color=3D"#660066"><br></font></=
div><div class=3D"subprettyprint"><font color=3D"#660066">template &lt;type=
name T&gt;</font></div><div class=3D"subprettyprint"><font color=3D"#660066=
">class C</font></div><div class=3D"subprettyprint"><font color=3D"#660066"=
>{</font></div><div class=3D"subprettyprint"><font color=3D"#660066">public=
:</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; =
&nbsp; C(T&amp;&amp; x)</font></div><div class=3D"subprettyprint"><font col=
or=3D"#660066">&nbsp; &nbsp; {</font></div><div class=3D"subprettyprint"><f=
ont color=3D"#660066">&nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; "T" &lt;&lt=
; endl;</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&=
nbsp; &nbsp; }</font></div><div class=3D"subprettyprint"><font color=3D"#66=
0066">};</font></div><div class=3D"subprettyprint"><font color=3D"#660066">=
<br></font></div><div class=3D"subprettyprint"><font color=3D"#660066">temp=
late &lt;typename T&gt;</font></div><div class=3D"subprettyprint"><font col=
or=3D"#660066">class C&lt;T&amp;&amp;&gt;</font></div><div class=3D"subpret=
typrint"><font color=3D"#660066">{</font></div><div class=3D"subprettyprint=
"><font color=3D"#660066">public:</font></div><div class=3D"subprettyprint"=
><font color=3D"#660066">&nbsp; &nbsp; C(T&amp;&amp; x)</font></div><div cl=
ass=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; {</font></div>=
<div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; &nbsp; =
&nbsp; cout &lt;&lt; "T&amp;&amp;" &lt;&lt; endl;</font></div><div class=3D=
"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; }</font></div><div c=
lass=3D"subprettyprint"><font color=3D"#660066">};</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066"><br></font></div><div class=3D"=
subprettyprint"><font color=3D"#660066">template &lt;typename T&gt;</font><=
/div><div class=3D"subprettyprint"><font color=3D"#660066">void F(T&amp;&am=
p; x)</font></div><div class=3D"subprettyprint"><font color=3D"#660066">{</=
font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nb=
sp; C&lt;T&amp;&amp;&gt; c(forward&lt;T&gt;(x));</font></div><div class=3D"=
subprettyprint"><font color=3D"#660066">}</font></div><div class=3D"subpret=
typrint"><font color=3D"#660066"><br></font></div><div class=3D"subprettypr=
int"><font color=3D"#660066">int main()</font></div><div class=3D"subpretty=
print"><font color=3D"#660066">{</font></div><div class=3D"subprettyprint">=
<font color=3D"#660066">&nbsp; &nbsp; F(1);</font></div><div class=3D"subpr=
ettyprint"><font color=3D"#660066">&nbsp; &nbsp; int x =3D 0;</font></div><=
div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; F(x);</f=
ont></div><div class=3D"subprettyprint"><font color=3D"#660066">}</font></d=
iv></div></code></div><div><br></div>So in the constructor of initializer_l=
ist&lt;T&amp;&amp;&gt;, we can assume all the inputs are r-value, otherwise=
, just build error.<br><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_2034_33707297.1423748856633--
------=_Part_2033_531155068.1423748856633--

.


Author: David Krauss <potswa@gmail.com>
Date: Thu, 12 Feb 2015 22:16:22 +0800
Raw View
--Apple-Mail=_21404C52-6C47-4BEC-A4EB-5F78ABEF4468
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

I felt guilty after my last message, so I=E2=80=99m scoping out a GCC imple=
mentation now.


> On 2015=E2=80=9302=E2=80=9312, at 9:47 PM, zijiehe@google.com wrote:
>=20
> To the benefit, what I can imagine is to store the std::function(s) in a =
container for *further* usage. i.e. you do not need to copy all the values =
in the closure, just move them. Say,

Sure: std::function is like a container.

> class C
> {
> private:
>     vector<function<void(void)>> vs;
> public:
>     C(initializer_list<function<void(void)>&&> i)
>     {
>         for(auto x : i)
>         {
>             vs.push_back(move(x));
>         }
>     }
> };
>=20
> Which will work better with lambda expression. Just as the cases I have p=
rovided above.
>=20
> To the implementation, we properly do not want to break anything existing=
, since we will need to change the compiler to generate initializer_list<T&=
&> according to the situation.
> 1. We will have an initializer_list<T&&>, which is initializer_list<T>, i=
..e. inheritance.

This is elaborated in N4166.

> 2. We will have an initializer_list<T&&>, which can be converted to initi=
alizer_list<T> implicitly. i.e. adding a new implicit constructor in initia=
lizer_list<T>.

A base class allows the same object with the same layout to be used when th=
e list is passed, whatever the parameter type. User-defined conversion requ=
ires a new object to be generated even though it=E2=80=99s a natural slice =
operation. See the top of page 6 in N4166.

> 3. This is tricky, but I am also considering to avoid change to the compi=
ler, but just library. First, surely we need an initializer_list<T&&>.

Well, there could be movable_initializer_list<T>, and that decision is orth=
ogonal to the inheritance issue. You can=E2=80=99t turn one library hook in=
to two, or alter constness at all, without modifying the compiler.

> The acceptable solution is to raise compiler error when the consumer type=
 accepts only initializer_list<T&&> instead of initializer_list<T>.

If you don=E2=80=99t allow the consumer to refuse a non-modifiable list, th=
en it=E2=80=99s impossible to avoid a useless, read-only list of unique_ptr=
s. I don=E2=80=99t see how this is good, or related to points 1-3.

> The assumption is, initializer_list<T&&> will be preferred.

Preferred when? It=E2=80=99s an optimization to reuse elements without rein=
itialization, in which case initializer_list<T> is better.

> So in the constructor of initializer_list<T&&>, we can assume all the inp=
uts are r-value, otherwise, just build error.

The underlying sequence of initializer_list<T&&> can be initialized just th=
e same as initializer_list<T>, which already supports move-construction of =
elements.

--=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/.

--Apple-Mail=_21404C52-6C47-4BEC-A4EB-5F78ABEF4468
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D"">I felt guilty afte=
r my last message, so I=E2=80=99m scoping out a GCC implementation now.<div=
 class=3D""><br class=3D""></div><div class=3D""><br class=3D""><div><block=
quote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9302=E2=80=931=
2, at 9:47 PM, <a href=3D"mailto:zijiehe@google.com" class=3D"">zijiehe@goo=
gle.com</a> wrote:</div><br class=3D"Apple-interchange-newline"><div class=
=3D""><div dir=3D"ltr" class=3D"">To the benefit, what I can imagine is to =
store the std::function(s) in a container for *further* usage. i.e. you do =
not need to copy all the values in the closure, just move them. Say,</div><=
/div></blockquote><div><br class=3D""></div><div>Sure: <font face=3D"Courie=
r" class=3D"">std::function</font> is like a container.</div><br class=3D""=
><blockquote type=3D"cite" class=3D""><div class=3D""><div dir=3D"ltr" clas=
s=3D""><div class=3D""><div class=3D"prettyprint" style=3D"border: 1px soli=
d rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250=
, 250);"><code class=3D"prettyprint"><span style=3D"color: #008;" class=3D"=
styled-by-prettify">class</span> C<br class=3D""><span style=3D"color: #660=
;" class=3D"styled-by-prettify">{</span><br class=3D""><span style=3D"color=
: #008;" class=3D"styled-by-prettify">private</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">:</span><br class=3D"">&nbsp; &nbsp; vec=
tor<span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">function</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><font class=
=3D""><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">)&gt;&gt;</span><span style=3D""=
 class=3D"styled-by-prettify"> vs</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"" class=3D"styled-by-prettif=
y"><br class=3D""></span></font><span style=3D"color: #008;" class=3D"style=
d-by-prettify">public</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">:</span><br class=3D"">&nbsp; &nbsp; C<span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span>initializer_list<span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">function</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">void</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">void</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">)&gt;&amp;&amp;&gt;</span> i<span style=3D"color: #660;" class=3D"style=
d-by-prettify">)</span><br class=3D"">&nbsp; &nbsp; <span style=3D"color: #=
660;" class=3D"styled-by-prettify">{</span><br class=3D"">&nbsp; &nbsp; &nb=
sp; &nbsp; <span style=3D"color: #008;" class=3D"styled-by-prettify">for</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">auto</span> x <span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">:</span> i<span style=3D"=
color: #660;" class=3D"styled-by-prettify">)</span><br class=3D"">&nbsp; &n=
bsp; &nbsp; &nbsp; <span style=3D"color: #660;" class=3D"styled-by-prettify=
">{</span><br class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vs<span =
style=3D"color: #660;" class=3D"styled-by-prettify">.</span>push_back<span =
style=3D"color: #660;" class=3D"styled-by-prettify">(</span>move<span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span>x<span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">));</span><br class=3D"">&nbsp; &nbs=
p; &nbsp; &nbsp; <span style=3D"color: #660;" class=3D"styled-by-prettify">=
}</span><br class=3D"">&nbsp; &nbsp; <span style=3D"color: #660;" class=3D"=
styled-by-prettify">}</span><br class=3D""><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">};</span></code></div><div class=3D""><br class=
=3D""></div></div><div class=3D"">Which will work better with lambda expres=
sion. Just as the cases I have provided above.</div><div class=3D""><br cla=
ss=3D""></div><div class=3D"">To the implementation, we properly do not wan=
t to break anything existing, since we will need to change the compiler to =
generate initializer_list&lt;T&amp;&amp;&gt; according to the situation.</d=
iv><div class=3D"">1. We will have an initializer_list&lt;T&amp;&amp;&gt;, =
which is initializer_list&lt;T&gt;, i.e. inheritance.</div></div></div></bl=
ockquote><div><br class=3D""></div><div>This is elaborated in N4166.</div><=
br class=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><div dir=
=3D"ltr" class=3D""><div class=3D"">2. We will have an initializer_list&lt;=
T&amp;&amp;&gt;, which can be converted to initializer_list&lt;T&gt; implic=
itly. i.e. adding a new implicit constructor in initializer_list&lt;T&gt;.<=
/div></div></div></blockquote><div><br class=3D""></div><div>A base class a=
llows the same object with the same layout to be used when the list is pass=
ed, whatever the parameter type. User-defined conversion requires a new obj=
ect to be generated even though it=E2=80=99s a natural slice operation. See=
 the top of page 6 in N4166.</div><br class=3D""><blockquote type=3D"cite" =
class=3D""><div class=3D""><div dir=3D"ltr" class=3D""><div class=3D"">3. T=
his is tricky, but I am also considering to avoid change to the compiler, b=
ut just library. First, surely we need an initializer_list&lt;T&amp;&amp;&g=
t;.</div></div></div></blockquote><div><br class=3D""></div><div>Well, ther=
e could be <font face=3D"Courier" class=3D"">movable_initializer_list&lt;T&=
gt;</font>, and that decision is orthogonal to the inheritance issue. You c=
an=E2=80=99t turn one library hook into two, or alter constness at all, wit=
hout modifying the compiler.</div><br class=3D""><blockquote type=3D"cite" =
class=3D""><div class=3D""><div dir=3D"ltr" class=3D""><div class=3D"">The =
acceptable solution is to raise compiler error when the consumer type accep=
ts only initializer_list&lt;T&amp;&amp;&gt; instead of initializer_list&lt;=
T&gt;.</div></div></div></blockquote><div><br class=3D""></div><div>If you =
don=E2=80=99t allow the consumer to refuse a non-modifiable list, then it=
=E2=80=99s impossible to avoid a useless, read-only list of <font face=3D"C=
ourier" class=3D"">unique_ptr</font>s. I don=E2=80=99t see how this is good=
, or related to points 1-3.</div><br class=3D""><blockquote type=3D"cite" c=
lass=3D""><div dir=3D"ltr" class=3D""><div class=3D"">The assumption is, in=
itializer_list&lt;T&amp;&amp;&gt; will be preferred.</div></div></blockquot=
e><div><br class=3D""></div><div>Preferred when? It=E2=80=99s an optimizati=
on to reuse elements without reinitialization, in which case <font face=3D"=
Courier" class=3D"">initializer_list&lt;T&gt;</font> is better.</div><br cl=
ass=3D""><blockquote type=3D"cite" class=3D""><div dir=3D"ltr" class=3D""><=
div class=3D"">So in the constructor of initializer_list&lt;T&amp;&amp;&gt;=
, we can assume all the inputs are r-value, otherwise, just build error.<br=
 class=3D""></div></div></blockquote><div><br class=3D""></div><div>The und=
erlying sequence of <font face=3D"Courier" class=3D"">initializer_list&lt;T=
&amp;&amp;&gt;</font> can be initialized just the same as <font face=3D"Cou=
rier" class=3D"">initializer_list&lt;T&gt;</font>, which already supports m=
ove-construction of elements.</div></div></div></body></html>

<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 />

--Apple-Mail=_21404C52-6C47-4BEC-A4EB-5F78ABEF4468--

.


Author: Zijie He <hzj_jie@hotmail.com>
Date: Thu, 12 Feb 2015 20:54:50 -0800 (PST)
Raw View
------=_Part_255_962899136.1423803290721
Content-Type: multipart/alternative;
 boundary="----=_Part_256_9014960.1423803290721"

------=_Part_256_9014960.1423803290721
Content-Type: text/plain; charset=UTF-8

My bad, it's always me to reply the thread, really hate to merge my corp
account with my personal account, anyway.

The 'preferred' I have mentioned is about the output of following logic,
#include <iostream>
#include <utility>
using namespace std;

template <typename T>
class C
{
public:
   C(T&& x)
   {
       cout << "T" << endl;
   }
};

template <typename T>
class C<T&&>
{
public:
   C(T&& x)
   {
       cout << "T&&" << endl;
   }
};

template <typename T>
void F(T&& x)
{
   C<T&&> c(forward<T>(x));
}

int main()
{
   F(1);
   int x = 0;
   F(x);
}

// output is,
// T&&
// T

F(1) will trigger C<T&&>, while F(x) will trigger C<T>. Since r-value
reference of r-value reference is r-value reference, but r-value reference
of l-value reference is still l-value reference.
#include <iostream>
#include <type_traits>
using namespace std;

template <typename T>
void f(T&& x)
{
    cout << boolalpha;
    cout << "is_rvalue_reference<T>::value " <<
is_rvalue_reference<T>::value << endl;
    cout << "is_lvalue_reference<T>::value " <<
is_lvalue_reference<T>::value << endl;
    cout << "is_rvalue_reference<T&>::value " <<
is_rvalue_reference<T&>::value << endl;
    cout << "is_lvalue_reference<T&>::value " <<
is_lvalue_reference<T&>::value << endl;
    cout << "is_rvalue_reference<T&&>::value " <<
is_rvalue_reference<T&&>::value << endl;
    cout << "is_lvalue_reference<T&&>::value " <<
is_lvalue_reference<T&&>::value << endl;
}

int main()
{
    f(1);
    int x = 0;
    f(x);
}

// output is,
// is_rvalue_reference<T>::value false
// is_lvalue_reference<T>::value false
// is_rvalue_reference<T&>::value false
// is_lvalue_reference<T&>::value true
// is_rvalue_reference<T&&>::value true
// is_lvalue_reference<T&&>::value false
// is_rvalue_reference<T>::value false
// is_lvalue_reference<T>::value true
// is_rvalue_reference<T&>::value false
// is_lvalue_reference<T&>::value true
// is_rvalue_reference<T&&>::value false
// is_lvalue_reference<T&&>::value true

Unfortunately I do not know how gcc implemented, but if we can control how
the compiler generates the initializer_list<T>, i.e. if there is a 'create'
function, than we will be able to select the right implementation without
an 'if-else' in gcc itself.

--

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

<div dir=3D"ltr">My bad, it's always me to reply the thread, really hate to=
 merge my corp account with my personal account, anyway.<div><br></div><div=
>The 'preferred' I have mentioned is about the output of following logic,</=
div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187=
, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code=
 class=3D"prettyprint"><div class=3D"subprettyprint"><div><font color=3D"#6=
60066"><span style=3D"color: #800;" class=3D"styled-by-prettify">#include</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #080;" class=3D"styled-by-prettify">&lt;iostream&gt;</spa=
n></font></div><div><font color=3D"#660066"><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">#include</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styl=
ed-by-prettify">&lt;utility&gt;</span></font></div><div><font color=3D"#660=
066"><span style=3D"color: #008;" class=3D"styled-by-prettify">using</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">namespace</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">;</span></font></div><div><font c=
olor=3D"#660066"><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span></font></div><div><font color=3D"#660066"><span style=3D"color: =
#008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&lt;</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"> T</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&gt;</span></font></div><div><font color=3D"#660066"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> C</span></font></div><div><font =
color=3D"#660066"><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>{</span></font></div><div><font color=3D"#660066"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">public</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">:</span></font></div><div><font color=3D"#660=
066"><span style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbs=
p;C</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">)</span></font></div><div><font c=
olor=3D"#660066"><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 &nbsp; &nbsp;</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">{</span></font></div><div><font color=3D"#660066"><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp; &nbsp; &nbsp;cout </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #080;" class=3D"styled-by-prettify">"T"</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;&lt;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> endl</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">;</span></font></div><div><font color=3D"#660066"=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp;</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span></fo=
nt></div><div><font color=3D"#660066"><span style=3D"color: #660;" class=3D=
"styled-by-prettify">};</span></font></div><div><font color=3D"#660066"><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></font></=
div><div><font color=3D"#660066"><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">template</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">t=
ypename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span>=
</font></div><div><font color=3D"#660066"><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> C</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;&amp;&gt;</span></font></div><div><font color=3D"#660066"><span style=3D"=
color: #660;" class=3D"styled-by-prettify">{</span></font></div><div><font =
color=3D"#660066"><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>public</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</=
span></font></div><div><font color=3D"#660066"><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> &nbsp; &nbsp;C</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&amp;&amp;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> x</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)</span></font></div><div><font color=3D"#660066"><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp;</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span></font></div><div><f=
ont color=3D"#660066"><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> &nbsp; &nbsp; &nbsp; &nbsp;cout </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"sty=
led-by-prettify">"T&amp;&amp;"</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> endl</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">;</span></font></div><div><font color=3D"#660066"><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp;</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span></font></div><div><font co=
lor=3D"#660066"><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
;</span></font></div><div><font color=3D"#660066"><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span></font></div><div><font color=
=3D"#660066"><span style=3D"color: #008;" class=3D"styled-by-prettify">temp=
late</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><spa=
n 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"styled-by-prettify">&gt;</span></font></div><div><f=
ont color=3D"#660066"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
F</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)</span></font></div><div><font col=
or=3D"#660066"><span style=3D"color: #660;" class=3D"styled-by-prettify">{<=
/span></font></div><div><font color=3D"#660066"><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> &nbsp; &nbsp;C</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">&amp;&amp;&gt;</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">forward</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&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;(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">x</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">));</span></font></div><=
div><font color=3D"#660066"><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}</span></font></div><div><font color=3D"#660066"><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span></font></div><div><f=
ont color=3D"#660066"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> m=
ain</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</spa=
n></font></div><div><font color=3D"#660066"><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">{</span></font></div><div><font color=3D"#660066=
"><span style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp;F=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #066;" class=3D"styled-by-prettify">1</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">);</span></font></div><div><=
font color=3D"#660066"><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> &nbsp; &nbsp;</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> x </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span></font></div><div><f=
ont color=3D"#660066"><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> &nbsp; &nbsp;F</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>x</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span=
></font></div><div><font color=3D"#660066"><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br><br></span><span style=3D"color: #800;" class=3D"style=
d-by-prettify">// output is,</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #800;" class=3D"styled-b=
y-prettify">// T&amp;&amp;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br></span><span style=3D"color: #800;" class=3D"styled-by-=
prettify">// T</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span></font></div></div></code></div><br>F(1) will trigger C&lt;T=
&amp;&amp;&gt;, while F(x) will trigger C&lt;T&gt;. Since r-value reference=
 of r-value reference is r-value reference, but r-value reference of l-valu=
e reference is still l-value reference.</div><div><div class=3D"prettyprint=
" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; bac=
kground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><div class=3D"subprettyprint"><font color=3D"#660066">#=
include &lt;iostream&gt;</font></div><div class=3D"subprettyprint"><font co=
lor=3D"#660066">#include &lt;type_traits&gt;</font></div><div class=3D"subp=
rettyprint"><font color=3D"#660066">using namespace std;</font></div><div c=
lass=3D"subprettyprint"><font color=3D"#660066"><br></font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">template &lt;typename T&gt;</fo=
nt></div><div class=3D"subprettyprint"><font color=3D"#660066">void f(T&amp=
;&amp; x)</font></div><div class=3D"subprettyprint"><font color=3D"#660066"=
>{</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp;=
 &nbsp; cout &lt;&lt; boolalpha;</font></div><div class=3D"subprettyprint">=
<font color=3D"#660066">&nbsp; &nbsp; cout &lt;&lt; "is_rvalue_reference&lt=
;T&gt;::value " &lt;&lt; is_rvalue_reference&lt;T&gt;::value &lt;&lt; endl;=
</font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &=
nbsp; cout &lt;&lt; "is_lvalue_reference&lt;T&gt;::value " &lt;&lt; is_lval=
ue_reference&lt;T&gt;::value &lt;&lt; endl;</font></div><div class=3D"subpr=
ettyprint"><font color=3D"#660066">&nbsp; &nbsp; cout &lt;&lt; "is_rvalue_r=
eference&lt;T&amp;&gt;::value " &lt;&lt; is_rvalue_reference&lt;T&amp;&gt;:=
:value &lt;&lt; endl;</font></div><div class=3D"subprettyprint"><font color=
=3D"#660066">&nbsp; &nbsp; cout &lt;&lt; "is_lvalue_reference&lt;T&amp;&gt;=
::value " &lt;&lt; is_lvalue_reference&lt;T&amp;&gt;::value &lt;&lt; endl;<=
/font></div><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &n=
bsp; cout &lt;&lt; "is_rvalue_reference&lt;T&amp;&amp;&gt;::value " &lt;&lt=
; is_rvalue_reference&lt;T&amp;&amp;&gt;::value &lt;&lt; endl;</font></div>=
<div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; cout &l=
t;&lt; "is_lvalue_reference&lt;T&amp;&amp;&gt;::value " &lt;&lt; is_lvalue_=
reference&lt;T&amp;&amp;&gt;::value &lt;&lt; endl;</font></div><div class=
=3D"subprettyprint"><font color=3D"#660066">}</font></div><div class=3D"sub=
prettyprint"><font color=3D"#660066"><br></font></div><div class=3D"subpret=
typrint"><font color=3D"#660066">int main()</font></div><div class=3D"subpr=
ettyprint"><font color=3D"#660066">{</font></div><div class=3D"subprettypri=
nt"><font color=3D"#660066">&nbsp; &nbsp; f(1);</font></div><div class=3D"s=
ubprettyprint"><font color=3D"#660066">&nbsp; &nbsp; int x =3D 0;</font></d=
iv><div class=3D"subprettyprint"><font color=3D"#660066">&nbsp; &nbsp; f(x)=
;</font></div><div class=3D"subprettyprint"><font color=3D"#660066">}<br><b=
r>// output is,<br>//&nbsp;</font><span style=3D"font-family: Arial, Helvet=
ica, sans-serif;">is_rvalue_reference&lt;T&gt;::value false</span></div><di=
v class=3D"subprettyprint">// is_lvalue_reference&lt;T&gt;::value false</di=
v><div class=3D"subprettyprint">// is_rvalue_reference&lt;T&amp;&gt;::value=
 false</div><div class=3D"subprettyprint">// is_lvalue_reference&lt;T&amp;&=
gt;::value true</div><div class=3D"subprettyprint">// is_rvalue_reference&l=
t;T&amp;&amp;&gt;::value true</div><div class=3D"subprettyprint">// is_lval=
ue_reference&lt;T&amp;&amp;&gt;::value false</div><div class=3D"subprettypr=
int">// is_rvalue_reference&lt;T&gt;::value false</div><div class=3D"subpre=
ttyprint">// is_lvalue_reference&lt;T&gt;::value true</div><div class=3D"su=
bprettyprint">// is_rvalue_reference&lt;T&amp;&gt;::value false</div><div c=
lass=3D"subprettyprint">// is_lvalue_reference&lt;T&amp;&gt;::value true</d=
iv><div class=3D"subprettyprint">// is_rvalue_reference&lt;T&amp;&amp;&gt;:=
:value false</div><div class=3D"subprettyprint">// is_lvalue_reference&lt;T=
&amp;&amp;&gt;::value true</div></div></code></div><br></div><div>Unfortuna=
tely I do not know how gcc implemented, but if we can control how the compi=
ler generates the initializer_list&lt;T&gt;, i.e. if there is a 'create' fu=
nction, than we will be able to select the right implementation without an =
'if-else' in gcc itself.</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_256_9014960.1423803290721--
------=_Part_255_962899136.1423803290721--

.