Topic: nested namespace declaration
Author: Sean Middleditch <sean.middleditch@gmail.com>
Date: Fri, 19 Jul 2013 16:21:17 -0700 (PDT)
Raw View
------=_Part_1089_14312140.1374276077575
Content-Type: text/plain; charset=ISO-8859-1
We should add a nice namespace shorthand, IMO; see user request for such a
feature at
http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2286601-nested-namespace-declarations
Basic idea is to make
namespace A::B::C {
}
semantically equivalent to
namespace A { namespace B { namespace C {
} } }
in every way (lookup, etc.). Just a shorthand. It is completely identical
and only seeks to avoid excessive bracing and the usual desire of
users/editors to indent each level.
If you declare A::B::C and A or A::B does not exist yet, it is declared.
If any of A, A::B, or A::B::C is an existing non-namespace declaration,
this declaration is invalid. That is, you cannot use this syntax to try to
declare namespaces inside of class scope or the like, or to hide types or
function/variable declarations.
NOT proposing to do this for arbitrary declaration; e.g. the following
would still be illegal:
class A::B::my_class {
};
Maybe the type declaration is useful to have, but I leave that discussion
for another time (it can be added at a later date with no conflict with
this proposal).
--
---
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/.
------=_Part_1089_14312140.1374276077575
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div>We should add a nice namespace shorthand, IMO; see user request for su=
ch a feature at <a href=3D"http://visualstudio.uservoice.com/forums/12=
1579-visual-studio/suggestions/2286601-nested-namespace-declarations">http:=
//visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/228660=
1-nested-namespace-declarations</a></div><div><br></div><div>Basic idea is =
to make</div><div><br></div><div> namespace A::B::C {</div><div=
> }</div><div><br></div><div>semantically equivalent to</div><d=
iv><br></div><div> namespace A { namespace B { namespace C {</d=
iv><div> } } }</div><div><br></div><div>in every way (lookup, e=
tc.). Just a shorthand. It is completely identical and only see=
ks to avoid excessive bracing and the usual desire of users/editors to inde=
nt each level.</div><div><br></div><div>If you declare A::B::C and A or A::=
B does not exist yet, it is declared. If any of A, A::B, or A::B::C i=
s an existing non-namespace declaration, this declaration is invalid.  =
;That is, you cannot use this syntax to try to declare namespaces inside of=
class scope or the like, or to hide types or function/variable declaration=
s.</div><div><br></div><div>NOT proposing to do this for arbitrary declarat=
ion; e.g. the following would still be illegal:</div><div><br></div><div>&n=
bsp; class A::B::my_class {</div><div> };</div><div><br=
></div><div>Maybe the type declaration is useful to have, but I leave that =
discussion for another time (it can be added at a later date with no confli=
ct with this proposal).</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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
------=_Part_1089_14312140.1374276077575--
.
Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Sat, 20 Jul 2013 09:46:33 +0200
Raw View
On Fri, 2013-07-19 at 16:21 -0700, Sean Middleditch wrote:
> We should add a nice namespace shorthand, IMO; see user request for
> such a feature
> at http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2286601-nested-namespace-declarations
The case where I have wished for something like this is only marginally
related to the one described above but in the definition of the partial
specialization below
namespace X { namespace Y {
template <class X, int>
struct foo {
int bar() { return 0; }
};
} }
// Lots of code and then this is in into another file
namespace A { namespace B { namespace C {
// Do something
} // namespace C
} // namespace B
} // namespace A
namespace X { namespace Y {
template <>
int foo<::A::B::C::tag,17>::bar() { return 1; }
} }
namespace A { namespace B { namespace C {
// Do something with ::X::Y::foo::bar
....
it would be very nice to be able to define the partial specialization
of ::X::Y::foo<int,17>::bar() right inside the A::B::C namespace as
follows:
template <>
int ::X::Y::foo<int,17>::bar() { return 1; }
or even as
template <>
int ::namespace X::namespace Y::foo<int,17>::bar() { return 1; }
particularly when I have to do it over and over again intermixed with
other code - getting out of the current namespace and into the one I
need for the specialization and then back to where I need the
specialization gets old rather quickly.
On the other hand I can understand if people balks on how the name
lookup rules should look in this case.
/MF
--
---
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: Jonathan Wakely <cxx@kayari.org>
Date: Mon, 22 Jul 2013 04:33:14 -0700 (PDT)
Raw View
------=_Part_2956_28432213.1374492794259
Content-Type: text/plain; charset=ISO-8859-1
On Saturday, July 20, 2013 12:21:17 AM UTC+1, Sean Middleditch wrote:
>
> We should add a nice namespace shorthand, IMO; see user request for such a
> feature at
> http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2286601-nested-namespace-declarations
>
> Basic idea is to make
>
> namespace A::B::C {
> }
>
> semantically equivalent to
>
> namespace A { namespace B { namespace C {
> } } }
>
> in every way (lookup, etc.). Just a shorthand. It is completely
> identical and only seeks to avoid excessive bracing and the usual desire of
> users/editors to indent each level.
>
> If you declare A::B::C and A or A::B does not exist yet, it is declared.
> If any of A, A::B, or A::B::C is an existing non-namespace declaration,
> this declaration is invalid. That is, you cannot use this syntax to try to
> declare namespaces inside of class scope or the like, or to hide types or
> function/variable declarations.
>
> NOT proposing to do this for arbitrary declaration; e.g. the following
> would still be illegal:
>
> class A::B::my_class {
> };
>
> Maybe the type declaration is useful to have, but I leave that discussion
> for another time (it can be added at a later date with no conflict with
> this proposal).
>
Yes, this gets suggested now and then, but noone's ever written a proposal
AFAICT.
--
---
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/.
------=_Part_2956_28432213.1374492794259
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>On Saturday, July 20, 2013 12:21:17 AM UTC+1, Sean Middleditch wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><div>We should add a nice na=
mespace shorthand, IMO; see user request for such a feature at <a href=
=3D"http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestio=
ns/2286601-nested-namespace-declarations" target=3D"_blank">http://visualst=
udio.<wbr>uservoice.com/forums/121579-<wbr>visual-studio/suggestions/<wbr>2=
286601-nested-namespace-<wbr>declarations</a></div><div><br></div><div>Basi=
c idea is to make</div><div><br></div><div> namespace A::B::C {=
</div><div> }</div><div><br></div><div>semantically equivalent =
to</div><div><br></div><div> namespace A { namespace B { namesp=
ace C {</div><div> } } }</div><div><br></div><div>in every way =
(lookup, etc.). Just a shorthand. It is completely identical an=
d only seeks to avoid excessive bracing and the usual desire of users/edito=
rs to indent each level.</div><div><br></div><div>If you declare A::B::C an=
d A or A::B does not exist yet, it is declared. If any of A, A::B, or=
A::B::C is an existing non-namespace declaration, this declaration is inva=
lid. That is, you cannot use this syntax to try to declare namespaces=
inside of class scope or the like, or to hide types or function/variable d=
eclarations.</div><div><br></div><div>NOT proposing to do this for arbitrar=
y declaration; e.g. the following would still be illegal:</div><div><br></d=
iv><div> class A::B::my_class {</div><div> };</di=
v><div><br></div><div>Maybe the type declaration is useful to have, but I l=
eave that discussion for another time (it can be added at a later date with=
no conflict with this proposal).</div></blockquote><div><br>Yes, this gets=
suggested now and then, but noone's ever written a proposal AFAICT.<br><br=
><br><br> <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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
------=_Part_2956_28432213.1374492794259--
.
Author: Sean Middleditch <sean.middleditch@gmail.com>
Date: Mon, 22 Jul 2013 11:41:15 -0700 (PDT)
Raw View
------=_Part_16_3343134.1374518475059
Content-Type: text/plain; charset=ISO-8859-1
On Saturday, July 20, 2013 12:46:33 AM UTC-7, Magnus Fromreide wrote:
>
>
> it would be very nice to be able to define the partial specialization
> of ::X::Y::foo<int,17>::bar() right inside the A::B::C namespace as
> follows:
>
> template <>
> int ::X::Y::foo<int,17>::bar() { return 1; }
>
> or even as
>
> template <>
> int ::namespace X::namespace Y::foo<int,17>::bar() { return 1; }
>
At least in specialization case the namespaces must already have been
defined for you to have a template to specialize, so a shorthand without
the namespace keyword maybe makes more sense.
Forward declarations are another story.
namespace X { class Y; }
I'm still uncomfortable with idea of
class X::Y;
being legal. Adding in the namespace keyword make it:
namespace X::class Y;
I don't like that, but not for any reasons I can articulate, so it may just
be because it's different and new.
--
---
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/.
------=_Part_16_3343134.1374518475059
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>On Saturday, July 20, 2013 12:46:33 AM UTC-7, Magnus Fromreide wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><br>it would be very nice to=
be able to define the partial specialization
<br>of ::X::Y::foo<int,17>::bar() right inside the A::B::C namespace =
as
<br>follows:
<br>
<br>template <>
<br>int ::X::Y::foo<int,17>::bar() { return 1; }
<br>
<br>or even as
<br>
<br>template <>
<br>int ::namespace X::namespace Y::foo<int,17>::bar() { return 1; }
<br></blockquote><div><br></div><div>At least in specialization case the na=
mespaces must already have been defined for you to have a template to speci=
alize, so a shorthand without the namespace keyword maybe makes more sense.=
</div><div><br></div><div>Forward declarations are another story.</div><div=
> namespace X { class Y; }</div><div>I'm still uncomfortable with ide=
a of<br></div><div> class X::Y;</div><div>being legal. Adding i=
n the namespace keyword make it:</div><div> namespace X::class Y;</di=
v><div>I don't like that, but not for any reasons I can articulate, so it m=
ay just be because it's different and new.</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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
------=_Part_16_3343134.1374518475059--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Mon, 22 Jul 2013 22:14:15 +0300
Raw View
--047d7bdc93967e8d6c04e21e7b37
Content-Type: text/plain; charset=ISO-8859-1
On 22 July 2013 21:41, Sean Middleditch <sean.middleditch@gmail.com> wrote:
> Forward declarations are another story.
> namespace X { class Y; }
> I'm still uncomfortable with idea of
> class X::Y;
> being legal. Adding in the namespace keyword make it:
>
Isn't that already legal?
--
---
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/.
--047d7bdc93967e8d6c04e21e7b37
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 22 July 2013 21:41, Sean Middleditch <span dir=3D"ltr"><<a hr=
ef=3D"mailto:sean.middleditch@gmail.com" target=3D"_blank">sean.middleditch=
@gmail.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Forward declarations are another story.<div>=
=A0 namespace X { class Y; }</div><div>I'm still uncomfortable with ide=
a of<br>
</div><div>=A0 class X::Y;</div><div>being legal. =A0Adding in the namespac=
e keyword make it:</div></blockquote><div><br></div><div>Isn't that alr=
eady legal?<br><br></div></div><br></div></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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
--047d7bdc93967e8d6c04e21e7b37--
.
Author: Sean Middleditch <sean@middleditch.us>
Date: Mon, 22 Jul 2013 12:33:55 -0700
Raw View
On Mon, Jul 22, 2013 at 12:14 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
>
>> Forward declarations are another story.
>> namespace X { class Y; }
>> I'm still uncomfortable with idea of
>> class X::Y;
>> being legal. Adding in the namespace keyword make it:
>
> Isn't that already legal?
The first example, yes, that's what you do today, but not the second.
You can't introduce a definition into a namespace scope without
putting it inside the "namespace X { }" construct. It makes sense to
a degree, as X::Y could be either"
namespace X { class Y; }
or it could be a nested type as in:
struct X { class Y; };
so having X::Y by itself without X being defined already is ambiguous.
Even then, the following is not legal today as I understand (and a
quick test with GCC 4.8 agrees):
namespace X {}
class X::Y; // error: 'Y' in namespace 'X' does not name a type
--
Sean Middleditch
http://seanmiddleditch.com
--
---
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: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Mon, 22 Jul 2013 22:36:53 +0300
Raw View
--089e013cbae86f14c104e21ecc51
Content-Type: text/plain; charset=ISO-8859-1
On 22 July 2013 22:33, Sean Middleditch <sean@middleditch.us> wrote:
> On Mon, Jul 22, 2013 at 12:14 PM, Ville Voutilainen
> <ville.voutilainen@gmail.com> wrote:
> >
> >> Forward declarations are another story.
> >> namespace X { class Y; }
> >> I'm still uncomfortable with idea of
> >> class X::Y;
> >> being legal. Adding in the namespace keyword make it:
> >
> > Isn't that already legal?
>
> The first example, yes, that's what you do today, but not the second.
> You can't introduce a definition into a namespace scope without
> putting it inside the "namespace X { }" construct. It makes sense to
>
Both clang and gcc seem to allow it, as long as the namespace already
contains a previous declaration.
> a degree, as X::Y could be either"
> namespace X { class Y; }
> or it could be a nested type as in:
> struct X { class Y; };
> so having X::Y by itself without X being defined already is ambiguous.
>
Sure, that's different.
> Even then, the following is not legal today as I understand (and a
> quick test with GCC 4.8 agrees):
> namespace X {}
> class X::Y; // error: 'Y' in namespace 'X' does not name a type
>
Yes, you need to declare Y inside X first. This seems legal:
namespace X {class Y;}
class X::Y {};
--
---
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/.
--089e013cbae86f14c104e21ecc51
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 22 July 2013 22:33, Sean Middleditch <span dir=3D"ltr"><<a hr=
ef=3D"mailto:sean@middleditch.us" target=3D"_blank">sean@middleditch.us</a>=
></span> wrote:<br>
<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 class=3D"im">On Mon,=
Jul 22, 2013 at 12:14 PM, Ville Voutilainen<br>
<<a href=3D"mailto:ville.voutilainen@gmail.com">ville.voutilainen@gmail.=
com</a>> wrote:<br>
><br>
>> Forward declarations are another story.<br>
>> =A0 namespace X { class Y; }<br>
>> I'm still uncomfortable with idea of<br>
>> =A0 class X::Y;<br>
>> being legal. =A0Adding in the namespace keyword make it:<br>
><br>
> Isn't that already legal?<br>
<br>
</div>The first example, yes, that's what you do today, but not the sec=
ond.<br>
You can't introduce a definition into a namespace scope without<br>
putting it inside the "namespace X { }" construct. =A0It makes se=
nse to<br></blockquote><div><br></div><div>Both clang and gcc seem to allow=
it, as long as the namespace already<br>contains a previous declaration.<b=
r>
<br>=A0<br></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">
a degree, as X::Y could be either"<br>
=A0 =A0namespace X { class Y; }<br>
or it could be a nested type as in:<br>
=A0 =A0struct X { class Y; };<br>
so having X::Y by itself without X being defined already is ambiguous.<br><=
/blockquote><div><br></div><div>Sure, that's different. <br>=A0<br></di=
v><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;borde=
r-left:1px solid rgb(204,204,204);padding-left:1ex">
=A0Even then, the following is not legal today as I understand (and a<br>
quick test with GCC 4.8 agrees):<br>
=A0 =A0namespace X {}<br>
=A0 =A0class X::Y; // error: 'Y' in namespace 'X' does not =
name a type<br></blockquote><div><br></div><div>Yes, you need to declare Y =
inside X first. This seems legal:<br><br>namespace X {class Y;} <br>class X=
::Y {};<br>
<br></div></div><br></div></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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
--089e013cbae86f14c104e21ecc51--
.
Author: Sean Middleditch <sean@middleditch.us>
Date: Mon, 22 Jul 2013 12:42:24 -0700
Raw View
On Mon, Jul 22, 2013 at 12:36 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> namespace X {class Y;}
> class X::Y {};
Which is not the same thing at all. That is doing a forward
declaration using the current syntax and then defining the class. You
can't forward declare the type outside of the namespace {} bit. I
used the term "definition" where I should have said "forward
declaration" in my previous message; apologies.
--
---
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/.
.