Questions tagged [c++20]

C++20 is the version of C++ after C++17. This tag should be used (along with the [C++] tag) for questions about C++ features specific to C++20.

C++20 is, the name of the C++ standard that will come after C++17. It builds upon the previous standard, improving the core language and standard library, and adding a few new language features.

The final Working Draft of the Standard is N4860. See more information at the Standard C++ Foundation webpage.

Please tag questions about C++20 with the tag, along with the tag.

4856 questions
32 answers

enum to string in modern C++11 / C++14 / C++17 and future C++20

Contrary to all other similar questions, this question is about using the new C++ features. 2008 c Is there a simple way to convert C++ enum to string? 2008 c Easy way to use variables of enum types as string in C? 2008 c++ How to easily map c++…
  • 51,447
  • 27
  • 165
  • 200
4 answers

What is a "span" and when should I use one?

Recently I've gotten suggestions to use span's in my code, or have seen some answers here on the site which use span's - supposedly some kind of container. But - I can't find anything like that in the C++17 standard library. So what is this…
  • 118,144
  • 57
  • 340
  • 684
6 answers

What is the <=> ("spaceship", three-way comparison) operator in C++?

While I was trying to learn about C++ operators, I stumbled upon the following table that listed a strange comparison operator. What does this <=> operator do? Since 2017 updated that page and now contains detailed information…
  • 4,304
  • 3
  • 16
  • 36
5 answers

Why do we require “requires requires”?

One of the corners of C++20 concepts is that there are certain situations in which you have to write requires requires. For instance, this example from [expr.prim.req]/3: A requires-expression can also be used in a requires-clause ([temp]) as a way…
  • 286,269
  • 29
  • 621
  • 977
3 answers

What are coroutines in C++20?

What are coroutines in c++20? In what ways it is different from "Parallelism2" or/and "Concurrency2" (look into below image)? The below image is from ISOCPP.
Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34
2 answers

What is a niebloid?

With C++20 we can read the term "niebloid" more often now in the cppreference. On SO we can find today 2020/07/16 2 articles mentioning it: First post Second post, talking about customization point objects Google does also not spit out that many…
  • 14,694
  • 5
  • 19
  • 44
2 answers

Why is std::ssize() introduced in C++20?

C++20 introduced the std::ssize() free function as below: template constexpr auto ssize(const C& c) -> std::common_type_t>; A possible…
John Z. Li
  • 1,893
  • 2
  • 12
  • 19
1 answer

C++20 behaviour breaking existing code with equality operator?

I ran into this while debugging this question. I trimmed it down all the way to just using Boost Operators: Compiler Explorer C++17 C++20 #include struct F : boost::totally_ordered1> { …
  • 374,641
  • 47
  • 450
  • 633
1 answer

What is the difference between chrono::month and chrono::months

What is the difference between the C++20 chrono types/values month{7} and months{7}? Isn't it confusing to have two such similar names?
Howard Hinnant
  • 206,506
  • 52
  • 449
  • 577
4 answers

What is the need of template lambda introduced in C++20 when C++14 already has generic lambda?

c++14 introduced generic lambdas that made it possible to write following: auto func = [](auto a, auto b){ return a + b; }; auto Foo = func(2, 5); auto Bar = func("hello", "world"); It is very clear that this generic lambda func works just like…
  • 3,920
  • 3
  • 24
  • 28
2 answers

Does C++20 mandate source code being stored in files?

A slightly strange question, however, if I remember correctly, C++ source code doesn't require a file system to store its files. Having a compiler that scans handwritten papers via a camera would be a conforming implementation. Although practically…
  • 11,008
  • 5
  • 31
  • 67
2 answers

Is using malloc for int undefined behavior until C++20

I was told that the following code has undefined behavior until C++20: int *p = (int*)malloc(sizeof(int)); *p = 10; Is that true? The argument was that the lifetime of the int object is not started before assigning the value to it (P0593R6). To fix…
  • 8,226
  • 7
  • 45
  • 73
2 answers

What is `constinit` in C++20?

constinit is a new keyword and specifier in C++20 which was proposed in P1143. The following example is provided in the standard: const char * g() { return "dynamic initialization"; } constexpr const char * f(bool p) { return p ? "constant…
  • 24,970
  • 5
  • 40
  • 69
3 answers

Are stackless C++20 coroutines a problem?

Based on the following it looks like coroutines in C++20 will be stackless. I'm concerned for many reasons: On embedded systems heap allocation is often not acceptable. When in low level code,…
David Ledger
  • 2,033
  • 1
  • 12
  • 27
3 answers

Will consteval functions allow template parameters dependent on function arguments?

In C++17, this code is illegal: constexpr int foo(int i) { return std::integral_constant::value; } That's because even if foo can be evaluated at compile-time, the compiler still needs to produce the instructions to execute it at…
  • 1,387
  • 9
  • 20
2 3
99 100