 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Boris Kolpackov Guest
|
Posted: Tue Jul 13, 2004 2:50 am Post subject: Can a using-declaration name a namespace? |
|
|
Good day,
There is a defect report #406
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#460
that questions whether the following is legal or not (which is
legal according to the standard):
namespace n
{
namespace m
{
}
}
using n::m;
While the defect report does not say what exactly the defect is,
it has the following note:
"Notes from the March 2004 meeting:
We agree that it should be an error."
Can somebody explain to the rest of us why exactly it should be
an error?
thanks,
-boris
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Sandeep Guest
|
Posted: Tue Jul 13, 2004 2:04 pm Post subject: Re: Can a using-declaration name a namespace? |
|
|
[email]boris (AT) kolpackov (DOT) net[/email] (Boris Kolpackov) wrote in message news:<2lgaksFcl1qcU1 (AT) uni-berlin (DOT) de>...
| Quote: | Good day,
There is a defect report #406
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#460
that questions whether the following is legal or not (which is
legal according to the standard):
namespace n
{
namespace m
{
}
}
using n::m;
While the defect report does not say what exactly the defect is,
it has the following note:
"Notes from the March 2004 meeting:
We agree that it should be an error."
Can somebody explain to the rest of us why exactly it should be
an error?
thanks,
-boris
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
Hi,
I am novice to the C++,so if u think i am wrong then plz ignore my
comment.
The question was whether following is legal or not...
| Quote: | namespace n
{
namespace m
{
}
}
using n::m;
|
It is not legal .The problem might be the "namespace" word that we
need to use after "using" .
The legal syntax is
using namespace n::m;
It will work.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Steve Clamage Guest
|
Posted: Fri Jul 16, 2004 1:04 am Post subject: Re: Can a using-declaration name a namespace? |
|
|
Boris Kolpackov wrote:
| Quote: | Good day,
There is a defect report #406
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#460
that questions whether the following is legal or not (which is
legal according to the standard):
namespace n
{
namespace m
{
}
}
using n::m;
While the defect report does not say what exactly the defect is,
it has the following note:
"Notes from the March 2004 meeting:
We agree that it should be an error."
Can somebody explain to the rest of us why exactly it should be
an error?
thanks,
-boris
|
Here's my take on the issue.
To get access to names in namespace foo, you write a using-directive:
using namespace foo;
not a using-declaration:
using foo;
A using-declaration introduces the *name* into the current namespace.
It is not the same as a using-directive.
So in your example, the name "m" from namespace "n" would be
introduced into the global namespace. But "m" is the name of a
namespace, so introducing the name doesn't have any useful effect.
I wasn't present for the discussion of this issue, but I suppose the
idea was to make
using <namespace-name> ;
an error, since it probably is a programmer mistake anyway.
---
Steve Clamage, [email]stephen.clamage (AT) sun (DOT) com[/email]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Fri Jul 16, 2004 3:14 am Post subject: Re: Can a using-declaration name a namespace? |
|
|
[email]stephen.clamage (AT) sun (DOT) com[/email] (Steve Clamage) writes:
| Quote: | Boris Kolpackov wrote:
Good day,
There is a defect report #406
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#460
that questions whether the following is legal or not (which is
legal according to the standard):
namespace n
{
namespace m
{
}
}
using n::m;
While the defect report does not say what exactly the defect is,
it has the following note:
"Notes from the March 2004 meeting:
We agree that it should be an error."
Can somebody explain to the rest of us why exactly it should be an
error?
thanks,
-boris
Here's my take on the issue.
To get access to names in namespace foo, you write a using-directive:
using namespace foo;
not a using-declaration:
using foo;
|
Yes but that is not what Boris presented.
As you recalled in your message, a using-directive does not have the
same effect as a using-declaration. A using-declaration selectively
brings into scope a specific set of declarations. Using-directives on
the other hand profondly modifies the way look-up is done. They are
quite different things and I believe that reducing the issue to that
of using-directives is not right.
The inconsistency, as I understand it from Boris's message, is:
namespace N
{
struct S { };
namespace M { }
}
using N::S; // OK
using N::M; // would be ERROR according to the #406
I must confess I'm confused as to why it should be an error. As far
as I can tell, the effect is to bring the name "M" into scope, not to
dump the declarations in N::M:: into the current scope.
I believe that the resolution of #406 is defective.
| Quote: | A using-declaration introduces the *name* into the current namespace.
It is not the same as a using-directive.
|
Yes, agreed. But Boris does not want using-directive. He wants to
introduces the *name* "m" into the current scope. I see no technical
reason to forbid that.
| Quote: | So in your example, the name "m" from namespace "n" would be
introduced into the global namespace. But "m" is the name of a
namespace, so introducing the name doesn't have any useful effect.
|
Why?
It has the effect that he would just say "m" witthout:
(1) the qualification
(2) without dumping the whole content into the current scope.
| Quote: | I wasn't present for the discussion of this issue, but I suppose the
idea was to make
using <namespace-name> ;
an error, since it probably is a programmer mistake anyway.
|
That might be the idea but I don't find it particularly compelling.
Why would it be likely an error to say
using <namespace-name> ;
and
using <class-name> ;
would not?
I would suggest we trust the programmer and have, simple, general rules.
--
Gabriel Dos Reis
[email]gdr (AT) cs (DOT) tamu.edu[/email]
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Fri Jul 16, 2004 11:25 pm Post subject: Re: Can a using-declaration name a namespace? |
|
|
Gabriel Dos Reis wrote:
| Quote: | stephen.clamage (AT) sun (DOT) com (Steve Clamage) writes:
| Boris Kolpackov wrote:
| > Good day,
| > There is a defect report #406
| > http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#460
| > that questions whether the following is legal or not (which is
| > legal according to the standard):
| > namespace n
| > {
| > namespace m
| > {
| > }
| > }
| > using n::m;
| > While the defect report does not say what exactly the defect is,
| > it has the following note:
| > "Notes from the March 2004 meeting:
| > We agree that it should be an error."
| > Can somebody explain to the rest of us why exactly it should be an
| > error?
| > thanks,
| > -boris
|
| Here's my take on the issue.
|
| To get access to names in namespace foo, you write a using-directive:
| using namespace foo;
| not a using-declaration:
| using foo;
Yes but that is not what Boris presented.
As you recalled in your message, a using-directive does not have the
same effect as a using-declaration. A using-declaration selectively
brings into scope a specific set of declarations. Using-directives on
the other hand profondly modifies the way look-up is done. They are
quite different things and I believe that reducing the issue to that
of using-directives is not right.
The inconsistency, as I understand it from Boris's message, is:
namespace N
{
struct S { };
namespace M { }
}
using N::S; // OK
using N::M; // would be ERROR according to the #406
I must confess I'm confused as to why it should be an error. As far
as I can tell, the effect is to bring the name "M" into scope, not to
dump the declarations in N::M:: into the current scope.
I believe that the resolution of #406 is defective.
| A using-declaration introduces the *name* into the current namespace.
| It is not the same as a using-directive.
Yes, agreed. But Boris does not want using-directive. He wants to
introduces the *name* "m" into the current scope. I see no technical
reason to forbid that.
|
I believe the name "m" needs classification when it's injected. And
that classification is "either it's a namespace or it isn't". Just
"adding a name" won't work because names of namespaces are treated
differently from names of types and names of objects.
| Quote: |
| So in your example, the name "m" from namespace "n" would be
| introduced into the global namespace. But "m" is the name of a
| namespace, so introducing the name doesn't have any useful effect.
Why?
|
Because it won't.
| Quote: |
It has the effect that he would just say "m" witthout:
(1) the qualification
(2) without dumping the whole content into the current scope.
|
There is already a mechanism in the language to do that. It's called
"namespace aliasing".
| Quote: |
| I wasn't present for the discussion of this issue, but I suppose the
| idea was to make
| using <namespace-name> ;
| an error, since it probably is a programmer mistake anyway.
That might be the idea but I don't find it particularly compelling.
Why would it be likely an error to say
using <namespace-name> ;
and
using <class-name> ;
would not?
I would suggest we trust the programmer and have, simple, general rules.
|
A simple, general rule exists. It basically makes any namespace name
_special_. The name, when declared, is not added to the list of "all
known names", but gets put in a "all known namespaces". So, declaring
a namespace (to introduce its particular name into the set of namespaces
for, say, searching for a name when resolving a qualified name) is
already there:
namespace nm = n::m;
..
Correct me if I am wrong.
Victor
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Boris Kolpackov Guest
|
Posted: Sat Jul 17, 2004 2:42 am Post subject: Re: Can a using-declaration name a namespace? |
|
|
[email]stephen.clamage (AT) sun (DOT) com[/email] (Steve Clamage) writes:
| Quote: | So in your example, the name "m" from namespace "n" would be
introduced into the global namespace. But "m" is the name of a
namespace, so introducing the name doesn't have any useful effect.
|
It is as useful as any other using-declaration -- it brings mentioned
name into a scope which allows me to refer to such a name without any
further qualification:
namespace n
{
namespace m
{
void f ();
}
}
void g ()
{
n::m::f ();
using n::m;
// Now `m' is in the scope so I can use it unqualified.
m::f ();
}
Hope it is clear now.
-boris
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Max Polk Guest
|
Posted: Sat Jul 17, 2004 5:05 am Post subject: Re: Can a using-declaration name a namespace? |
|
|
Gabriel Dos Reis wrote:
| Quote: | namespace N
{
struct S { };
namespace M { }
}
using N::S; // OK
using N::M; // would be ERROR according to the #406
I must confess I'm confused as to why it should be an error. As far
as I can tell, the effect is to bring the name "M" into scope, not to
dump the declarations in N::M:: into the current scope.
....
It has the effect that he would just say "m" witthout:
(1) the qualification
(2) without dumping the whole content into the current scope.
|
Essentially you want to have the effect of saying M::Z instead of N::M::Z
[where Z is in the M namespace], but without bringing S and everything else in
N into the current scope.
This actually presents a problem if there is another namespace M adjacent to
N, as in:
namespace N
{
struct S { };
namespace M
{
struct Z { };
}
}
namespace M
{
struct Z { };
}
M::Z a; // this is not N::M::Z
using N::M; // your suggestion
M::Z b; // ambiguous
If you *were* able to bring the N::M namespace into current scope, M::Z would
then be ambiguous, and it would be *impossible* to refer to the Z inside M
which is in turn not inside N.
You might wish to do this:
::M::Z b; // solved ambiguity?
But you would be preventing somebody from wrapping your header file with all
these definitions inside a namespace to keep it separate from their code:
namespace VENDOR
{
#include "filename.h"
}
You haven't solved the ambiguity because ::M::Z isn't right, it's really
prefixed by VENDOR by whoever is including your code.
Basically you raise an ambiguity impossible to solve.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Sat Jul 17, 2004 7:16 am Post subject: Re: Can a using-declaration name a namespace? |
|
|
[email]ux9i003 (AT) yahoo (DOT) com[/email] (Max Polk) writes:
[...]
| Quote: | This actually presents a problem if there is another namespace M
adjacent to N, as in:
|
That is a non-argument. See below.
| Quote: | namespace N
{
struct S { };
namespace M
{
struct Z { };
}
}
namespace M
{
struct Z { };
}
M::Z a; // this is not N::M::Z
using N::M; // your suggestion
|
That particular configuration would be invalid in similar ways as
namespace N {
struct S { };
};
struct S { };
using N::S;
by general rules.
[...]
| Quote: | Basically you raise an ambiguity impossible to solve.
|
No. See above.
--
Gabriel Dos Reis
[email]gdr (AT) cs (DOT) tamu.edu[/email]
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Seungbeom Kim Guest
|
Posted: Sun Jul 18, 2004 12:10 am Post subject: Re: Can a using-declaration name a namespace? |
|
|
Max Polk wrote:
| Quote: |
This actually presents a problem if there is another namespace M
adjacent to N, as in:
namespace N
{
struct S { };
namespace M
{
struct Z { };
}
}
namespace M
{
struct Z { };
}
M::Z a; // this is not N::M::Z
using N::M; // your suggestion
M::Z b; // ambiguous
[...]
Basically you raise an ambiguity impossible to solve.
|
Is the situation different in any way with M being a name of a type or
an object instead of a namespace? I don't think so. If the possibility
of ambiguity were a problem that prevented us from using-declarations,
we wouldn't be able to use any using-declaration at all, would we?
--
Seungbeom Kim
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Bo Persson Guest
|
Posted: Sun Jul 18, 2004 12:12 am Post subject: Re: Can a using-declaration name a namespace? |
|
|
"Boris Kolpackov" <boris (AT) kolpackov (DOT) net> skrev i meddelandet
news:2lqa97FfrhqbU1 (AT) uni-berlin (DOT) de...
| Quote: | stephen.clamage (AT) sun (DOT) com (Steve Clamage) writes:
So in your example, the name "m" from namespace "n" would be
introduced into the global namespace. But "m" is the name of a
namespace, so introducing the name doesn't have any useful effect.
It is as useful as any other using-declaration -- it brings mentioned
name into a scope which allows me to refer to such a name without any
further qualification:
namespace n
{
namespace m
{
void f ();
}
}
void g ()
{
n::m::f ();
using n::m;
|
But this feature already exists, you just write it:
namespace m = n::m;
| Quote: |
// Now `m' is in the scope so I can use it unqualified.
|
Right!
Bo Persson
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Sun Jul 18, 2004 3:50 am Post subject: Re: Can a using-declaration name a namespace? |
|
|
[email]bop (AT) gmb (DOT) dk[/email] ("Bo Persson") writes:
[...]
| Quote: | namespace n
{
namespace m
{
void f ();
}
}
void g ()
{
n::m::f ();
using n::m;
But this feature already exists,
|
No, it does not.
| Quote: | you just write it:
namespace m = n::m;
|
Then the same reasoning implies that using-declaration that brings in
type-names should be abolished because we have typedef.
namespace N {
struct S { };
};
using N::S; // should be rejected, because it could be
// written typedef N::S S;
--
Gabriel Dos Reis
[email]gdr (AT) cs (DOT) tamu.edu[/email]
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Tue Jul 20, 2004 6:14 pm Post subject: Re: Can a using-declaration name a namespace? |
|
|
Victor Bazarov <v.Abazarov (AT) comAcast (DOT) net> writes:
[...]
| Quote: | The inconsistency, as I understand it from Boris's message, is:
namespace N
{
struct S { };
namespace M { }
}
using N::S; // OK
using N::M; // would be ERROR according to the #406
I must confess I'm confused as to why it should be an error. As far
as I can tell, the effect is to bring the name "M" into scope, not to
dump the declarations in N::M:: into the current scope.
I believe that the resolution of #406 is defective.
| A using-declaration introduces the *name* into the current
namespace.
| It is not the same as a using-directive.
Yes, agreed. But Boris does not want using-directive. He wants to
introduces the *name* "m" into the current scope. I see no technical
reason to forbid that.
I believe the name "m" needs classification when it's injected. And
|
When the name is brought into scope through a using-declaration, it is
not forgetfully done so. That is, by the time the using-declaration
was processed, the compiler looked into the scope named by the
nested-qualifier and determined that effectively "m" is a namespace.
When it bring that name into scope, it annotates it (someway of the
other) as to what it names. That, irrespectively of whether that name
designate a type-name or a fubhar. So the objection you present is not
a valid one.
| Quote: | that classification is "either it's a namespace or it isn't". Just
"adding a name" won't work because names of namespaces are treated
differently from names of types and names of objects.
|
Yes, that but a using-declatation (whether it brings a namespace-name
or a fubhar-name into scope) does not forget about what that name
happens to designate in reality. Nobody is asking that "m" to be
introduced as a symbol in void.
| Quote: | | So in your example, the name "m" from namespace "n" would be
| introduced into the global namespace. But "m" is the name of a
| namespace, so introducing the name doesn't have any useful effect.
Why?
Because it won't.
|
That is untrue, for at least the two useful effects I listed below
| Quote: | It has the effect that he would just say "m" witthout:
(1) the qualification
(2) without dumping the whole content into the current scope.
There is already a mechanism in the language to do that. It's called
"namespace aliasing".
|
So what? Following your logic a using-declaration that names a type
should be banned because we already have a mechanism in the language
to do that, namely typedef. I believe that the coherence of that
reasoning does not resist any serious analyzis.
| Quote: | | I wasn't present for the discussion of this issue, but I suppose
the
| idea was to make
| using <namespace-name> ;
| an error, since it probably is a programmer mistake anyway.
That might be the idea but I don't find it particularly compelling.
Why would it be likely an error to say
using <namespace-name> ;
and
using <class-name> ;
would not?
I would suggest we trust the programmer and have, simple, general
rules.
A simple, general rule exists. It basically makes any namespace name
_special_.
|
No, it does not.
| Quote: | The name, when declared, is not added to the list of "all
known names", but gets put in a "all known namespaces".
|
just as the same is done for class-names, typedef-names or non-type names.
| Quote: | So, declaring
a namespace (to introduce its particular name into the set of namespaces
for, say, searching for a name when resolving a qualified name) is
already there:
namespace nm = n::m;
.
Correct me if I am wrong.
|
Repeat the same for type-names.
--
Gabriel Dos Reis
[email]gdr (AT) cs (DOT) tamu.edu[/email]
Texas A&M University -- Computer Science Department
301, Bright Building -- College Station, TX 77843-3112
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|