-
Type: Improvement
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: None
-
Component/s: None
-
Environment:All
mongo/bson/bsontypes.h does 'using namespace std' in header context.
Even though its contained in the mongo namespace, best practice is that names from other namespaces should be namespace qualified in headers, for the following reason:
// From who knows where in my include chain...
class string
; // NOT std::string, global scope
// From mongo headers...
#include <string>
namespace mongo {
using namespace std;
class BSONObjBuilder {
// ...
// ERROR: 'string' ambiguous here!!!
BSONObjBuilder& append(const string& fieldName , BSONObj subObj);
// ...
} // namespace mongo
By 'using namespace std', and using names from the std namespace without qualification, you expose yourself to ambiguity with any global names introduced in other headers that shadow names in namespace std. When integrating the BSON headers (or other client facing headers) into complex existing applications that already integrate many libraries the potential for such conflicts materializing in practice grows considerably.