Topic: ADL using-declaration for subobject initializer scope
Author: David Krauss <potswa@gmail.com>
Date: Mon, 14 Jul 2014 13:27:23 +0800
Raw View
--Apple-Mail=_503C8B4A-3C49-4B6B-952A-B16E4700381B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1
Standard library functions that work with primitive types, but also may be =
found by ADL for user-defined types, should be found through a using std::f=
oo; declaration. The most familiar one is swap, but most of <cmath> also ap=
plies. (<math.h> provides a retro workaround, by putting the names into the=
global namespace, but that's not a nice thing for a C++ library to do.)
How should such a declaration be provided for a mem-initializer or brace-or=
-equal-initializer? The best option I see is a wrapper function around each=
standard library name.
It would be nice if a using-declaration at class scope referring to a names=
pace member had this effect. Class scope is usually for interface specifica=
tion, but potential confusion could be mitigated by requiring the declarati=
on to have private access qualification.
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail=_503C8B4A-3C49-4B6B-952A-B16E4700381B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;">Standard library funct=
ions that work with primitive types, but also may be found by ADL for user-=
defined types, should be found through a <font face=3D"Courier">using std::=
foo;</font> declaration. The most familiar one is <font face=3D"Courier">sw=
ap</font>, but most of <font face=3D"Courier"><cmath></font> also app=
lies. (<font face=3D"Courier"><math.h></font> provides a retro workar=
ound, by putting the names into the global namespace, but that’s not =
a nice thing for a C++ library to do.)<div><br></div><div>How should such a=
declaration be provided for a <i>mem-initializer</i> or <i>brace-or-equal-=
initializer</i>? The best option I see is a wrapper function around each st=
andard library name.</div><div><br></div><div>It would be nice if a using-d=
eclaration at class scope referring to a namespace member had this effect. =
Class scope is usually for interface specification, but potential confusion=
could be mitigated by requiring the declaration to have private access qua=
lification.</div><div><br></div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail=_503C8B4A-3C49-4B6B-952A-B16E4700381B--
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Mon, 14 Jul 2014 16:10:21 -0700 (PDT)
Raw View
Is using an immediate lambda not an option? The syntax is reasonably terse (apart from the return keyword) and clearly delineates the scope of the using-declaration.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: David Krauss <potswa@gmail.com>
Date: Tue, 15 Jul 2014 08:19:55 +0800
Raw View
--Apple-Mail=_324C1EB9-A7C2-4544-8330-B4897BFB59DE
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1
On 2014-07-15, at 7:10 AM, Edward Catmur <ed@catmur.co.uk> wrote:
> Is using an immediate lambda not an option? The syntax is reasonably ters=
e (apart from the return keyword) and clearly delineates the scope of the u=
sing-declaration.=20
I think that yesterday I felt the immediate lambda to be too verbose, but n=
ow I'm more ambivalent. It's subjective.
Often there are particular globals, free functions, or namespaces that most=
members of a particular class will import by using. The class scope declar=
ation, restricted to private, would probably be a good way to express such =
a relationship between implementation modules.
Also, it's generally nice when things behave the same regardless of context=
, and I don't see any other meaning that such a using declaration could hav=
e. These reasons are weak, though, and I never mentioned how name lookup wo=
uld actually be adjusted. It doesn't all add up to a proposal yet.
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail=_324C1EB9-A7C2-4544-8330-B4897BFB59DE
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;07–15, at 7:10 AM, Edward Catmur <<a href=3D"mailto:ed@catmu=
r.co.uk">ed@catmur.co.uk</a>> wrote:</div><br class=3D"Apple-interchange=
-newline"><blockquote type=3D"cite">Is using an immediate lambda not an opt=
ion? The syntax is reasonably terse (apart from the return keyword) and cle=
arly delineates the scope of the using-declaration. <br></blockquote></div>=
<br><div>I think that yesterday I felt the immediate lambda to be too verbo=
se, but now I’m more ambivalent. It’s subjective.</div><div><br=
></div><div>Often there are particular globals, free functions, or namespac=
es that most members of a particular class will import by <font face=3D"Cou=
rier">using</font>. The class scope declaration, restricted to <font face=
=3D"Courier">private</font>, would probably be a good way to express such a=
relationship between implementation modules.</div><div><br></div><div>Also=
, it’s generally nice when things behave the same regardless of conte=
xt, and I don’t see any other meaning that such a using declaration c=
ould have. These reasons are weak, though, and I never mentioned how name l=
ookup would actually be adjusted. It doesn’t all add up to a proposal=
yet.</div><div><br></div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail=_324C1EB9-A7C2-4544-8330-B4897BFB59DE--
.
Author: =?UTF-8?Q?David_Rodr=C3=ADguez_Ibeas?= <dibeas@ieee.org>
Date: Mon, 14 Jul 2014 23:45:44 -0400
Raw View
--001a11c2e8f00e5cf104fe333e8c
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
This reflects on what some people believe to be a deeper underlying design
issue in the standard regarding this type of functions: use and extension
interfaces are unnecessarily merged into a single interface.
I am not going to go all the way to propose an alternative (as in a proper
proposal), as in the most common case, 'swap', it is probably too late
already (a couple of standards at least). Still a different approach would
have a user interface 'swap', and an extension point 'swap_impl' (open for
bike shedding):
namespace std {
template <typename T>
void swap(T & lhs, T & rhs) {
swap_impl(lhs,rhs);
}
template <typename T>
void swap_impl(T & lhs, T & rhs) {
// default implementation goes here
}
}
Then user code can provide the extension point easily:
namespace application {
template <typename T>
struct MyType {
T value; // may be user defined, with or without 'swap_impl',
fundamental=E2=80=A6
friend void swap_impl(MyType & lhs, MyType & rhs) {
std::swap(lhs.value, rhs.value);
}
};
}
I am not sure if this type of solution could still be applied to the other
functions that David mentions. I fear that it is a bit late for 'swap' as
user code will be implementing their 'swap' in terms of 'swap'=E2=80=A6
David
On Mon, Jul 14, 2014 at 8:19 PM, David Krauss <potswa@gmail.com> wrote:
>
> On 2014=E2=80=9307=E2=80=9315, at 7:10 AM, Edward Catmur <ed@catmur.co.uk=
> wrote:
>
> Is using an immediate lambda not an option? The syntax is reasonably ters=
e
> (apart from the return keyword) and clearly delineates the scope of the
> using-declaration.
>
>
> I think that yesterday I felt the immediate lambda to be too verbose, but
> now I=E2=80=99m more ambivalent. It=E2=80=99s subjective.
>
> Often there are particular globals, free functions, or namespaces that
> most members of a particular class will import by using. The class scope
> declaration, restricted to private, would probably be a good way to
> express such a relationship between implementation modules.
>
> Also, it=E2=80=99s generally nice when things behave the same regardless =
of
> context, and I don=E2=80=99t see any other meaning that such a using decl=
aration
> could have. These reasons are weak, though, and I never mentioned how nam=
e
> lookup would actually be adjusted. It doesn=E2=80=99t all add up to a pro=
posal yet.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--001a11c2e8f00e5cf104fe333e8c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">This reflects on what some people believe to be a deeper u=
nderlying design issue in the standard regarding this type of functions: us=
e and extension interfaces are unnecessarily merged into a single interface=
..<div>
<br></div><div>I am not going to go all the way to propose an alternative (=
as in a proper proposal), as in the most common case, 'swap', it is=
probably too late already (a couple of standards at least). Still a differ=
ent approach would have a user interface 'swap', and an extension p=
oint 'swap_impl' (open for bike shedding):</div>
<div><br></div><div>namespace std {</div><div>template <typename T></=
div><div>void swap(T & lhs, T & rhs) {</div><div>=C2=A0 =C2=A0 swap=
_impl(lhs,rhs);</div><div>}</div><div>template <typename T></div><div=
>void swap_impl(T & lhs, T & rhs) {</div>
<div>=C2=A0 =C2=A0 // default implementation goes here</div><div>}</div><di=
v>}</div><div><br></div><div>Then user code can provide the extension point=
easily:</div><div><br></div><div>namespace application {</div><div>templat=
e <typename T></div>
<div>struct MyType {</div><div>=C2=A0 =C2=A0T value; =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 // may be user defined, with or without 'swap_impl', fundame=
ntal=E2=80=A6</div><div>=C2=A0 =C2=A0friend void swap_impl(MyType & lhs=
, MyType & rhs) {</div><div>=C2=A0 =C2=A0 =C2=A0 std::swap(lhs.value, r=
hs.value);</div>
<div>=C2=A0 =C2=A0}</div><div>};</div><div>}</div><div><br></div><div>I am =
not sure if this type of solution could still be applied to the other funct=
ions that David mentions. I fear that it is a bit late for 'swap' a=
s user code will be implementing their 'swap' in terms of 'swap=
'=E2=80=A6</div>
<div><br></div><div>=C2=A0 =C2=A0 David</div><div><br></div><div><br></div>=
</div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On Mon,=
Jul 14, 2014 at 8:19 PM, David Krauss <span dir=3D"ltr"><<a href=3D"mai=
lto:potswa@gmail.com" target=3D"_blank">potswa@gmail.com</a>></span> wro=
te:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div style=3D"word-wrap:break-word"><div cla=
ss=3D""><br><div><div>On 2014=E2=80=9307=E2=80=9315, at 7:10 AM, Edward Cat=
mur <<a href=3D"mailto:ed@catmur.co.uk" target=3D"_blank">ed@catmur.co.u=
k</a>> wrote:</div>
<br><blockquote type=3D"cite">Is using an immediate lambda not an option? T=
he syntax is reasonably terse (apart from the return keyword) and clearly d=
elineates the scope of the using-declaration. <br></blockquote></div><br>
</div><div>I think that yesterday I felt the immediate lambda to be too ver=
bose, but now I=E2=80=99m more ambivalent. It=E2=80=99s subjective.</div><d=
iv><br></div><div>Often there are particular globals, free functions, or na=
mespaces that most members of a particular class will import by <font face=
=3D"Courier">using</font>. The class scope declaration, restricted to <font=
face=3D"Courier">private</font>, would probably be a good way to express s=
uch a relationship between implementation modules.</div>
<div><br></div><div>Also, it=E2=80=99s generally nice when things behave th=
e same regardless of context, and I don=E2=80=99t see any other meaning tha=
t such a using declaration could have. These reasons are weak, though, and =
I never mentioned how name lookup would actually be adjusted. It doesn=E2=
=80=99t all add up to a proposal yet.</div>
<div><br></div></div><div class=3D"HOEnZb"><div class=3D"h5">
<p></p>
-- <br>
<br>
--- <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" target=3D"_=
blank">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">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>
<p></p>
-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c2e8f00e5cf104fe333e8c--
.
Author: David Krauss <potswa@gmail.com>
Date: Tue, 15 Jul 2014 12:10:00 +0800
Raw View
On 2014-07-15, at 11:45 AM, David Rodr=EDguez Ibeas <dibeas@ieee.org> wrote=
:
> I am not sure if this type of solution could still be applied to the othe=
r functions that David mentions. I fear that it is a bit late for 'swap' as=
user code will be implementing their 'swap' in terms of 'swap'...
It's a best practice for ADL-customizable handles, but that's not a reason =
for the core language not to improve usability of libraries that don't foll=
ow best practices (including the standard library).
Anyway, the cases I described go beyond ADL. Often a class serves as an int=
erface point between two modules, and its members all want to import the sa=
me foreign names. One way to do this currently is to inherit from a detail =
class in a dedicated detail namespace, which contains appropriate using dec=
larations. But that's a fair bit of trouble and it complicates the inherita=
nce hierarchy. (Unnamed and inline namespaces are non-starters because they=
leak internal using declarations.)
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
.