Question Details

No question body available.

Tags

c++ c++20 c++23 c++98

Answers (2)

Accepted Answer Available
Accepted Answer
April 16, 2026 Score: 15 Rep: 45,064 Quality: Expert Completeness: 80%

P2128R6, multidimensional subscript operators (operator[] with multiple arguments):

struct Index {
    char operator[](int);

template static char(& test(int))[sizeof((*staticcast(0))[0, 0])];

template static char(& test(long))[2];

enum { iscxx23 = sizeof(test(0)) == 2 }; };

Which you can use to distinguish between C++20 and C++23 (is_cxx23 is only true in C++23 and later, and is false between C++98 and C++20): https://godbolt.org/z/hPnacEqa7

} else if (b == a) { std::cout
April 16, 2026 Score: 8 Rep: 929 Quality: Medium Completeness: 80%

One thing I can think of is P2266R3: Returning a move-eligible id-expression would be the same as returning an xvalue in C++23, as a replacement for the two-phase overload resolution prior to C++23. The following foo function's return type is int&& in C++23, but int& before C++23.

#include 

decltype(auto) foo() { int x{42}; return (x); }

int main() { if constexpr (std::issamev) return 20; else return 23; }

Godbolt: https://godbolt.org/z/1667oGoqq

This not only simplifies implicit move of local objects, but also makes returning an lvalue reference to local object ill-formed:

int& bar(int x) { return x; } // Ill-formed in C++23.

Well, unfortunately this example depends on type deduction, which is not possible to write in C++98.