I got some code sent to me today, and it's using the std::transform on a std::string to make it all lowercase. The sender had written and compiled the code in Visual Studio 2010:
using namespace std;
string test = "TEST";
transform(test.begin(), test.end(), test.begin(), tolower);
Wheras I compiled it on OSx with GCC and/or Clang, and got compile error, as it involves namespace's clashing.
There is indeed a bunch of answered questions that addresses the global namespace vs local (::tolower vs std::tolower), but this is regarding the fact that this piece of code actually works on VS.
Questions I'd like answers to:
- Why does Visual Studio compile this?
- How come it defaults (?) to the global namespace :: when std:: should take precedence?
- Heres a ideone snippet (with errors): http://ideone.com/qvUAMw
- Heres a ideone snippet (that works) : http://ideone.com/lk0H5d
Note: Im using GCC 4.2 and Clang (425.0.24 LLVM 3.2svn) on OSx Mountain Lion