-
September 24th, 2010, 02:01 AM
#1
::std
Originally Posted by 17.6.1.1 Library contents
3: Whenever a name x defined in the standard library is mentioned, the name x is assumed to be fully qualified as ::std::x, unless explicitly described otherwise. For example, if the Effects section for library function F is described as calling library function G, the function ::std::G is meant.
I was reading the standard, and came across this. I noticed that the std namespace was fully qualified to reference the "global" std namespace. While I realize it is probably overkill to do it in an everyday program ("::std::string myString"), I asked myself this question: Can it even serve a use to fully qualify std? I know the standard makes it illegal to put anything inside the std namespace (except for full template sepcializations), so is there a point?
Can you think of a case where writing ::std would be mandatory?
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
September 24th, 2010, 03:30 AM
#2
Re: ::std
I suppose it may be necessary if someone has created a 'std' namespace within another namespace.
This won't compile without the :: qualifier.
Code:
#include <algorithm>
namespace application
{
namespace std
{
}
}
using namespace application;
int main()
{
int a[10];
::std::distance(&a[0], &a[10]);
}
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
September 24th, 2010, 04:27 AM
#3
Re: ::std
Originally Posted by JohnW@Wessex
I suppose it may be necessary if someone has created a 'std' namespace within another namespace.
This won't compile without the :: qualifier.
Code:
#include <algorithm>
namespace application
{
namespace std
{
}
}
using namespace application;
int main()
{
int a[10];
::std::distance(&a[0], &a[10]);
}
I had thought of that, but that would be the only case right? Besides, are you even allowed to do that?
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
September 24th, 2010, 05:15 AM
#4
Re: ::std
Originally Posted by monarch_dodra
Besides, are you even allowed to do that?
Yes, you are.
-
September 24th, 2010, 07:14 AM
#5
Re: ::std
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|