In standard library, I found that namespace std is declared as a macro.
#define _STD_BEGIN namespace std {
#define _STD_END }
- Is this a best practice when using namespaces?
- The macro is declared in
Microsoft Visual Studio 9.0\VC\include\yvals.h. But I couldn’t find the STL files including this. If it is not included, how it can be used?
Any thoughts..?
Probably not a best practice as it can be difficult to read compared to a vanilla
namespacedeclaration. That said, remember rules don’t always apply universally, and I’m sure there is some scenario where a macro might clean things up considerably."But I couldn’t find the STL files including this. If it is not included, how it can be used?".
All files that use this macro include
yvals.hsomehow. For example<vector>includes<memory>, which includes<iterator>, which includes<xutility>, which includes<climits>, which includes<yvals.h>. The chain may be deep, but it does include it it some point.And I want to clarify, this only applies to this particular implementation of the standard library; this is in no way standardized.