Topic: automatic generation of visitor for variant type
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Fri, 20 May 2016 19:33:20 +0200
Raw View
Le 20/05/2016 =C3=A0 11:28, godefv@gmail.com a =C3=A9crit :
> Consider the following :
>
> ##################
> template<class T>
> concept bool Arithmetic =3D std::is_arithmetic<T>::value;
>
> void f(Arithmetic i){
> /* do something with i */
> }
>
> int main(){
> variant<int, double> my_variant{/* give some value */};
> /*
> * Here is what would be nice (maybe) :
> */
> f(my_variant);
> /*
> * and would be equivalent to
> * apply([](Aritmetic i){return f(i);}, my_variant);
> * assuming the variant type provides an "apply" or "visit" function,=20
> which should be the case.
> */
> }
I believe that the following should work in your case (at least with=20
overloaded sets),
visit(f, my_variant);
which is already more friendly (remove the lambda noise).
Your proposal/idea introduces a dependency of the core language to the=20
library, which is bad. I believe that this introduces complexity that=20
can just be avoided. With a language based variant (the dependency on=20
the library will disappear). I would expect to have pattern matching=20
when language based variants are introduced and so this could expressed=20
also as
inspect (my_variant) { auto a =3D> f(a); }
What would happen if you have in addition the overload
void f(variant<int, double> v){ // (**)
/* do something with v */
}
I guess that
f(my_variant);
should call the variant overload (**).
So I believe that
visit(f, my_variant);
express better the intent and avoids surprises.
Vicente
--=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/d3216698-4fa4-f157-fd61-efb6ab8221bc%40wanadoo.f=
r.
.
Author: godefv@gmail.com
Date: Fri, 20 May 2016 14:33:09 -0700 (PDT)
Raw View
------=_Part_2348_594987708.1463779989957
Content-Type: multipart/alternative;
boundary="----=_Part_2349_405541260.1463779989957"
------=_Part_2349_405541260.1463779989957
Content-Type: text/plain; charset=UTF-8
> I believe that the following should work in your case (at least with
> overloaded sets),
>
> visit(f, my_variant);
>
> which is already more friendly (remove the lambda noise).
>
I don't believe this could work. The lambda is a class with templated
operator() and so can be passed as an argument and used, but "f" is the
name of several functions and is not a valid object to be passed to
anything unless specifying the full prototype of one of these function (I
think).
> Your proposal/idea introduces a dependency of the core language to the
> library, which is bad. I believe that this introduces complexity that
> can just be avoided.
Ah, you are right, I kind of thought of the range for loop as depending on
the STL's begin() functions, but it is actually not a dependency...
I guess we can close this suggestion just with this, thank you for your
answer. Language based variant would be another topic.
--
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/8c4ca7e4-a1a1-4973-8c84-a27cda91fe41%40isocpp.org.
------=_Part_2349_405541260.1463779989957
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">=C2=A0<br><blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">I b=
elieve that the following should work in your case (at least with=20
<br>overloaded sets),
<br>
<br>=C2=A0 =C2=A0 =C2=A0visit(f, my_variant);
<br>
<br>which is already more friendly (remove the lambda noise).
<br></blockquote><div><br>I don't believe this could work. The lambda i=
s a class with templated operator() and so can be passed as an argument and=
used, but "f" is the name of several functions and is not a vali=
d object to be passed to anything unless specifying the full prototype of o=
ne of these function (I think).<br>=C2=A0</div><blockquote class=3D"gmail_q=
uote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pad=
ding-left: 1ex;">Your proposal/idea introduces a dependency of the core lan=
guage to the=20
<br>library, which is bad. I believe that this introduces complexity that=
=20
<br>can just be avoided. </blockquote><div><br>Ah, you are right, I kind of=
thought of the range for loop as depending on the STL's begin() functi=
ons, but it is actually not a dependency...<br>I guess we can close this su=
ggestion just with this, thank you for your answer. Language based variant =
would be another topic.<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/8c4ca7e4-a1a1-4973-8c84-a27cda91fe41%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8c4ca7e4-a1a1-4973-8c84-a27cda91fe41=
%40isocpp.org</a>.<br />
------=_Part_2349_405541260.1463779989957--
------=_Part_2348_594987708.1463779989957--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 21 May 2016 00:00:57 +0200
Raw View
This is a multi-part message in MIME format.
--------------3488A89BC9E5DBA3C665B97F
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 20/05/2016 =C3=A0 23:33, godefv@gmail.com a =C3=A9crit :
>
> I believe that the following should work in your case (at least with
> overloaded sets),
>
> visit(f, my_variant);
>
> which is already more friendly (remove the lambda noise).
>
>
> I don't believe this could work. The lambda is a class with templated=20
> operator() and so can be passed as an argument and used, but "f" is=20
> the name of several functions and is not a valid object to be passed=20
> to anything unless specifying the full prototype of one of these=20
> function (I think).
See Overload sets=20
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0119r1.pdf
Vicente
--=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/d917254e-9234-aa19-d3ea-d128fdf13402%40wanadoo.f=
r.
--------------3488A89BC9E5DBA3C665B97F
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
<div class=3D"moz-cite-prefix">Le 20/05/2016 =C3=A0 23:33, <a class=3D"=
moz-txt-link-abbreviated" href=3D"mailto:godefv@gmail.com">godefv@gmail.com=
</a>
a =C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:8c4ca7e4-a1a1-4973-8c84-a27cda91fe41@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">=C2=A0<br>
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">I
believe that the following should work in your case (at least
with <br>
overloaded sets),
<br>
<br>
=C2=A0 =C2=A0 =C2=A0visit(f, my_variant);
<br>
<br>
which is already more friendly (remove the lambda noise).
<br>
</blockquote>
<div><br>
I don't believe this could work. The lambda is a class with
templated operator() and so can be passed as an argument and
used, but "f" is the name of several functions and is not a
valid object to be passed to anything unless specifying the
full prototype of one of these function (I think).<br>
</div>
</div>
</blockquote>
See Overload sets
<a class=3D"moz-txt-link-freetext" href=3D"http://www.open-std.org/jtc1=
/sc22/wg21/docs/papers/2016/p0119r1.pdf">http://www.open-std.org/jtc1/sc22/=
wg21/docs/papers/2016/p0119r1.pdf</a><br>
<br>
Vicente<br>
</body>
</html>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/d917254e-9234-aa19-d3ea-d128fdf13402%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d917254e-9234-aa19-d3ea-d128fdf13402=
%40wanadoo.fr</a>.<br />
--------------3488A89BC9E5DBA3C665B97F--
.
Author: godefv@gmail.com
Date: Sat, 21 May 2016 03:01:18 -0700 (PDT)
Raw View
------=_Part_89_539990137.1463824878397
Content-Type: multipart/alternative;
boundary="----=_Part_90_1519021050.1463824878397"
------=_Part_90_1519021050.1463824878397
Content-Type: text/plain; charset=UTF-8
>
> See Overload sets
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0119r1.pdf
>
> Vicente
>
Oh ok, this proposal would allow to do it indeed, and the runtime cost of
visitation is not hidden.
--
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/c75b7609-c20c-4d02-a3ef-f8539ac5acd3%40isocpp.org.
------=_Part_90_1519021050.1463824878397
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div bgcolor=3D"#FFFFF=
F" text=3D"#000000"><blockquote type=3D"cite"><div dir=3D"ltr">
</div>
</blockquote>
See Overload sets
<a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p011=
9r1.pdf" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'=
;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22=
%2Fwg21%2Fdocs%2Fpapers%2F2016%2Fp0119r1.pdf\x26sa\x3dD\x26sntz\x3d1\x26usg=
\x3dAFQjCNGTe8w7FqrRQRapDHJqwCvyWfkAvQ';return true;" onclick=3D"this.h=
ref=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2Fj=
tc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2016%2Fp0119r1.pdf\x26sa\x3dD\x26sntz\x=
3d1\x26usg\x3dAFQjCNGTe8w7FqrRQRapDHJqwCvyWfkAvQ';return true;">http://=
www.open-std.org/jtc1/<wbr>sc22/wg21/docs/papers/2016/<wbr>p0119r1.pdf</a><=
br>
<br>
Vicente<br></div></blockquote><div><br>Oh ok, this proposal would allow=
to do it indeed, and the runtime cost of visitation is not hidden. <br></d=
iv></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/c75b7609-c20c-4d02-a3ef-f8539ac5acd3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c75b7609-c20c-4d02-a3ef-f8539ac5acd3=
%40isocpp.org</a>.<br />
------=_Part_90_1519021050.1463824878397--
------=_Part_89_539990137.1463824878397--
.