How to check if C ++ 2011 is enabled in Microsoft and Intel compilers?

I was sure that the compiler should determine __cplusplusthat it indicates which version of the C ++ standard is being processed.

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;
}

from

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, it produces unexpected results

C++ version: 199711
Sum: 200

As we can see, the forrange-based loop works as expected, but __cplusplusshould have been 201102, right?

So my question is three times:

  • Is the /Qstd=c++11right way to incorporate C ++ 2011 into the Microsoft or Intel compiler on Windows?
  • Is it correct to __cpluspluscheck the language version based on the C ++ standard? Is there a more robust alternative for standards-compliant compilers?
  • Microsoft Intel Windows?
+4

Source: https://habr.com/ru/post/1629109/


All Articles