I was pretty sure that the compiler is supposed to define __cplusplus such that it indicates which version of the C++ standard is being parsed.
But compiling the following code
#include <iostream>
#include <vector>
int main(int argc, char **argv)
{
  const int cxx_version = __cplusplus;
  std::cout << "C++ version: " << cxx_version << std::endl;
  std::vector<int> v(100, 2);
  int s = 0;
  for(auto i : v) {
    s += i;
  }
  std::cout << "Sum: " << s << std::endl;
  return 0;
}
with
cl cxx11.cpp /Qstd=c++11
or
icl cxx11.cpp /Qstd=c++11
with both Visual Studio 2013 and Intel C++ 16.0 on Windows, produces the unexpected result
C++ version: 199711
Sum: 200
As we can see, the range-based for loop works as expected, but __cplusplus should have been 201102, right?
So my question is three-fold:
- Is /Qstd=c++11the correct way to enable C++ 2011 on Microsoft or Intel compiler on Windows?
- Is __cplusplusthe correct think to check the language version based on the C++ standard? Is there a more reliable alternative for standards-compliant compilers?
- Is there a reliable check for either the Microsoft or Intel compilers in Windows?
