Skip to content

Commit 052c3d8

Browse files
Support for __VA_OPT__.
1 parent 9852478 commit 052c3d8

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CPP20.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ C++20 includes the following new language features:
1919
- [lambda capture of parameter pack](#lambda-capture-of-parameter-pack)
2020
- [char8_t](#char8_t)
2121
- [constinit](#constinit)
22+
- [__VA_OPT__](#__VA_OPT__)
2223

2324
C++20 includes the following new library features:
2425
- [concepts library](#concepts-library)
@@ -446,6 +447,14 @@ constinit const char* c = f(true); // OK
446447
constinit const char* d = g(false); // ERROR: `g` is not constexpr, so `d` cannot be evaluated at compile-time.
447448
```
448449
450+
### `__VA_OPT__`
451+
Helps support variadic macros by evaluating to the given argument if the variadic macro is non-empty.
452+
```c++
453+
#define F(...) f(0 __VA_OPT__(,) __VA_ARGS__)
454+
F(a, b, c) // replaced by f(0, a, b, c)
455+
F() // replaced by f(0)
456+
```
457+
449458
## C++20 Library Features
450459

451460
### Concepts library

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ C++20 includes the following new language features:
1818
- [lambda capture of parameter pack](#lambda-capture-of-parameter-pack)
1919
- [char8_t](#char8_t)
2020
- [constinit](#constinit)
21+
- [__VA_OPT__](#__VA_OPT__)
2122

2223
C++20 includes the following new library features:
2324
- [concepts library](#concepts-library)
@@ -549,6 +550,14 @@ constinit const char* c = f(true); // OK
549550
constinit const char* d = g(false); // ERROR: `g` is not constexpr, so `d` cannot be evaluated at compile-time.
550551
```
551552
553+
### `__VA_OPT__`
554+
Helps support variadic macros by evaluating to the given argument if the variadic macro is non-empty.
555+
```c++
556+
#define F(...) f(0 __VA_OPT__(,) __VA_ARGS__)
557+
F(a, b, c) // replaced by f(0, a, b, c)
558+
F() // replaced by f(0)
559+
```
560+
552561
## C++20 Library Features
553562

554563
### Concepts library

0 commit comments

Comments
 (0)