Topic: Add std::begin and std::end for regular expression iterators
Author: frederik.hertzum@gmail.com
Date: Tue, 20 Feb 2018 00:35:28 -0800 (PST)
Raw View
------=_Part_15160_1828667455.1519115728312
Content-Type: multipart/alternative;
boundary="----=_Part_15161_1583106779.1519115728312"
------=_Part_15161_1583106779.1519115728312
Content-Type: text/plain; charset="UTF-8"
Currently, it is not possible to use extended for-loops with stuff like
std::sregex_iterator, because there is no .begin()/.end() pair and no
std::begin/std::end pair for std::sregex_iterator -- adding an overload for
std::sregex_iterator to the std-namespace is trivial and doing so will
allow using them in extended for-loops.
I'm already doing this in production code and so far, have found no issues
with it.
My implementation is fairly simple: std::begin(std::sregex_iterator&)
returns the argument and std::end(std::sregex_iterator&) return a default
constructed std::sregex_iterator:
namespace std {
auto end(std::sregex_iterator& ) -> std::sregex_iterator& {
static std::sregex_iterator end_of_sequence_iterator;
return end_of_sequence_iterator;
}
auto begin(std::sregex_iterator& b) -> std::sregex_iterator& {
return b;
}
}
--
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/96975ffe-e956-4c04-b8bf-140a6520bfd2%40isocpp.org.
------=_Part_15161_1583106779.1519115728312
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Currently, it is not possible to use extended for-loops wi=
th stuff like std::sregex_iterator, because there is no <font face=3D"couri=
er new, monospace">.begin()</font>/<font face=3D"courier new, monospace">.e=
nd()</font>=C2=A0pair and no <font face=3D"courier new, monospace">std::beg=
in</font>/<font face=3D"courier new, monospace">std::end</font> pair for <f=
ont face=3D"courier new, monospace">std::sregex_iterator</font> -- adding a=
n overload for <font face=3D"courier new, monospace">std::sregex_iterator</=
font> to the <font face=3D"courier new, monospace">std</font>-namespace is =
trivial and doing so will allow using them in extended for-loops.<div><br><=
/div><div>I'm already doing this in production code and so far, have fo=
und no issues with it.</div><div><br></div><div>My implementation is fairly=
simple: <font face=3D"courier new, monospace">std::begin(std::sregex_itera=
tor&)</font> returns the argument and <font face=3D"courier new, monosp=
ace">std::end(std::sregex_iterator&)</font> return a default constructe=
d <font face=3D"courier new, monospace">std::sregex_iterator</font>:</div><=
div><font face=3D"courier new, monospace"><br></font></div><div><div><font =
face=3D"courier new, monospace"><br></font></div><div><font face=3D"courier=
new, monospace">namespace std {</font></div><div><font face=3D"courier new=
, monospace"><span style=3D"white-space:pre"> </span>auto end(std::sregex_i=
terator& ) -> std::sregex_iterator& {</font></div><div><font fac=
e=3D"courier new, monospace"><span style=3D"white-space:pre"> </span>stat=
ic std::sregex_iterator end_of_sequence_iterator;</font></div><div><font fa=
ce=3D"courier new, monospace"><span style=3D"white-space:pre"> </span>ret=
urn end_of_sequence_iterator;</font></div><div><font face=3D"courier new, m=
onospace"><span style=3D"white-space:pre"> </span>}</font></div><div><font =
face=3D"courier new, monospace"><br></font></div><div><font face=3D"courier=
new, monospace"><span style=3D"white-space:pre"> </span>auto begin(std::sr=
egex_iterator& b) -> std::sregex_iterator& {</font></div><div><f=
ont face=3D"courier new, monospace"><span style=3D"white-space:pre"> </spa=
n>return b;</font></div><div><font face=3D"courier new, monospace"><span st=
yle=3D"white-space:pre"> </span>}</font></div><div><font face=3D"courier ne=
w, monospace">}</font></div></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/96975ffe-e956-4c04-b8bf-140a6520bfd2%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/96975ffe-e956-4c04-b8bf-140a6520bfd2=
%40isocpp.org</a>.<br />
------=_Part_15161_1583106779.1519115728312--
------=_Part_15160_1828667455.1519115728312--
.