Topic: comparison operators for std::initializer_list proposal


Author: prithviy@umich.edu
Date: Thu, 24 Jan 2019 21:04:30 -0800 (PST)
Raw View
------=_Part_637_863646852.1548392670625
Content-Type: multipart/alternative;
 boundary="----=_Part_638_700192995.1548392670625"

------=_Part_638_700192995.1548392670625
Content-Type: text/plain; charset="UTF-8"

*std::array*, *std::tuple* and *std::pair* all have *operator<* defined to
compare instances of similar template parameters (element-wise comparison).

Would it be a good idea to implement *operator<* (and >,==,!=) for
*std::initializer_list<T>*?

Implementing such functions will be straightforward and will allow people
to use something more natural in cases where they want to compare two lists
as opposed to having to fallback to algorithms with iterators. These
functions can be marked *constexpr* as well.

Currently, such code will not compile:
[image: Screen Shot 2019-01-23 at 8.27.21 AM.png]

--
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/1c659d00-3828-47cc-83b9-e980e097e3da%40isocpp.org.

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

<div dir=3D"ltr"><i style=3D"font-size: small;"><b>std::array</b></i><span =
style=3D"font-size: small;">,</span><span style=3D"font-size: small;"><font=
 color=3D"#000000"><span style=3D"font-family: system-ui, -apple-system, sy=
stem-ui, &quot;.SFNSText-Regular&quot;, sans-serif; font-size: 13px; white-=
space: pre-wrap;"> <i><b>std::tuple</b></i> and <i><b>std::pair</b></i> all=
 have <i><b>operator&lt;</b></i> defined to compare instances of similar te=
mplate parameters (element-wise comparison). </span></font></span><div styl=
e=3D"font-size: small;"><font color=3D"#000000"><span style=3D"font-family:=
 system-ui, -apple-system, system-ui, &quot;.SFNSText-Regular&quot;, sans-s=
erif; font-size: 13px; white-space: pre-wrap;"><br></span></font></div><div=
 style=3D"font-size: small;"><font color=3D"#000000"><span style=3D"font-fa=
mily: system-ui, -apple-system, system-ui, &quot;.SFNSText-Regular&quot;, s=
ans-serif; font-size: 13px; white-space: pre-wrap;">Would it be a good idea=
 to implement <i><b>operator&lt;</b></i> (and &gt;,=3D=3D,!=3D) for <i><b>s=
td::initializer_list&lt;T&gt;</b></i>? </span></font></div><div style=3D"fo=
nt-size: small;"><font color=3D"#000000"><span style=3D"font-family: system=
-ui, -apple-system, system-ui, &quot;.SFNSText-Regular&quot;, sans-serif; f=
ont-size: 13px; white-space: pre-wrap;"><br></span></font></div><div style=
=3D"font-size: small;"><font color=3D"#000000"><span style=3D"font-family: =
system-ui, -apple-system, system-ui, &quot;.SFNSText-Regular&quot;, sans-se=
rif; font-size: 13px; white-space: pre-wrap;">Implementing such functions w=
ill be straightforward and will allow people to use something more natural =
in cases where they want to compare two lists as opposed to having to fallb=
ack to algorithms with iterators.

These functions can be marked <i><b>constexpr</b></i> as well.</span></font=
></div><div style=3D"font-size: small;"><font color=3D"#000000"><font face=
=3D"system-ui, -apple-system, system-ui, .SFNSText-Regular, sans-serif"><sp=
an style=3D"white-space: pre-wrap;"><br></span></font></font></div><div sty=
le=3D"font-size: small;"><font color=3D"#000000"><font face=3D"system-ui, -=
apple-system, system-ui, .SFNSText-Regular, sans-serif"><span style=3D"whit=
e-space: pre-wrap;">Currently, such code will not compile:<br></span></font=
></font></div><div style=3D"font-size: small;"><img src=3D"https://mail.goo=
gle.com/mail/u/0?ui=3D2&amp;ik=3D03d5a6adab&amp;attid=3D0.1&amp;permmsgid=
=3Dmsg-a:r2165094196123566683&amp;th=3D1687ae7be313d2be&amp;view=3Dfimg&amp=
;sz=3Ds0-l75-ft&amp;attbid=3DANGjdJ_fFTHDx9-5QEWVfcPF9tF5uZIAGCOXhjgBCJORGG=
PZK9pc6jPthltHRcGjmtUMbkZ3fallr8DylALmORhn8HPspzMuQ_OLEZEoU-sUKfdDYN3TS9Mio=
ciaeXo&amp;disp=3Demb&amp;realattid=3Dii_jr983uuq0" alt=3D"Screen Shot 2019=
-01-23 at 8.27.21 AM.png" width=3D"307" height=3D"195" data-image-whitelist=
ed=3D"" class=3D"CToWUd a6T" tabindex=3D"0" style=3D"cursor: pointer; outli=
ne: 0px;"><br></div><div><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/1c659d00-3828-47cc-83b9-e980e097e3da%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1c659d00-3828-47cc-83b9-e980e097e3da=
%40isocpp.org</a>.<br />

------=_Part_638_700192995.1548392670625--

------=_Part_637_863646852.1548392670625--

.