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
541
votes
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++…
oHo
  • 51,447
  • 27
  • 165
  • 200
411
votes
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…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
295
votes
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 cppreference.com updated that page and now contains detailed information…
q-l-p
  • 4,304
  • 3
  • 16
  • 36
215
votes
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…
Barry
  • 286,269
  • 29
  • 621
  • 977
139
votes
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. https://isocpp.org/files/img/wg21-timeline-2017-03.png
Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34
121
votes
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…
A M
  • 14,694
  • 5
  • 19
  • 44
120
votes
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
115
votes
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> { …
sehe
  • 374,641
  • 47
  • 450
  • 633
110
votes
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
110
votes
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…
coder3101
  • 3,920
  • 3
  • 24
  • 28
109
votes
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…
JVApen
  • 11,008
  • 5
  • 31
  • 67
102
votes
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…
anton_rh
  • 8,226
  • 7
  • 45
  • 73
88
votes
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…
Acorn
  • 24,970
  • 5
  • 40
  • 69
88
votes
3 answers

Are stackless C++20 coroutines a problem?

Based on the following it looks like coroutines in C++20 will be stackless. https://en.cppreference.com/w/cpp/language/coroutines 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
87
votes
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…
Annyo
  • 1,387
  • 9
  • 20
1
2 3
99 100