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.

1952 questions
428
votes
30 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
  • 41,098
  • 25
  • 141
  • 183
291
votes
2 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
  • 86,754
  • 39
  • 223
  • 453
235
votes
4 answers

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

While I was trying to learn about C++ operators, I stumbled upon a strange comparison operator on cppreference.com,* in a table that looked like this: "Well, if these are common operators in C++, I better learn them", I thought. But all my attempts…
q-l-p
  • 3,262
  • 3
  • 12
  • 32
177
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
  • 247,587
  • 26
  • 487
  • 819
117
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
  • 8,891
  • 4
  • 17
  • 29
107
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
  • 10,085
  • 3
  • 26
  • 56
105
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
  • 328,274
  • 43
  • 416
  • 565
105
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
  • 179,402
  • 46
  • 391
  • 527
105
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,515
  • 1
  • 9
  • 17
104
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,175
  • 1
  • 19
  • 24
96
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
  • 5,990
  • 1
  • 31
  • 58
74
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,201
  • 5
  • 17
70
votes
2 answers

Why don't I need to specify "typename" before a dependent type in C++20?

This bit of code compiled in C++20 (using gcc 10.1) without using the typename keyword before the dependent type std::vector::iterator. Why does it compile? #include template std::vector::iterator // Why does this not…
Jake Schmidt
  • 1,171
  • 5
  • 14
69
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
  • 1,744
  • 1
  • 6
  • 23
66
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…
Armin Montigny
  • 7,879
  • 3
  • 11
  • 29
1
2 3
99 100