Skip to content

Commit 5f41b15

Browse files
authored
Revert xinterpreter.cpp (#350)
1 parent e0946f7 commit 5f41b15

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/xinterpreter.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,31 @@ namespace xcpp
7373
xeus::register_interpreter(this);
7474
}
7575

76-
static std::string get_stdopt(int argc, const char* const* argv)
76+
static std::string get_stdopt()
7777
{
78-
std::string res = "14";
79-
for (int i = 0; i < argc; ++i)
80-
{
81-
std::string arg(argv[i]);
82-
auto pos = arg.find("-std=c++");
83-
if (pos != std::string::npos)
84-
{
85-
res = arg.substr(pos + 8);
86-
break;
87-
}
88-
}
89-
return res;
78+
// We need to find what's the C++ version the interpreter runs with.
79+
const char* code = R"(
80+
int __get_cxx_version () {
81+
#if __cplusplus > 202302L
82+
return 26;
83+
#elif __cplusplus > 202002L
84+
return 23;
85+
#elif __cplusplus > 201703L
86+
return 20;
87+
#elif __cplusplus > 201402L
88+
return 17;
89+
#elif __cplusplus > 201103L || (defined(_WIN32) && _MSC_VER >= 1900)
90+
return 14;
91+
#elif __cplusplus >= 201103L
92+
return 11;
93+
#else
94+
return 0;
95+
#endif
96+
}
97+
__get_cxx_version ()
98+
)";
99+
auto cxx_version = Cpp::Evaluate(code);
100+
return std::to_string(cxx_version);
90101
}
91102

92103
interpreter::interpreter(int argc, const char* const* argv) :
@@ -98,7 +109,7 @@ namespace xcpp
98109
{
99110
//NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic)
100111
createInterpreter(Args(argv ? argv + 1 : argv, argv + argc));
101-
m_version = get_stdopt(argc, argv);
112+
m_version = get_stdopt();
102113
redirect_output();
103114
init_preamble();
104115
init_magic();

0 commit comments

Comments
 (0)