How to include library feature macros like __cpp_lib_* if importing std only?

Jul 15, 2024 at 10:29pm
the library feature macros __cpp_lib_* are defined in header yvals_core.h (for visual C++) which is an implementation header and thus not meant to be included in cross platform libraries... So how can we obtain these macros in 3rd party library code that uses the standard library via

 
import std;


?



Last edited on Jul 15, 2024 at 10:30pm
Jul 16, 2024 at 2:43am
You do realize C++ code can still #include headers even with imports?
Jul 16, 2024 at 7:01am
And you only need to include one header.

#include <version>

https://en.cppreference.com/w/cpp/header/version
Including <version> also defines all library feature-test macros.
Last edited on Jul 16, 2024 at 7:01am
Jul 16, 2024 at 5:27pm
Yes I know I can #include
Thanks!
Jul 27, 2024 at 7:34pm
Even though <version> was added to C++20 it isn't automatically added when using C++23's import std; or import std.compat; It has to be manually imported/#included to get access to the macros.

1
2
3
4
5
6
7
import std;
import <version>;

int main( )
{
   std::cout << __cpp_lib_any << '\n';
}


Compiles with nary a problem with VS 2022 as long as the C++ language standard is set to latest.
Topic archived. No new replies allowed.