C/C++ API Reference
Loading...
Searching...
No Matches
pw_polyfill

Oveview

Main docs: https://pigweed.dev/pw_polyfill.

Macros

#define PW_CONSTEXPR_CPP20   constexpr
 
#define PW_CONSTEVAL   constexpr
 
#define PW_CONSTINIT
 
#define PW_NODISCARD_STR(str)   [[nodiscard(str)]]
 
#define PW_CXX_STANDARD_IS_SUPPORTED(std)    (__cplusplus >= _PW_CXX_STANDARD_##std())
 
#define PW_C_STANDARD_IS_SUPPORTED(std)   (0 >= _PW_C_STANDARD_##std())
 

Macro Definition Documentation

◆ PW_C_STANDARD_IS_SUPPORTED

#define PW_C_STANDARD_IS_SUPPORTED (   std)    (0 >= _PW_C_STANDARD_##std())

Evaluates true if the provided C standard (89, 98, 11, 17, 23) is supported by the compiler. This is a simple alternative to checking the value of the __STDC_VERSION__ macro.

◆ PW_CONSTEVAL

#define PW_CONSTEVAL   constexpr

Mark functions as consteval if supported (C++20), or constexpr if not (C++17).

Use with caution in portable code. Calling a consteval function outside of a constant expression is an error.

◆ PW_CONSTEXPR_CPP20

#define PW_CONSTEXPR_CPP20   constexpr

Mark functions as constexpr if compiling for C++20 or newer. In C++17, PW_CONSTEXPR_CPP20 expands to nothing.

This is primarily used for functions that rely on standard library functions that only became constexpr in C++20 (e.g. std::copy). Use with caution in portable code; if constexpr is required in C++17, use constexpr.

◆ PW_CONSTINIT

#define PW_CONSTINIT
Value:
static_assert(false, \
"PW_CONSTINIT does not yet support this compiler; " \
"implement PW_CONSTINIT for this compiler to use it.");

Declare a variable as constinit. Requires compiler-specific features if constinit is not available.

◆ PW_CXX_STANDARD_IS_SUPPORTED

#define PW_CXX_STANDARD_IS_SUPPORTED (   std)     (__cplusplus >= _PW_CXX_STANDARD_##std())

Evaluates true if the provided C++ standard (98, 11, 14, 17, 20, 23) is supported by the compiler. This is a simple alternative to checking the value of the __cplusplus macro.

◆ PW_NODISCARD_STR

#define PW_NODISCARD_STR (   str)    [[nodiscard(str)]]

Provides [[nodiscard]] with a string literal description, which is only available starting in C++20.