Passing a C-style array to `span`

The question is not why this fails for int[], but why it works for all the other types! Unfortunately, you have fallen prey to ADL which is actually calling std::size instead of the size function you have written. This is because all overloads of your function fail, and so it looks in the namespace of … Read more

C++20 constexpr vector and string not working

Your program is actually ill-formed, though the error may be hard to understand. constexpr allocation support in C++20 is limited – you can only have transient allocation. That is, the allocation has to be completely deallocated by the end of constant evaluation. So you cannot write this: int main() { constexpr std::vector<int> v = {1, … Read more

Why C++20 doesn’t support out-of-order designated initializer?

Yes, the rationale is covered in Annex C (informative) Compatibility specifically [diff.dcl]p10 (emphasis mine): Affected subclause: [dcl.init.aggr] Change: In C++, designated initialization support is restricted compared to the corresponding functionality in C. In C++, designators for non-static data members must be specified in declaration order, designators for array elements and nested designators are not supported, … Read more

How can you detect contiguous iterators, given that there is no std::contiguous_iterator_tag?

Original answer The rationale is given in N4284, which is the adopted version of the contiguous iterators proposal: This paper introduces the term “contiguous iterator” as a refinement of random-access iterator, without introducing a corresponding contiguous_iterator_tag, which was found to break code during the Issaquah discussions of Nevin Liber’s paper N3884 “Contiguous Iterators: A Refinement … Read more

What are the mechanics of coroutines in C++20?

N4775 outlines the proposal for coroutines for C++20. It introduces an number of different ideas. The following is from my blog at https://dwcomputersolutions.net . More info can be found in my other posts. Before we examine our whole Hello World coroutine program, go through the various parts step-by-step. These include: The coroutine Promise The coroutine … Read more

New-expression with consteval constructor in constexpr context

The relevant wording is [expr.const]/13: An expression or conversion is an immediate invocation if it is a potentially-evaluated explicit or implicit invocation of an immediate function and is not in an immediate function context. An immediate invocation shall be a constant expression. Note the words ‘or conversion’ and ‘implicit invocation’ – this seems to imply … Read more

What is std::jthread in c++20?

std::jthread is like std::thread, only without the stupid. See, std::thread‘s destructor would terminate the program if you didn’t join or detach it manually beforehand. This led to tons of bugs, as people would expect it to join on destruction. jthread fixes this; it joins on destruction by default (hence the name: “joining thread”). It also … Read more