Topic: Classes with lambda captures


Author: charleshenri@gmail.com
Date: Mon, 22 Oct 2018 12:27:10 -0700 (PDT)
Raw View
------=_Part_1021_1321758721.1540236430638
Content-Type: multipart/alternative;
 boundary="----=_Part_1022_681448458.1540236430638"

------=_Part_1022_681448458.1540236430638
Content-Type: text/plain; charset="UTF-8"



Hi,

I have an API that requires passing an object which implements multiple
callbacks.

For instance:

template<typename Callbacks> void myAPI(Callbacks &&c)
{
  c.foo();
  c.bar();
}

When I use it, I end up doing something like this:

void useMyAPI() {
  int i;
  class MyCallbacks {
    MyCallbacks(int &i): i(i) {}
    int &i;
    void foo() { ++ i; }
    void bar() { --i; }
  };
  myAPI(MyCallbacks{i});
}


This can be cumbersome if I want to capture more local variables.

So, to solve this problem, I'd like to allow captures in local class
definitions.

To make this work, I would:

- make the classes unnamed
- force the class to be used immediately to declare a variable or
generate a temporary

For instance, something like this:

void useMyAPI() {
  int i = 0;
  myAPI(class [&] {
    void foo() { ++ i; }
    void bar() { --i; }
  }());
}

This would also be useful to generate a class implementing a specific
interface using inheritance.

Incidentally, lambdas could then be defined in terms of a capture-class
with an operator().

A useful addition would be to allow putting destructors in them and, in
that case, allow an implicit, unnamed variable declaration, for easy
RAII, for instance like this:

int *p = (int *)malloc(10);
class [p] {
  ~() { free(p); }
};

Anyway, so my questions are:
- Has something like this already been proposed? It's not easy to search
for so I didn't find anything in 5 minutes on google
- If not, does it sound interesting? If so I could work on a paper

Thanks!

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/bf3a4a59-cc3f-4272-a239-80d7e28c4bf0%40isocpp.org.

------=_Part_1022_681448458.1540236430638
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><pre wrap=3D"">Hi,

I have an API that requires passing an object which implements multiple
callbacks.

For instance:

template&lt;typename Callbacks&gt; void myAPI(Callbacks &amp;&amp;c)
{
  c.foo();
  c.bar();
}

When I use it, I end up doing something like this:

void useMyAPI() {
  int i;
  class MyCallbacks {
    MyCallbacks(int &amp;i): i(i) {}
    int &amp;i;
    void foo() { ++ i; }
    void bar() { --i; }
  };
  myAPI(MyCallbacks{i});
}


This can be cumbersome if I want to capture more local variables.

So, to solve this problem, I&#39;d like to allow captures in local class
definitions.

To make this work, I would:

- make the classes unnamed
- force the class to be used immediately to declare a variable or
generate a temporary

For instance, something like this:

void useMyAPI() {
  int i =3D 0;
  myAPI(class [&amp;] {
    void foo() { ++ i; }
    void bar() { --i; }
  }());
}

This would also be useful to generate a class implementing a specific
interface using inheritance.

Incidentally, lambdas could then be defined in terms of a capture-class
with an operator().

A useful addition would be to allow putting destructors in them and, in
that case, allow an implicit, unnamed variable declaration, for easy
RAII, for instance like this:

int *p =3D (int *)malloc(10);
class [p] {
  ~() { free(p); }
};

Anyway, so my questions are:
- Has something like this already been proposed? It&#39;s not easy to searc=
h
for so I didn&#39;t find anything in 5 minutes on google
- If not, does it sound interesting? If so I could work on a paper

Thanks!
</pre></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/bf3a4a59-cc3f-4272-a239-80d7e28c4bf0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/bf3a4a59-cc3f-4272-a239-80d7e28c4bf0=
%40isocpp.org</a>.<br />

------=_Part_1022_681448458.1540236430638--

------=_Part_1021_1321758721.1540236430638--

.


Author: mihailnajdenov@gmail.com
Date: Mon, 22 Oct 2018 13:45:44 -0700 (PDT)
Raw View
------=_Part_4832_2004163372.1540241144551
Content-Type: multipart/alternative;
 boundary="----=_Part_4833_649374295.1540241144551"

------=_Part_4833_649374295.1540241144551
Content-Type: text/plain; charset="UTF-8"

It has been suggested (can't find the posts). Problem is it is ultimately a
niche feature, that has workarounds, and still requires considerable amount
of work to design and implement.

Also don't forget that lambdas don't exactly stimulate code reuse.

On Monday, October 22, 2018 at 10:27:10 PM UTC+3, charle...@gmail.com wrote:
>
> Hi,
>
> I have an API that requires passing an object which implements multiple
> callbacks.
>
> For instance:
>
> template<typename Callbacks> void myAPI(Callbacks &&c)
> {
>   c.foo();
>   c.bar();
> }
>
> When I use it, I end up doing something like this:
>
> void useMyAPI() {
>   int i;
>   class MyCallbacks {
>     MyCallbacks(int &i): i(i) {}
>     int &i;
>     void foo() { ++ i; }
>     void bar() { --i; }
>   };
>   myAPI(MyCallbacks{i});
> }
>
>
> This can be cumbersome if I want to capture more local variables.
>
> So, to solve this problem, I'd like to allow captures in local class
> definitions.
>
> To make this work, I would:
>
> - make the classes unnamed
> - force the class to be used immediately to declare a variable or
> generate a temporary
>
> For instance, something like this:
>
> void useMyAPI() {
>   int i = 0;
>   myAPI(class [&] {
>     void foo() { ++ i; }
>     void bar() { --i; }
>   }());
> }
>
> This would also be useful to generate a class implementing a specific
> interface using inheritance.
>
> Incidentally, lambdas could then be defined in terms of a capture-class
> with an operator().
>
> A useful addition would be to allow putting destructors in them and, in
> that case, allow an implicit, unnamed variable declaration, for easy
> RAII, for instance like this:
>
> int *p = (int *)malloc(10);
> class [p] {
>   ~() { free(p); }
> };
>
> Anyway, so my questions are:
> - Has something like this already been proposed? It's not easy to search
> for so I didn't find anything in 5 minutes on google
> - If not, does it sound interesting? If so I could work on a paper
>
> Thanks!
>
>

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/19a0f2e0-344e-489e-9541-387784c2b269%40isocpp.org.

------=_Part_4833_649374295.1540241144551
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">It has been suggested (can&#39;t find the posts). Problem =
is it is ultimately a niche feature, that has workarounds, and still requir=
es considerable amount of work to design and implement.<div><br></div><div>=
Also don&#39;t forget that lambdas don&#39;t exactly stimulate code reuse.<=
/div><div><br>On Monday, October 22, 2018 at 10:27:10 PM UTC+3, charle...@g=
mail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr=
"><pre>Hi,

I have an API that requires passing an object which implements multiple
callbacks.

For instance:

template&lt;typename Callbacks&gt; void myAPI(Callbacks &amp;&amp;c)
{
  c.foo();
  c.bar();
}

When I use it, I end up doing something like this:

void useMyAPI() {
  int i;
  class MyCallbacks {
    MyCallbacks(int &amp;i): i(i) {}
    int &amp;i;
    void foo() { ++ i; }
    void bar() { --i; }
  };
  myAPI(MyCallbacks{i});
}


This can be cumbersome if I want to capture more local variables.

So, to solve this problem, I&#39;d like to allow captures in local class
definitions.

To make this work, I would:

- make the classes unnamed
- force the class to be used immediately to declare a variable or
generate a temporary

For instance, something like this:

void useMyAPI() {
  int i =3D 0;
  myAPI(class [&amp;] {
    void foo() { ++ i; }
    void bar() { --i; }
  }());
}

This would also be useful to generate a class implementing a specific
interface using inheritance.

Incidentally, lambdas could then be defined in terms of a capture-class
with an operator().

A useful addition would be to allow putting destructors in them and, in
that case, allow an implicit, unnamed variable declaration, for easy
RAII, for instance like this:

int *p =3D (int *)malloc(10);
class [p] {
  ~() { free(p); }
};

Anyway, so my questions are:
- Has something like this already been proposed? It&#39;s not easy to searc=
h
for so I didn&#39;t find anything in 5 minutes on google
- If not, does it sound interesting? If so I could work on a paper

Thanks!
</pre></div></blockquote></div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/19a0f2e0-344e-489e-9541-387784c2b269%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/19a0f2e0-344e-489e-9541-387784c2b269=
%40isocpp.org</a>.<br />

------=_Part_4833_649374295.1540241144551--

------=_Part_4832_2004163372.1540241144551--

.


Author: charleshenri@gmail.com
Date: Mon, 22 Oct 2018 14:34:09 -0700 (PDT)
Raw View
------=_Part_1313_604752206.1540244049390
Content-Type: multipart/alternative;
 boundary="----=_Part_1314_1087693827.1540244049390"

------=_Part_1314_1087693827.1540244049390
Content-Type: text/plain; charset="UTF-8"



On Monday, October 22, 2018 at 1:45:44 PM UTC-7, mihailn...@gmail.com wrote:
>
> It has been suggested (can't find the posts). Problem is it is ultimately
> a niche feature, that has workarounds, and still requires considerable
> amount of work to design and implement.
>

Fair enough.


>
> Also don't forget that lambdas don't exactly stimulate code reuse.
>

Curious, my experience has been the exact opposite:
- It allows using std algorithms like remove_if, which without lambdas are
often easier to reimplement inline each time
- It allows factoring small amounts of code within a single function, where
the data dependency would make extracting the code logic harder than
duplicating it. For instance, a common thing I do is factor some common
(invariant) arguments to a recursive function call.



>
> On Monday, October 22, 2018 at 10:27:10 PM UTC+3, charle...@gmail.com
> wrote:
>>
>> Hi,
>>
>> I have an API that requires passing an object which implements multiple
>> callbacks.
>>
>> For instance:
>>
>> template<typename Callbacks> void myAPI(Callbacks &&c)
>> {
>>   c.foo();
>>   c.bar();
>> }
>>
>> When I use it, I end up doing something like this:
>>
>> void useMyAPI() {
>>   int i;
>>   class MyCallbacks {
>>     MyCallbacks(int &i): i(i) {}
>>     int &i;
>>     void foo() { ++ i; }
>>     void bar() { --i; }
>>   };
>>   myAPI(MyCallbacks{i});
>> }
>>
>>
>> This can be cumbersome if I want to capture more local variables.
>>
>> So, to solve this problem, I'd like to allow captures in local class
>> definitions.
>>
>> To make this work, I would:
>>
>> - make the classes unnamed
>> - force the class to be used immediately to declare a variable or
>> generate a temporary
>>
>> For instance, something like this:
>>
>> void useMyAPI() {
>>   int i = 0;
>>   myAPI(class [&] {
>>     void foo() { ++ i; }
>>     void bar() { --i; }
>>   }());
>> }
>>
>> This would also be useful to generate a class implementing a specific
>> interface using inheritance.
>>
>> Incidentally, lambdas could then be defined in terms of a capture-class
>> with an operator().
>>
>> A useful addition would be to allow putting destructors in them and, in
>> that case, allow an implicit, unnamed variable declaration, for easy
>> RAII, for instance like this:
>>
>> int *p = (int *)malloc(10);
>> class [p] {
>>   ~() { free(p); }
>> };
>>
>> Anyway, so my questions are:
>> - Has something like this already been proposed? It's not easy to search
>> for so I didn't find anything in 5 minutes on google
>> - If not, does it sound interesting? If so I could work on a paper
>>
>> Thanks!
>>
>>

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1b789066-7b95-4034-bd33-ff510b6f5094%40isocpp.org.

------=_Part_1314_1087693827.1540244049390
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Monday, October 22, 2018 at 1:45:44 PM UTC-7, m=
ihailn...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin=
: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div=
 dir=3D"ltr">It has been suggested (can&#39;t find the posts). Problem is i=
t is ultimately a niche feature, that has workarounds, and still requires c=
onsiderable amount of work to design and implement.</div></blockquote><div>=
<br></div><div>Fair enough.<br></div><div>=C2=A0</div><blockquote class=3D"=
gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc so=
lid;padding-left: 1ex;"><div dir=3D"ltr"><div><br></div><div>Also don&#39;t=
 forget that lambdas don&#39;t exactly stimulate code reuse.</div></div></b=
lockquote><div><br></div><div>Curious, my experience has been the exact opp=
osite:</div><div>- It allows using std algorithms like remove_if, which wit=
hout lambdas are often easier to reimplement inline each time</div><div>- I=
t allows factoring small amounts of code within a single function, where th=
e data dependency would make extracting the code logic harder than duplicat=
ing it. For instance, a common thing I do is factor some common (invariant)=
 arguments to a recursive function call.<br></div><div><br></div><div>=C2=
=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div=
><br>On Monday, October 22, 2018 at 10:27:10 PM UTC+3, <a>charle...@gmail.c=
om</a> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-lef=
t:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><pre>=
Hi,

I have an API that requires passing an object which implements multiple
callbacks.

For instance:

template&lt;typename Callbacks&gt; void myAPI(Callbacks &amp;&amp;c)
{
  c.foo();
  c.bar();
}

When I use it, I end up doing something like this:

void useMyAPI() {
  int i;
  class MyCallbacks {
    MyCallbacks(int &amp;i): i(i) {}
    int &amp;i;
    void foo() { ++ i; }
    void bar() { --i; }
  };
  myAPI(MyCallbacks{i});
}


This can be cumbersome if I want to capture more local variables.

So, to solve this problem, I&#39;d like to allow captures in local class
definitions.

To make this work, I would:

- make the classes unnamed
- force the class to be used immediately to declare a variable or
generate a temporary

For instance, something like this:

void useMyAPI() {
  int i =3D 0;
  myAPI(class [&amp;] {
    void foo() { ++ i; }
    void bar() { --i; }
  }());
}

This would also be useful to generate a class implementing a specific
interface using inheritance.

Incidentally, lambdas could then be defined in terms of a capture-class
with an operator().

A useful addition would be to allow putting destructors in them and, in
that case, allow an implicit, unnamed variable declaration, for easy
RAII, for instance like this:

int *p =3D (int *)malloc(10);
class [p] {
  ~() { free(p); }
};

Anyway, so my questions are:
- Has something like this already been proposed? It&#39;s not easy to searc=
h
for so I didn&#39;t find anything in 5 minutes on google
- If not, does it sound interesting? If so I could work on a paper

Thanks!
</pre></div></blockquote></div></div></blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/1b789066-7b95-4034-bd33-ff510b6f5094%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1b789066-7b95-4034-bd33-ff510b6f5094=
%40isocpp.org</a>.<br />

------=_Part_1314_1087693827.1540244049390--

------=_Part_1313_604752206.1540244049390--

.


Author: mutant.sheepdog@gmail.com
Date: Mon, 22 Oct 2018 22:12:15 -0700 (PDT)
Raw View
------=_Part_545_90983777.1540271535294
Content-Type: multipart/alternative;
 boundary="----=_Part_546_1128105786.1540271535295"

------=_Part_546_1128105786.1540271535295
Content-Type: text/plain; charset="UTF-8"

You might be able to get what you need out of the proposed std::overload
(not sure of the status of that).
Godbolt example: https://godbolt.org/z/IulFWz

On Tuesday, 23 October 2018 06:27:10 UTC+11, charle...@gmail.com wrote:
>
> Hi,
>
> I have an API that requires passing an object which implements multiple
> callbacks.
>
> For instance:
>
> template<typename Callbacks> void myAPI(Callbacks &&c)
> {
>   c.foo();
>   c.bar();
> }
>
> When I use it, I end up doing something like this:
>
> void useMyAPI() {
>   int i;
>   class MyCallbacks {
>     MyCallbacks(int &i): i(i) {}
>     int &i;
>     void foo() { ++ i; }
>     void bar() { --i; }
>   };
>   myAPI(MyCallbacks{i});
> }
>
>
> This can be cumbersome if I want to capture more local variables.
>
> So, to solve this problem, I'd like to allow captures in local class
> definitions.
>
> To make this work, I would:
>
> - make the classes unnamed
> - force the class to be used immediately to declare a variable or
> generate a temporary
>
> For instance, something like this:
>
> void useMyAPI() {
>   int i = 0;
>   myAPI(class [&] {
>     void foo() { ++ i; }
>     void bar() { --i; }
>   }());
> }
>
> This would also be useful to generate a class implementing a specific
> interface using inheritance.
>
> Incidentally, lambdas could then be defined in terms of a capture-class
> with an operator().
>
> A useful addition would be to allow putting destructors in them and, in
> that case, allow an implicit, unnamed variable declaration, for easy
> RAII, for instance like this:
>
> int *p = (int *)malloc(10);
> class [p] {
>   ~() { free(p); }
> };
>
> Anyway, so my questions are:
> - Has something like this already been proposed? It's not easy to search
> for so I didn't find anything in 5 minutes on google
> - If not, does it sound interesting? If so I could work on a paper
>
> Thanks!
>
>

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/00a6d453-fc6f-49c9-aa7d-f1135b3aacd3%40isocpp.org.

------=_Part_546_1128105786.1540271535295
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>You might be able to get what you need out of the pro=
posed std::overload (not sure of the status of that).</div><div>Godbolt exa=
mple: https://godbolt.org/z/IulFWz<br></div><br>On Tuesday, 23 October 2018=
 06:27:10 UTC+11, charle...@gmail.com  wrote:<blockquote class=3D"gmail_quo=
te" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddi=
ng-left: 1ex;"><div dir=3D"ltr"><pre>Hi,

I have an API that requires passing an object which implements multiple
callbacks.

For instance:

template&lt;typename Callbacks&gt; void myAPI(Callbacks &amp;&amp;c)
{
  c.foo();
  c.bar();
}

When I use it, I end up doing something like this:

void useMyAPI() {
  int i;
  class MyCallbacks {
    MyCallbacks(int &amp;i): i(i) {}
    int &amp;i;
    void foo() { ++ i; }
    void bar() { --i; }
  };
  myAPI(MyCallbacks{i});
}


This can be cumbersome if I want to capture more local variables.

So, to solve this problem, I&#39;d like to allow captures in local class
definitions.

To make this work, I would:

- make the classes unnamed
- force the class to be used immediately to declare a variable or
generate a temporary

For instance, something like this:

void useMyAPI() {
  int i =3D 0;
  myAPI(class [&amp;] {
    void foo() { ++ i; }
    void bar() { --i; }
  }());
}

This would also be useful to generate a class implementing a specific
interface using inheritance.

Incidentally, lambdas could then be defined in terms of a capture-class
with an operator().

A useful addition would be to allow putting destructors in them and, in
that case, allow an implicit, unnamed variable declaration, for easy
RAII, for instance like this:

int *p =3D (int *)malloc(10);
class [p] {
  ~() { free(p); }
};

Anyway, so my questions are:
- Has something like this already been proposed? It&#39;s not easy to searc=
h
for so I didn&#39;t find anything in 5 minutes on google
- If not, does it sound interesting? If so I could work on a paper

Thanks!
</pre></div></blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/00a6d453-fc6f-49c9-aa7d-f1135b3aacd3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/00a6d453-fc6f-49c9-aa7d-f1135b3aacd3=
%40isocpp.org</a>.<br />

------=_Part_546_1128105786.1540271535295--

------=_Part_545_90983777.1540271535294--

.


Author: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Date: Wed, 24 Oct 2018 17:31:59 +0300
Raw View
--0000000000001968cb0578fa5a94
Content-Type: text/plain; charset="UTF-8"

If not directly std::overload, its implementation should give you the idea
of how to implement what you need as a pure library.

On Tue, Oct 23, 2018, 08:12 <mutant.sheepdog@gmail.com> wrote:

> You might be able to get what you need out of the proposed std::overload
> (not sure of the status of that).
> Godbolt example: https://godbolt.org/z/IulFWz
>
> On Tuesday, 23 October 2018 06:27:10 UTC+11, charle...@gmail.com wrote:
>>
>> Hi,
>>
>> I have an API that requires passing an object which implements multiple
>> callbacks.
>>
>> For instance:
>>
>> template<typename Callbacks> void myAPI(Callbacks &&c)
>> {
>>   c.foo();
>>   c.bar();
>> }
>>
>> When I use it, I end up doing something like this:
>>
>> void useMyAPI() {
>>   int i;
>>   class MyCallbacks {
>>     MyCallbacks(int &i): i(i) {}
>>     int &i;
>>     void foo() { ++ i; }
>>     void bar() { --i; }
>>   };
>>   myAPI(MyCallbacks{i});
>> }
>>
>>
>> This can be cumbersome if I want to capture more local variables.
>>
>> So, to solve this problem, I'd like to allow captures in local class
>> definitions.
>>
>> To make this work, I would:
>>
>> - make the classes unnamed
>> - force the class to be used immediately to declare a variable or
>> generate a temporary
>>
>> For instance, something like this:
>>
>> void useMyAPI() {
>>   int i = 0;
>>   myAPI(class [&] {
>>     void foo() { ++ i; }
>>     void bar() { --i; }
>>   }());
>> }
>>
>> This would also be useful to generate a class implementing a specific
>> interface using inheritance.
>>
>> Incidentally, lambdas could then be defined in terms of a capture-class
>> with an operator().
>>
>> A useful addition would be to allow putting destructors in them and, in
>> that case, allow an implicit, unnamed variable declaration, for easy
>> RAII, for instance like this:
>>
>> int *p = (int *)malloc(10);
>> class [p] {
>>   ~() { free(p); }
>> };
>>
>> Anyway, so my questions are:
>> - Has something like this already been proposed? It's not easy to search
>> for so I didn't find anything in 5 minutes on google
>> - If not, does it sound interesting? If so I could work on a paper
>>
>> Thanks!
>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/00a6d453-fc6f-49c9-aa7d-f1135b3aacd3%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/00a6d453-fc6f-49c9-aa7d-f1135b3aacd3%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkWkKtC-bHrToHc-zHWySFWxhW6_1LxrjZoVo9VfeWCSPA%40mail.gmail.com.

--0000000000001968cb0578fa5a94
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">If not directly std::overload, its implementation should =
give you the idea of how to implement what you need as a pure library.</div=
><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Oct 23, 2018, 08:1=
2  &lt;<a href=3D"mailto:mutant.sheepdog@gmail.com">mutant.sheepdog@gmail.c=
om</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margi=
n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">=
<div>You might be able to get what you need out of the proposed std::overlo=
ad (not sure of the status of that).</div><div>Godbolt example: <a href=3D"=
https://godbolt.org/z/IulFWz" target=3D"_blank" rel=3D"noreferrer">https://=
godbolt.org/z/IulFWz</a><br></div><br>On Tuesday, 23 October 2018 06:27:10 =
UTC+11, <a href=3D"mailto:charle...@gmail.com" target=3D"_blank" rel=3D"nor=
eferrer">charle...@gmail.com</a>  wrote:<blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:=
1ex"><div dir=3D"ltr"><pre>Hi,

I have an API that requires passing an object which implements multiple
callbacks.

For instance:

template&lt;typename Callbacks&gt; void myAPI(Callbacks &amp;&amp;c)
{
  c.foo();
  c.bar();
}

When I use it, I end up doing something like this:

void useMyAPI() {
  int i;
  class MyCallbacks {
    MyCallbacks(int &amp;i): i(i) {}
    int &amp;i;
    void foo() { ++ i; }
    void bar() { --i; }
  };
  myAPI(MyCallbacks{i});
}


This can be cumbersome if I want to capture more local variables.

So, to solve this problem, I&#39;d like to allow captures in local class
definitions.

To make this work, I would:

- make the classes unnamed
- force the class to be used immediately to declare a variable or
generate a temporary

For instance, something like this:

void useMyAPI() {
  int i =3D 0;
  myAPI(class [&amp;] {
    void foo() { ++ i; }
    void bar() { --i; }
  }());
}

This would also be useful to generate a class implementing a specific
interface using inheritance.

Incidentally, lambdas could then be defined in terms of a capture-class
with an operator().

A useful addition would be to allow putting destructors in them and, in
that case, allow an implicit, unnamed variable declaration, for easy
RAII, for instance like this:

int *p =3D (int *)malloc(10);
class [p] {
  ~() { free(p); }
};

Anyway, so my questions are:
- Has something like this already been proposed? It&#39;s not easy to searc=
h
for so I didn&#39;t find anything in 5 minutes on google
- If not, does it sound interesting? If so I could work on a paper

Thanks!
</pre></div></blockquote></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank" rel=3D"noreferrer">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank" rel=3D"noreferrer">std-proposals@isocpp.org</a>.<br=
>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/00a6d453-fc6f-49c9-aa7d-f1135b3aacd3%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank" =
rel=3D"noreferrer">https://groups.google.com/a/isocpp.org/d/msgid/std-propo=
sals/00a6d453-fc6f-49c9-aa7d-f1135b3aacd3%40isocpp.org</a>.<br>
</blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkWkKtC-bHrToHc-zHWySFWxhW6_1L=
xrjZoVo9VfeWCSPA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkWkKtC-=
bHrToHc-zHWySFWxhW6_1LxrjZoVo9VfeWCSPA%40mail.gmail.com</a>.<br />

--0000000000001968cb0578fa5a94--

.


Author: Victor Dyachenko <victor.dyachenko@gmail.com>
Date: Thu, 25 Oct 2018 03:47:44 -0700 (PDT)
Raw View
------=_Part_316_354261156.1540464464612
Content-Type: multipart/alternative;
 boundary="----=_Part_317_77544798.1540464464612"

------=_Part_317_77544798.1540464464612
Content-Type: text/plain; charset="UTF-8"

On Tuesday, October 23, 2018 at 8:12:15 AM UTC+3, mutant....@gmail.com
wrote:
>
> You might be able to get what you need out of the proposed std::overload
> (not sure of the status of that).
> Godbolt example: https://godbolt.org/z/IulFWz
>

And now we have copy of the captured data in EACH lambda. std::overload is
a bad solution.


- If not, does it sound interesting? If so I could work on a paper
>
>
Sounds interesting for me. std::variant visitation is more convenient using
functional objects like:

struct visitor
{
    void operator()(int v) const { ...; }
    void operator()(float v) const { ...; }
    template<class Other> void operator()(const Other &v) const { ...; }
};

It's more convenient that

[](auto &v) {
    using T = std::remove_cvref_t<decltype(v)>;
    if constexpr(std::is_same<T, int>())
        ...;
    else if constexpr(std::is_same<T, float>())
        ...;
    else
        ...;
}

But almost always we need to capture some data and it's a pain with
hand-written class now... :-(

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a92696b6-06b5-41f8-8be9-b7bf8c2bc6c1%40isocpp.org.

------=_Part_317_77544798.1540464464612
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, October 23, 2018 at 8:12:15 AM UTC+3, mutant..=
...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr"><div>You might be able to get what you need out of the proposed std::=
overload (not sure of the status of that).</div><div>Godbolt example: <a hr=
ef=3D"https://godbolt.org/z/IulFWz" target=3D"_blank" rel=3D"nofollow" onmo=
usedown=3D"this.href=3D&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fg=
odbolt.org%2Fz%2FIulFWz\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEKl22svWwgR=
nKVxkzKmWimX5vOYg&#39;;return true;" onclick=3D"this.href=3D&#39;https://ww=
w.google.com/url?q\x3dhttps%3A%2F%2Fgodbolt.org%2Fz%2FIulFWz\x26sa\x3dD\x26=
sntz\x3d1\x26usg\x3dAFQjCNEKl22svWwgRnKVxkzKmWimX5vOYg&#39;;return true;">h=
ttps://godbolt.org/z/IulFWz</a></div></div></blockquote><div><br></div><div=
>And now we have copy of the captured data in EACH lambda. std::overload is=
 a bad solution.</div><div><br></div><div><br></div><div></div><blockquote =
class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; border-left: 1px =
solid rgb(204, 204, 204); padding-left: 1ex;"><div><pre>- If not, does it s=
ound interesting? If so I could work on a paper</pre></div></blockquote><di=
v><br></div><div>Sounds interesting for me. std::variant visitation is more=
 convenient using functional objects like:</div><div><br></div>struct visit=
or<br>{<br>=C2=A0=C2=A0=C2=A0 void operator()(int v) const { ...; }<br>=C2=
=A0=C2=A0=C2=A0 void operator()(float v) const { ...; }<br>=C2=A0=C2=A0=C2=
=A0 template&lt;class Other&gt; void operator()(const Other &amp;v) const {=
 ...; }<br>};<br><br><div>It&#39;s more convenient that</div><div><br></div=
><div>[](auto &amp;v) {<br>=C2=A0=C2=A0=C2=A0 using T =3D std::remove_cvref=
_t&lt;decltype(v)&gt;;<br>=C2=A0=C2=A0=C2=A0 if constexpr(std::is_same&lt;T=
, int&gt;())<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ...;<br>=C2=A0=
=C2=A0=C2=A0 else if constexpr(std::is_same&lt;T, float&gt;())<br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ...;<br>=C2=A0=C2=A0=C2=A0 else<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ...;<br>}<br></div><div><br></div><div=
>But almost always we need to capture some data and it&#39;s a pain with ha=
nd-written class now... :-(<br></div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a92696b6-06b5-41f8-8be9-b7bf8c2bc6c1%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a92696b6-06b5-41f8-8be9-b7bf8c2bc6c1=
%40isocpp.org</a>.<br />

------=_Part_317_77544798.1540464464612--

------=_Part_316_354261156.1540464464612--

.


Author: Olivier Sohn <olivier.sohn@gmail.com>
Date: Fri, 26 Oct 2018 01:29:49 -0700 (PDT)
Raw View
------=_Part_692_2134111152.1540542589850
Content-Type: multipart/alternative;
 boundary="----=_Part_693_405275061.1540542589850"

------=_Part_693_405275061.1540542589850
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello,

I like the first part of the idea, however I think that allowing to=20
implement destructors may not be a good idea: with the example you provide,=
=20
if the lambda is somewhere passed by value, then the source lambda will be=
=20
destructed, the pointer will be deleted and the lambda copy will have a=20
dangling pointer. Capturing using a std::unique_ptr=20
<https://stackoverflow.com/questions/8236521/how-to-capture-a-unique-ptr-in=
to-a-lambda-expression> in=20
your example would do what you want, without the need to write a destructor=
..

My 2 cents

Olivier


Le lundi 22 octobre 2018 21:27:10 UTC+2, charle...@gmail.com a =C3=A9crit :
>
> Hi,
>
> I have an API that requires passing an object which implements multiple
> callbacks.
>
> For instance:
>
> template<typename Callbacks> void myAPI(Callbacks &&c)
> {
>   c.foo();
>   c.bar();
> }
>
> When I use it, I end up doing something like this:
>
> void useMyAPI() {
>   int i;
>   class MyCallbacks {
>     MyCallbacks(int &i): i(i) {}
>     int &i;
>     void foo() { ++ i; }
>     void bar() { --i; }
>   };
>   myAPI(MyCallbacks{i});
> }
>
>
> This can be cumbersome if I want to capture more local variables.
>
> So, to solve this problem, I'd like to allow captures in local class
> definitions.
>
> To make this work, I would:
>
> - make the classes unnamed
> - force the class to be used immediately to declare a variable or
> generate a temporary
>
> For instance, something like this:
>
> void useMyAPI() {
>   int i =3D 0;
>   myAPI(class [&] {
>     void foo() { ++ i; }
>     void bar() { --i; }
>   }());
> }
>
> This would also be useful to generate a class implementing a specific
> interface using inheritance.
>
> Incidentally, lambdas could then be defined in terms of a capture-class
> with an operator().
>
> A useful addition would be to allow putting destructors in them and, in
> that case, allow an implicit, unnamed variable declaration, for easy
> RAII, for instance like this:
>
> int *p =3D (int *)malloc(10);
> class [p] {
>   ~() { free(p); }
> };
>
> Anyway, so my questions are:
> - Has something like this already been proposed? It's not easy to search
> for so I didn't find anything in 5 minutes on google
> - If not, does it sound interesting? If so I could work on a paper
>
> Thanks!
>
>

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/523bb4bb-aca6-4ae8-911f-9e0839675e5b%40isocpp.or=
g.

------=_Part_693_405275061.1540542589850
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello,<div><br></div><div>I like the first part of the ide=
a, however I think that allowing to implement destructors may not be a good=
 idea: with the example you provide, if the lambda is somewhere passed by v=
alue, then the source lambda will be destructed, the pointer will be delete=
d and the lambda copy will have a dangling pointer. Capturing=C2=A0<a href=
=3D"https://stackoverflow.com/questions/8236521/how-to-capture-a-unique-ptr=
-into-a-lambda-expression">using a std::unique_ptr</a>=C2=A0in your example=
 would do what you want, without the need to write a destructor.<div><div><=
br></div><div>My 2 cents</div><div><br></div><div>Olivier<br></div></div></=
div><div><br></div><br>Le lundi 22 octobre 2018 21:27:10 UTC+2, charle...@g=
mail.com a =C3=A9crit=C2=A0:<blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><d=
iv dir=3D"ltr"><pre>Hi,

I have an API that requires passing an object which implements multiple
callbacks.

For instance:

template&lt;typename Callbacks&gt; void myAPI(Callbacks &amp;&amp;c)
{
  c.foo();
  c.bar();
}

When I use it, I end up doing something like this:

void useMyAPI() {
  int i;
  class MyCallbacks {
    MyCallbacks(int &amp;i): i(i) {}
    int &amp;i;
    void foo() { ++ i; }
    void bar() { --i; }
  };
  myAPI(MyCallbacks{i});
}


This can be cumbersome if I want to capture more local variables.

So, to solve this problem, I&#39;d like to allow captures in local class
definitions.

To make this work, I would:

- make the classes unnamed
- force the class to be used immediately to declare a variable or
generate a temporary

For instance, something like this:

void useMyAPI() {
  int i =3D 0;
  myAPI(class [&amp;] {
    void foo() { ++ i; }
    void bar() { --i; }
  }());
}

This would also be useful to generate a class implementing a specific
interface using inheritance.

Incidentally, lambdas could then be defined in terms of a capture-class
with an operator().

A useful addition would be to allow putting destructors in them and, in
that case, allow an implicit, unnamed variable declaration, for easy
RAII, for instance like this:

int *p =3D (int *)malloc(10);
class [p] {
  ~() { free(p); }
};

Anyway, so my questions are:
- Has something like this already been proposed? It&#39;s not easy to searc=
h
for so I didn&#39;t find anything in 5 minutes on google
- If not, does it sound interesting? If so I could work on a paper

Thanks!
</pre></div></blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/523bb4bb-aca6-4ae8-911f-9e0839675e5b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/523bb4bb-aca6-4ae8-911f-9e0839675e5b=
%40isocpp.org</a>.<br />

------=_Part_693_405275061.1540542589850--

------=_Part_692_2134111152.1540542589850--

.


Author: charleshenri@gmail.com
Date: Fri, 26 Oct 2018 16:51:15 -0700 (PDT)
Raw View
------=_Part_1134_214654802.1540597875321
Content-Type: multipart/alternative;
 boundary="----=_Part_1135_1184231052.1540597875321"

------=_Part_1135_1184231052.1540597875321
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable



On Friday, October 26, 2018 at 1:29:49 AM UTC-7, Olivier Sohn wrote:
>
> Hello,
>
> I like the first part of the idea, however I think that allowing to=20
> implement destructors may not be a good idea: with the example you provid=
e,=20
> if the lambda is somewhere passed by value, then the source lambda will b=
e=20
> destructed, the pointer will be deleted and the lambda copy will have a=
=20
> dangling pointer. Capturing using a std::unique_ptr=20
> <https://www.google.com/url?q=3Dhttps%3A%2F%2Fstackoverflow.com%2Fquestio=
ns%2F8236521%2Fhow-to-capture-a-unique-ptr-into-a-lambda-expression&sa=3DD&=
sntz=3D1&usg=3DAFQjCNFQoPc45xM-K5CxKLIKPRjumfq0lw> in=20
> your example would do what you want, without the need to write a destruct=
or.
>

In my example with a destructor, an anonymous instance of the unnamed type=
=20
is generated. There's no way to copy the instance. I'm not sure I=20
understand your objection.
My preferred solution would be to allow "finally" in C++, but that's=20
probably never going to happen.
=20

>
> My 2 cents
>
> Olivier
>
>
> Le lundi 22 octobre 2018 21:27:10 UTC+2, charle...@gmail.com a =C3=A9crit=
 :
>>
>> Hi,
>>
>> I have an API that requires passing an object which implements multiple
>> callbacks.
>>
>> For instance:
>>
>> template<typename Callbacks> void myAPI(Callbacks &&c)
>> {
>>   c.foo();
>>   c.bar();
>> }
>>
>> When I use it, I end up doing something like this:
>>
>> void useMyAPI() {
>>   int i;
>>   class MyCallbacks {
>>     MyCallbacks(int &i): i(i) {}
>>     int &i;
>>     void foo() { ++ i; }
>>     void bar() { --i; }
>>   };
>>   myAPI(MyCallbacks{i});
>> }
>>
>>
>> This can be cumbersome if I want to capture more local variables.
>>
>> So, to solve this problem, I'd like to allow captures in local class
>> definitions.
>>
>> To make this work, I would:
>>
>> - make the classes unnamed
>> - force the class to be used immediately to declare a variable or
>> generate a temporary
>>
>> For instance, something like this:
>>
>> void useMyAPI() {
>>   int i =3D 0;
>>   myAPI(class [&] {
>>     void foo() { ++ i; }
>>     void bar() { --i; }
>>   }());
>> }
>>
>> This would also be useful to generate a class implementing a specific
>> interface using inheritance.
>>
>> Incidentally, lambdas could then be defined in terms of a capture-class
>> with an operator().
>>
>> A useful addition would be to allow putting destructors in them and, in
>> that case, allow an implicit, unnamed variable declaration, for easy
>> RAII, for instance like this:
>>
>> int *p =3D (int *)malloc(10);
>> class [p] {
>>   ~() { free(p); }
>> };
>>
>> Anyway, so my questions are:
>> - Has something like this already been proposed? It's not easy to search
>> for so I didn't find anything in 5 minutes on google
>> - If not, does it sound interesting? If so I could work on a paper
>>
>> Thanks!
>>
>>

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/1ca63b59-268a-4818-9ba9-08c4f58595ef%40isocpp.or=
g.

------=_Part_1135_1184231052.1540597875321
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Friday, October 26, 2018 at 1:29:49 AM UTC-7, O=
livier Sohn wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr">Hello,<div><br></div><div>I like the first part of the idea, however I=
 think that allowing to implement destructors may not be a good idea: with =
the example you provide, if the lambda is somewhere passed by value, then t=
he source lambda will be destructed, the pointer will be deleted and the la=
mbda copy will have a dangling pointer. Capturing=C2=A0<a href=3D"https://w=
ww.google.com/url?q=3Dhttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F8236521=
%2Fhow-to-capture-a-unique-ptr-into-a-lambda-expression&amp;sa=3DD&amp;sntz=
=3D1&amp;usg=3DAFQjCNFQoPc45xM-K5CxKLIKPRjumfq0lw" target=3D"_blank" rel=3D=
"nofollow" onmousedown=3D"this.href=3D&#39;https://www.google.com/url?q\x3d=
https%3A%2F%2Fstackoverflow.com%2Fquestions%2F8236521%2Fhow-to-capture-a-un=
ique-ptr-into-a-lambda-expression\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF=
QoPc45xM-K5CxKLIKPRjumfq0lw&#39;;return true;" onclick=3D"this.href=3D&#39;=
https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%2Fquestions=
%2F8236521%2Fhow-to-capture-a-unique-ptr-into-a-lambda-expression\x26sa\x3d=
D\x26sntz\x3d1\x26usg\x3dAFQjCNFQoPc45xM-K5CxKLIKPRjumfq0lw&#39;;return tru=
e;">using a std::unique_ptr</a>=C2=A0in your example would do what you want=
, without the need to write a destructor.</div></div></blockquote><div><br>=
</div><div>In my example with a destructor, an anonymous instance of the un=
named type is generated. There&#39;s no way to copy the instance. I&#39;m n=
ot sure I understand your objection.</div><div>My preferred solution would =
be to allow &quot;finally&quot; in C++, but that&#39;s probably never going=
 to happen.<br></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" sty=
le=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left=
: 1ex;"><div dir=3D"ltr"><div><div><div><br></div><div>My 2 cents</div><div=
><br></div><div>Olivier<br></div></div></div><div><br></div><br>Le lundi 22=
 octobre 2018 21:27:10 UTC+2, <a>charle...@gmail.com</a> a =C3=A9crit=C2=A0=
:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bord=
er-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><pre>Hi,

I have an API that requires passing an object which implements multiple
callbacks.

For instance:

template&lt;typename Callbacks&gt; void myAPI(Callbacks &amp;&amp;c)
{
  c.foo();
  c.bar();
}

When I use it, I end up doing something like this:

void useMyAPI() {
  int i;
  class MyCallbacks {
    MyCallbacks(int &amp;i): i(i) {}
    int &amp;i;
    void foo() { ++ i; }
    void bar() { --i; }
  };
  myAPI(MyCallbacks{i});
}


This can be cumbersome if I want to capture more local variables.

So, to solve this problem, I&#39;d like to allow captures in local class
definitions.

To make this work, I would:

- make the classes unnamed
- force the class to be used immediately to declare a variable or
generate a temporary

For instance, something like this:

void useMyAPI() {
  int i =3D 0;
  myAPI(class [&amp;] {
    void foo() { ++ i; }
    void bar() { --i; }
  }());
}

This would also be useful to generate a class implementing a specific
interface using inheritance.

Incidentally, lambdas could then be defined in terms of a capture-class
with an operator().

A useful addition would be to allow putting destructors in them and, in
that case, allow an implicit, unnamed variable declaration, for easy
RAII, for instance like this:

int *p =3D (int *)malloc(10);
class [p] {
  ~() { free(p); }
};

Anyway, so my questions are:
- Has something like this already been proposed? It&#39;s not easy to searc=
h
for so I didn&#39;t find anything in 5 minutes on google
- If not, does it sound interesting? If so I could work on a paper

Thanks!
</pre></div></blockquote></div></blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/1ca63b59-268a-4818-9ba9-08c4f58595ef%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1ca63b59-268a-4818-9ba9-08c4f58595ef=
%40isocpp.org</a>.<br />

------=_Part_1135_1184231052.1540597875321--

------=_Part_1134_214654802.1540597875321--

.


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Fri, 26 Oct 2018 19:52:24 -0700 (PDT)
Raw View
------=_Part_1177_1769421857.1540608744479
Content-Type: multipart/alternative;
 boundary="----=_Part_1178_81009567.1540608744480"

------=_Part_1178_81009567.1540608744480
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Friday, October 26, 2018 at 7:51:15 PM UTC-4, charle...@gmail.com wrote:
>
> On Friday, October 26, 2018 at 1:29:49 AM UTC-7, Olivier Sohn wrote:
>>
>>
>> I like the first part of the idea, however I think that allowing to=20
>> implement destructors may not be a good idea: with the example you provi=
de,=20
>> if the lambda is somewhere passed by value, then the source lambda will =
be=20
>> destructed, the pointer will be deleted and the lambda copy will have a=
=20
>> dangling pointer. Capturing using a std::unique_ptr=20
>> <https://www.google.com/url?q=3Dhttps%3A%2F%2Fstackoverflow.com%2Fquesti=
ons%2F8236521%2Fhow-to-capture-a-unique-ptr-into-a-lambda-expression&sa=3DD=
&sntz=3D1&usg=3DAFQjCNFQoPc45xM-K5CxKLIKPRjumfq0lw> in=20
>> your example would do what you want, without the need to write a destruc=
tor.
>>
>
> In my example with a destructor, an anonymous instance of the unnamed typ=
e=20
> is generated. There's no way to copy the instance. I'm not sure I=20
> understand your objection.
>

Providing a user-provided destructor does not actually render the class=20
non-copyable.
https://wandbox.org/permlink/O9hsBJpgsiqJZCI1
(This behavior is deprecated, but not actually removed.)


My preferred solution would be to allow "finally" in C++, but that's=20
> probably never going to happen.
>

Shameless plug:=20
https://quuxplusone.github.io/blog/2018/08/11/the-auto-macro/

Anyway, as for the idea, I think it's philosophically interesting, but not=
=20
worth pursuing in that form in practice because the cost/benefit ratio (in=
=20
terms of "friction with the existing C++ grammar" and "cost savings for=20
software developers") is just not there.

The people telling you to look at std::overload, AFAICT, are wrong and have=
=20
misunderstood your original post.

I'll chime in a different wrong idea, though: Your problem seems similar in=
=20
spirit to "dynamic polymorphism", in that you have a bag of behaviors and=
=20
you want to wrap it up in something with the right "shape" (which in your=
=20
current codebase is a class with foo and bar methods). If you can change=20
your codebase to prefer Dyno <https://github.com/ldionne/dyno#overview>=20
syntax, then you could end up with something like a cross between std::bind=
=20
and std::overload that yields a Dyno object. I'm too lazy to look up the=20
real syntax but I can see how to implement this syntax in vanilla C++14:

DEFINE_POLY_METHOD_TAG(foo);

DEFINE_POLY_METHOD_TAG(bar);


template<typename Callbacks>

void myAPI(const poly<foo, bar>& c)
{
  c.call<foo>();
  c.call<bar>();
}

void useMyAPI() {
  int i;

  myAPI(

    polybind(std::ref(i))

      .define<foo>([](int& i){ ++i; })

      .define<bar>([](int& i){ --i; })

  );
}


void useMyAPI_simpler() {
  int i;

  myAPI(

    polybind()

      .define<foo>([&](){ ++i; })

      .define<bar>([&](){ --i; })

  );
}


(Hat tip to John Bandela for the c.call<foo>() syntax. He showed it to me a=
t a Bay Area C++ meetup a while back; I don't think it's been implemented a=
nywhere public yet. But it's doable!)


=E2=80=93Arthur

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/c729089c-c560-4add-abd2-6cd6a651d57e%40isocpp.or=
g.

------=_Part_1178_81009567.1540608744480
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Friday, October 26, 2018 at 7:51:15 PM UTC-4, charle...=
@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">On Friday, October 26, 2018 at 1:29:49 AM UTC-7, Olivier Sohn wrote:<bl=
ockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><br></div><div>I=
 like the first part of the idea, however I think that allowing to implemen=
t destructors may not be a good idea: with the example you provide, if the =
lambda is somewhere passed by value, then the source lambda will be destruc=
ted, the pointer will be deleted and the lambda copy will have a dangling p=
ointer. Capturing=C2=A0<a href=3D"https://www.google.com/url?q=3Dhttps%3A%2=
F%2Fstackoverflow.com%2Fquestions%2F8236521%2Fhow-to-capture-a-unique-ptr-i=
nto-a-lambda-expression&amp;sa=3DD&amp;sntz=3D1&amp;usg=3DAFQjCNFQoPc45xM-K=
5CxKLIKPRjumfq0lw" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.h=
ref=3D&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fstackoverflow.com%=
2Fquestions%2F8236521%2Fhow-to-capture-a-unique-ptr-into-a-lambda-expressio=
n\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFQoPc45xM-K5CxKLIKPRjumfq0lw&#39;=
;return true;" onclick=3D"this.href=3D&#39;https://www.google.com/url?q\x3d=
https%3A%2F%2Fstackoverflow.com%2Fquestions%2F8236521%2Fhow-to-capture-a-un=
ique-ptr-into-a-lambda-expression\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF=
QoPc45xM-K5CxKLIKPRjumfq0lw&#39;;return true;">using a std::unique_ptr</a>=
=C2=A0in your example would do what you want, without the need to write a d=
estructor.</div></div></blockquote><div><br></div><div>In my example with a=
 destructor, an anonymous instance of the unnamed type is generated. There&=
#39;s no way to copy the instance. I&#39;m not sure I understand your objec=
tion.</div></div></blockquote><div><br></div><div>Providing a user-provided=
 destructor does not actually render the class non-copyable.</div><div><a h=
ref=3D"https://wandbox.org/permlink/O9hsBJpgsiqJZCI1">https://wandbox.org/p=
ermlink/O9hsBJpgsiqJZCI1</a><br></div><div>(This behavior is deprecated, bu=
t not actually removed.)</div><div><br></div><div><br></div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>My preferred solution w=
ould be to allow &quot;finally&quot; in C++, but that&#39;s probably never =
going to happen.<br></div></div></blockquote><div><br></div><div>Shameless =
plug:=C2=A0<a href=3D"https://quuxplusone.github.io/blog/2018/08/11/the-aut=
o-macro/">https://quuxplusone.github.io/blog/2018/08/11/the-auto-macro/</a>=
</div><div><br></div><div>Anyway, as for the idea, I think it&#39;s philoso=
phically interesting, but not worth pursuing in that form in practice becau=
se the cost/benefit ratio (in terms of &quot;friction with the existing C++=
 grammar&quot; and &quot;cost savings for software developers&quot;) is jus=
t not there.</div><div><br></div><div>The people telling you to look at std=
::overload, AFAICT, are wrong and have misunderstood your original post.</d=
iv><div><br></div><div>I&#39;ll chime in a different wrong idea, though: Yo=
ur problem seems similar in spirit to &quot;dynamic polymorphism&quot;, in =
that you have a bag of behaviors and you want to wrap it up in something wi=
th the right &quot;shape&quot; (which in your current codebase is a class w=
ith foo and bar methods). If you can change your codebase to prefer <a href=
=3D"https://github.com/ldionne/dyno#overview">Dyno</a> syntax, then you cou=
ld end up with something like a cross between std::bind and std::overload t=
hat yields a Dyno object. I&#39;m too lazy to look up the real syntax but I=
 can see how to implement this syntax in vanilla C++14:</div><div><br></div=
><div><pre>DEFINE_POLY_METHOD_TAG(foo);</pre><div><pre>DEFINE_POLY_METHOD_T=
AG(bar);</pre></div><div><br></div><pre>template&lt;typename Callbacks&gt;<=
/pre><pre>void myAPI(const poly&lt;foo, bar&gt;&amp; c)
{
  c.call&lt;foo&gt;();
  c.call&lt;bar&gt;();
}

void useMyAPI() {
  int i;</pre><pre>  myAPI(</pre><pre>    polybind(std::ref(i))</pre><pre> =
     .define&lt;foo&gt;([](int&amp; i){ ++i; })</pre><pre>      .define&lt;=
bar&gt;([](int&amp; i){ --i; })</pre><pre>  );
}</pre></div><div><br></div><div><div><pre>void useMyAPI_simpler() {
  int i;</pre><pre>  myAPI(</pre><pre>    polybind()</pre><pre>      .defin=
e&lt;foo&gt;([&amp;](){ ++i; })</pre><pre>      .define&lt;bar&gt;([&amp;](=
){ --i; })</pre><pre>  );
}</pre><pre><br></pre><pre><font face=3D"arial, sans-serif">(Hat tip to Joh=
n Bandela for the </font>c.call&lt;foo&gt;()<font face=3D"arial, sans-serif=
"> syntax. He showed it to me at a Bay Area C++ meetup a while back; I don&=
#39;t think it&#39;s been implemented anywhere public yet. But it&#39;s doa=
ble!)</font></pre></div></div><div><br></div><div>=E2=80=93Arthur</div></di=
v>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/c729089c-c560-4add-abd2-6cd6a651d57e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c729089c-c560-4add-abd2-6cd6a651d57e=
%40isocpp.org</a>.<br />

------=_Part_1178_81009567.1540608744480--

------=_Part_1177_1769421857.1540608744479--

.


Author: Raymund Hofmann <hofmannraymund@gmail.com>
Date: Mon, 29 Oct 2018 20:55:54 +0700
Raw View
--000000000000ada57305795e77f1
Content-Type: text/plain; charset="UTF-8"

I had a similar idea for anonymous "lambda classes" just extending the
lambda function idea we already have.

We have lambda functions anyway and basically they are a class with
function call operator, why not extend them to be a "lambda class"?

My motivation was to create a self-owned anonymous deriving from
"enable_shared_from_this" class that is kicked off as a servlet that
captures a few things from the current scope and then doing some network
stuff and destroying itself when finished.

I ended up doing it with a lambda like so:

struct selfowning_functor : public
std::enable_shared_from_this<selfowning_functor>
{
    typedef function<void(shared_ptr<struct selfowning_functor>&&)> rc_ft;
    rc_ft lambda;
    selfowning_functor(rc_ft&& _f) : lambda(std::move(_f)) {}
    void start(void)
    {
        lambda(shared_from_this());
    }
    void operator()(void)
    {
        lambda(shared_from_this());
    }
};

template<class _Type>
shared_ptr<selfowning_functor> make_selfowning_functor(_Type&& _Arg)
{
    return make_shared<selfowning_functor>(_Arg);
}

use:
                make_selfowning_functor([=, buffer =
vector<char>(0x10000)](auto&& self) mutable
                {
                    if (auto read_length = ifs->read(&buffer[0],
buffer.size()).gcount(); read_length > 0)
                    {
                        response->write(&buffer[0], read_length);
                        if (read_length == buffer.size())
                            response->send([=](auto &ec)
                                {
                                    if (!ec)
                                        (*self)();
                                    else
                                        cerr << "Connection interrupted" <<
endl;
                                });
                    }
                })->start();


So this is the "library" solution wrapping a capturing lambda in a class
and also allowing the lambda to be recursive.

I can't see how a language extension somewhat like "[] class (){}" to the
already existing and very useful "[](){}" would create much "friction with
the existing C++ grammar. How would it?


Then you could also define classes quickly that have members/captures
without repeating their name thrice, greatly improving DRY.

Sure, details are not worked out, but it is a good idea to work on.

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAD_7Vbks-oT0%3DRFiaPFn304iHY07J6LygUfCCRjv-kpd7yhKGw%40mail.gmail.com.

--000000000000ada57305795e77f1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div>I had a similar ide=
a for anonymous &quot;lambda classes&quot; just extending the lambda functi=
on idea we already have.</div><div><br></div><div>
<div class=3D"gmail_quote">We have lambda functions anyway and basically th=
ey are a class with function call operator, why not extend them to be a &qu=
ot;lambda class&quot;?<br></div><div class=3D"gmail_quote"><br></div>

</div><div>My motivation was to create a self-owned anonymous deriving from=
 &quot;enable_shared_from_this&quot; class that is kicked off as a servlet =
that captures a few things from the current scope and then doing some netwo=
rk stuff and destroying itself when finished.</div><div><br></div><div>I en=
ded up doing it with a lambda like so:</div><div><span style=3D"font-family=
:monospace,monospace"><br>struct selfowning_functor : public std::enable_sh=
ared_from_this&lt;selfowning_functor&gt;<br>{<br>=C2=A0=C2=A0=C2=A0 typedef=
 function&lt;void(shared_ptr&lt;struct selfowning_functor&gt;&amp;&amp;)&gt=
; rc_ft;<br>=C2=A0=C2=A0=C2=A0 rc_ft lambda;<br>=C2=A0=C2=A0=C2=A0 selfowni=
ng_functor(rc_ft&amp;&amp; _f) : lambda(std::move(_f)) {}<br>=C2=A0=C2=A0=
=C2=A0 void start(void)<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 lambda(shared_from_this());<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=
=A0=C2=A0=C2=A0 void operator()(void)<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=
=A0=C2=A0 =C2=A0=C2=A0=C2=A0 lambda(shared_from_this());<br>=C2=A0=C2=A0=C2=
=A0 }<br>};<br><br>template&lt;class _Type&gt;<br>shared_ptr&lt;selfowning_=
functor&gt; make_selfowning_functor(_Type&amp;&amp; _Arg)<br>{<br>=C2=A0=C2=
=A0=C2=A0 return make_shared&lt;selfowning_functor&gt;(_Arg);<br>}<br></spa=
n></div><div><span style=3D"font-family:monospace,monospace"><br></span></d=
iv><div><span style=3D"font-family:monospace,monospace">use:<br></span></di=
v><div><span style=3D"font-family:monospace,monospace">=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 make_selfowning_fu=
nctor([=3D, buffer =3D vector&lt;char&gt;(0x10000)](auto&amp;&amp; self) mu=
table<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=
=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (auto read_length =3D ifs-&gt;read(&a=
mp;buffer[0], buffer.size()).gcount(); read_length &gt; 0)<br>=C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=
=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 response-&gt;write(&a=
mp;buffer[0], read_length);<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (r=
ead_length =3D=3D buffer.size())<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 response-&gt;send([=3D](auto &amp;ec) <br>=C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=
=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 { <br>=
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 if (!ec)<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 (*self)(); <br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=
 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 else<br>=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 cerr &lt;&lt; &quot;Connection interrupted&quot; &lt;&lt=
; endl;<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=
=A0=C2=A0=C2=A0 });<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 })-&gt;start();<br></spa=
n><br></div></div></div><br><div class=3D"gmail_quote">So this is the &quot=
;library&quot; solution wrapping a capturing lambda in a class and also all=
owing the lambda to be recursive.</div><div class=3D"gmail_quote"><br></div=
><div class=3D"gmail_quote">I can&#39;t see how a language extension somewh=
at like &quot;[]

class=20



(){}&quot; to the already existing and very useful &quot;[](){}&quot; would=
=20
create much &quot;friction with the existing C++ grammar. How would it?</di=
v><div class=3D"gmail_quote"><br></div><br><div class=3D"gmail_quote">Then =
you could also define classes quickly that have members/captures without re=
peating their name thrice, greatly improving DRY.</div><div class=3D"gmail_=
quote"><br></div><div class=3D"gmail_quote">Sure, details are not worked ou=
t, but it is a good idea to work on.<br></div><div class=3D"gmail_quote"><b=
r></div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAD_7Vbks-oT0%3DRFiaPFn304iHY07J6LygU=
fCCRjv-kpd7yhKGw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAD_7Vbks-oT0%3=
DRFiaPFn304iHY07J6LygUfCCRjv-kpd7yhKGw%40mail.gmail.com</a>.<br />

--000000000000ada57305795e77f1--

.