c++ - usage of namespaces in libraries -
i'd know if qualifying names in library necessary.
for example (i indent namespaces here readability):
namespace { namespace b { namespace c { class foo { ... }; } // namespace c ::a::b::c::foo foo; // or c::foo foo } // namespace b namespace d { ::a::b::c::foo foo; // or b::c::foo foo } // namespace d } // namespace
i didn't understand 3.4 chapter of c++ standard, , saw can't explain in stl vector header (simplified readability):
namespace std { template<.. class reverse_iterator { ... }; template<.. class vector { typedef _std reverse_iterator<const_iterator> const_reverse_iterator; ... } }
the thing _std expanded ::std:: .. according understanding of name up, reverse_iterator have been looked in vector first in parent namespace std. how collision possible ?
subsidiary question : name lookup rules names in template functions arguments ? think qualified-id directly names declared without adl unqualified name adl, right ?
thank in advance answers.
you're right, qualification appears unnecessary there.
don't try learn c++ standard library code, has written in peculiar style various reasons don't apply you, including backwards compatibility, portability, alternative configurations (e.g. disabling namespaces historical compilers). it's possible in configurations _std
expands different, or it's possible it's redundant (but harmless.)
what name lookup rules names in template functions arguments ? think qualified-id directly names declared without adl unqualified name adl, right ?
yes, adl applies unqualified names.
Comments
Post a Comment