From 052c3d80bfe51253d2e74e8d6bdb294397bb7128 Mon Sep 17 00:00:00 2001 From: Anthony Calandra Date: Sat, 12 Oct 2024 20:31:31 -0400 Subject: [PATCH] Support for __VA_OPT__. --- CPP20.md | 9 +++++++++ README.md | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/CPP20.md b/CPP20.md index a32fa03..764c770 100644 --- a/CPP20.md +++ b/CPP20.md @@ -19,6 +19,7 @@ C++20 includes the following new language features: - [lambda capture of parameter pack](#lambda-capture-of-parameter-pack) - [char8_t](#char8_t) - [constinit](#constinit) +- [__VA_OPT__](#__VA_OPT__) C++20 includes the following new library features: - [concepts library](#concepts-library) @@ -446,6 +447,14 @@ constinit const char* c = f(true); // OK constinit const char* d = g(false); // ERROR: `g` is not constexpr, so `d` cannot be evaluated at compile-time. ``` +### `__VA_OPT__` +Helps support variadic macros by evaluating to the given argument if the variadic macro is non-empty. +```c++ +#define F(...) f(0 __VA_OPT__(,) __VA_ARGS__) +F(a, b, c) // replaced by f(0, a, b, c) +F() // replaced by f(0) +``` + ## C++20 Library Features ### Concepts library diff --git a/README.md b/README.md index b7ced0a..143d01f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ C++20 includes the following new language features: - [lambda capture of parameter pack](#lambda-capture-of-parameter-pack) - [char8_t](#char8_t) - [constinit](#constinit) +- [__VA_OPT__](#__VA_OPT__) C++20 includes the following new library features: - [concepts library](#concepts-library) @@ -549,6 +550,14 @@ constinit const char* c = f(true); // OK constinit const char* d = g(false); // ERROR: `g` is not constexpr, so `d` cannot be evaluated at compile-time. ``` +### `__VA_OPT__` +Helps support variadic macros by evaluating to the given argument if the variadic macro is non-empty. +```c++ +#define F(...) f(0 __VA_OPT__(,) __VA_ARGS__) +F(a, b, c) // replaced by f(0, a, b, c) +F() // replaced by f(0) +``` + ## C++20 Library Features ### Concepts library