CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: ::std

  1. #1
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    ::std

    Quote 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.

  2. #2
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    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

  3. #3
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: ::std

    Quote Originally Posted by JohnW@Wessex View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: ::std

    Quote Originally Posted by monarch_dodra
    Besides, are you even allowed to do that?
    Yes, you are.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: ::std

    Thanks for your answers.
    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
  •  





Click Here to Expand Forum to Full Width

Featured