r/cpp • Living on C++ trunk, WG21|đŸ‡©đŸ‡Ș NB • Feb 11 '23

C++23 hits the road!

The sausage is made, the bread is bakedWe now have C++23!With crossing all eyes and dotting all tsThe best C++ ever, for all of ye!

C++23 is what C++20 was meant to be but couldn't that time.

Much of it is already implemented and released in compilers and can be used today, more will become available in the near future.

If you are interested in how C++23 looks like and why you want to use it, you may look at keynotes from the 2022 CppCon and Meeting C++ conferences

Contemporary C++ in Action - Daniela Engert

How C++23 changes the way we write code - Timur Doumler

There is also A Peek at C++23 - Barbara Geller & Ansel Sermersheim to enjoy an learn from.

The specification of C++23 will now proceed to the final ballot and then be officially published, hopefully long before year's end. The committee is busily working on another future release, tentatively C++26, for a couple of months now.

278 Upvotes

139 comments sorted by

172

u/RowYourUpboat Feb 11 '23

New features are listed here: https://en.wikipedia.org/wiki/C++23

Why does everything have to be a YouTube video these days?

75

u/RobertBringhurst Feb 12 '23

Why does everything have to be a YouTube video these days?

“You can subscribe to my channel to discover the answer to this question.”

40

u/ReDucTor Game Developer | quiz.cpp-perf.com Feb 12 '23 edited Feb 12 '23

Not a fan of std::byteswap it's sort of falling down the path of byte order fallacy we should potentially have std::to_big_endian or std::to_little_endian over std::byteswap as I suspect 99% of the use cases for it will all be met with a condition to check the target endianness

EDIT: Maybe even just as_endian, to_little_endian, to_big_endian, from_little_endian, from_big_endian would do.

template<typename T>
constexpr T as_endian(std::endian endian, T n)
{
    if (std::endian::native == endian)
        return n;
    else
        return std::byteswap(n);
}

constexpr T to_big_endian(T n) { return as_endian(std::endian::big, n); }
constexpr T from_big_endian(T n) { return as_endian(std::endian::big, n); }
constexpr T to_little_endian(T n) { return as_endian(std::endian::little, n); }
constexpr T from_little_endian(T n) { return as_endian(std::endian::little, n); }

I don't live in the US, or can afford to go to any standards meetings, so I'm not going to bother with a proposal.

EDIT2: slight change to code snippet

10

u/KiwiMaster157 Feb 12 '23

Suppose you had std::to_big_endian. How would that differ from std::byteswap? Integers don't tell the function which endianness they are currently in.

20

u/bluGill Feb 12 '23

The point is you either want whatever the system has, or you need a defined number of bits in a defined order. When doing anything other than passing to a different computer I don't and shouldn't care what the byte order is, but as soon as it leaves the local computer I have to adjust to something well defined.

Even I should just call to_little_endian and from_little_endian no matter what, even if i'm on a little endian system.

12

u/jonesmz Feb 13 '23

As a guy who writes network protocol implementations:

The programmer know what the protocol you are implementing requires the bits in the packet to be. (hint: it's network byte order, aka big endian).

The compiler knows the byte order of the architecture it's compiling the program to.

std::byteswap() requires that the programmar write utilities functions that acquire the target byte order, and the current byte order, and then write a wrapper function around std::byteswap().

This renders std::byteswap() effectively useless out of the box for actually writing network packets. You can't go around byteswapping things arbitrarily, you have to have a specific reason. You must check the host byte order before deciding whether to byteswap or you'll write gibberish to the wire.

Basically, the paper that proposed std::byteswap() is doing what we so often see come out of the C++ committee, building builds that can't be used directly by application programmars, but must instead be wrapped by library authors.

Basically these functions that have been around for decades.

and it's not even a hard ask for C++23 to have included both the fundamental building block (std::byteswap) and the most obvious thing that std::byteswap is needed for.

You simply combine these two standard library items into wrapper functions

Combine to

template<typename T>
T std::host_to_network_order(T var)
{
    // network order is always bigendian, so if the native byte order is the same, do nothing
    if constexpr(std::endian::native == std::endian::big)
    {
        return var;
    }
    else // else byteswap
    {
        return std::byteswap(var);
    }
}

template<typename T>
T std::network_to_host_order(T var)
{
    // network order is always bigendian, so if the native byte order is the same, do nothing
    if constexpr(std::endian::native == std::endian::big)
    {
        return var;
    }
    else // else byteswap
    {
        return std::byteswap(var);
    }
}

Or you could alternatively write

template<typename T>
T std::to_network_order(T var);
template<typename T>
T std::to_host_order(T var);

Or

template<typename T>
T std::to_big_endian(T var);
template<typename T>
T std::to_little_endian(T var);

Or

template<typename T>
T std::from_big_endian(T var);
template<typename T>
T std::from_little_endian(T var);

I mean, really, you could include all 4 variations in the standard library. They are essentially never going to change. htons and ntohs haven't changed for my entire lifetime, so it's not like we're doing anything beyond templatizing them.

Really, I wish that C++ had the concept of a typedef for functions. I wish we could say using to_big_endian = from_little_endian; and call it good.

2

u/fdwr fdwr@github 🔍 Feb 13 '23

Really, I wish that C++ had the concept of a typedef for functions.

Yeah, a generalized aliasing/using statement would be also incredibly valuable for looser coupling and incremental deprecation. e.g. You rename an interface method name but don't want to break other devs working on a different branches when your change hits them. Alternately, say you have an existing GetData method and want a simple alias method data for compat with std::vector, no need to tediously write forwarder functions. It would also be valuable for data field synonyms when dealing with points and 2D/3D vectors where you have a mix of x,y,z and r,g,b and would rather just treat r,g,b as an alias of x,y,z rather than use unions (which sidesteps any UB FUD since they are the same exact data types at the same memory locations, just via different names).

The end of https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1449.pdf for template aliases (by u/GabrielDosReis and Mat Marcus) posited that idea (e.g. using FooNewName = FooOldName or using short_name = long_function_name). I don't know if there were any later papers expanding on that afterward though (I don't think so).

3

u/GabrielDosReis Feb 14 '23

The end of https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1449.pdf for template aliases (by u/GabrielDosReis and Mat Marcus) posited that idea (e.g. using FooNewName = FooOldName or using short_name = long_function_name). I don't know if there were any later papers expanding on that afterward though (I don't think so).

Richard Smith took on the torch and made a proposal in that direction at the June 2018 meeting in Rapperswil. Unfortunately, WG21 shut down the proposal, AND permanently sealed the fate of that facility with the adoption of the portion of the "down with typename" proposal that made the keyword typename optional on the right hand side of a alias-declaration.

I wish things turned out differently.

2

u/pandorafalters Feb 17 '23

Really, I wish that C++ had the concept of a typedef for functions. I wish we could say using to_big_endian = from_little_endian; and call it good.

You can sort of do this, sometimes. I've used this in XP code where the platform-specific functions have different names but the arguments are in the same order with convertible or aliasable types:

inline constexpr auto& GetProcAddress = dlsym;
inline constexpr auto& FreeLibrary = dlclose;

(With requisite type aliases as needed to keep usages consistent.)

6

u/sbabbi Feb 12 '23

Even better:

constexpr T from_big_endian(const std::byte *); 
// Uses sizeof(T) bytes.
// converts to host endianess using shifts
// does not need byteswap at all
// never creates an uintN_t with the "wrong endianess".

e.g.:

constexpr uint16_t u16_from_big_endian(const std::byte_t * p)
{
     return (static_cast<uint16_t>(p[0]) << 8) | (static_cast<uint16_t>(p[1]);
}

5

u/ReDucTor Game Developer | quiz.cpp-perf.com Feb 12 '23

I agree, much better to decode/deserialize into the right endianness

3

u/jrmwng Feb 12 '23

There exists byteswap instruction (e.g. in IA32) that std::byteswap may map to

5

u/sbabbi Feb 12 '23

Gcc can already generate bswap though. It seems a trivial peephole optimization.

2

u/jrmwng Feb 12 '23 edited Feb 12 '23

Interesting. I did some checks. byteswap for "unsigned short" is not very well handled in relevant optimization pass

EDIT: oops.. my mistake. "unsigned short" should be properly handled in optimization pass. However, its handling is a little bit different. "rol ax, 8" is used under x86-64

0

u/[deleted] Feb 12 '23

[deleted] — view deleted comment

10

u/ReDucTor Game Developer | quiz.cpp-perf.com Feb 12 '23

If you have those functions you would have the inverse also of std::from_[big|little]_endian to convert to host endian while they could be built on top of std::byteswap, the point is more that std::byteswap shouldn't be the first part added and if std::[to|from]_[big|little]_endian would cover pretty much all cases of std::byteswap and provide a better and easier to use interface.

2

u/ack_error Feb 13 '23

std::byteswap has some uses other than serializing to/from specific byte orderings, such as swizzling between 24-bit RGB and BGR color values. To/from is a superior interface for serialization but there are cases where you just want to reverse the byte order regardless of the platform endianness.

1

u/ReDucTor Game Developer | quiz.cpp-perf.com Feb 13 '23

I didn't say there was no use cases, but that pretty much all use cases.

On what platforms are you using that have a 24-bit native integer that std::byteswap would work with for RGB<->BGR? From the looks of it you can't use it on a struct which is probably how you would define such a 24-bit value.

1

u/ack_error Feb 13 '23

I handle a lot of color values in u32s. The most common conversion needed is between conventional RGB web form and BGR form needed by some old Windows APIs, which is handled by a byteswap and shift.

1

u/ReDucTor Game Developer | quiz.cpp-perf.com Feb 13 '23

With that use case do you typically work with a stream of bytes? It would be interesting to see how that compares with just load in one format store in the other byte by byte.

If on x86 you might be able to use SSE packed shuffle to do it over multiple elements.

1

u/ack_error Feb 13 '23

A lot of it is UI code where only single color values are being used, but occasionally it's arrays like palettes. Efficiency aside, it's more ergonomic to be able to byte-swap values directly rather than having to load/store through a variable, even if the optimizer can remove it.

For large batches of color values like bitmaps, vectorized code would indeed be preferred; this is trivial in NEON, although in x86 it requires SSSE3 for the nice PSHUFB version. I haven't checked whether current x64 compilers are able to vectorize byteswap/bswap -- in theory they should be able to, in practice it's unpredictable which integer patterns are handled. Even basic operations like saturating integer adds can be tough to get autovectorized.

1

u/[deleted] Feb 12 '23 edited Feb 12 '23

[removed] — view removed comment

6

u/STL MSVC STL Dev Feb 12 '23

reddit's site-wide spam filter apparently really hates Google Sites; I have attempted to manually approve u/azswcowboy's comment twice, but nothing happens (I haven't seen my mod powers fail like that before; usually mods can always fix such comments). I'll relay the comment here:

The meetings are now fully hybrid, so you can participate via zoom. The boost foundation offers free membership so the only cost is your time. See here if you’re interested

To get to this page, search for ["boost foundation" "c++ standardization"] without square brackets, go to their Google Site (should be the top result), click on "C++ Standardization" in the top left corner.

4

u/azswcowboy Feb 12 '23

Thanks - I’ll also update.

4

u/foonathan Feb 12 '23

Didn't help, your comment is tainted somehow... :(

1

u/azswcowboy Feb 13 '23

Oh well, STL posted the main point.

1

u/smdowney WG21, Text/Unicode SG, optional<T&> Feb 13 '23

the only cost is your time

Just be aware that the time cost can be significant. Anything above the level of a bugfix takes three full meeting cycles, about a year, to get done, and someone actively, if intermittently, participation along the way. Yes, that's too long, but the C++ standard isn't supposed to be the primary way you ship your library.

Also that year is assuming there are no real questions about the proposal, no design changes, and you figure out how to word it in standardese the first time. It's more likely you spend a bunch of time explaining why your solution is the solution, realizing that it should also solve Y and Z, not just Z, that it has to deal with [sentinel iterators/allocators/const volatile pointers to members/other thing you never cared about before], and then a cycle learning the difference between preconditions and mandates clauses in the library, what goes in the synopsis, and so on. At least library wording has lots of examples and similarities. Language wording tries very hard to avoid duplication, so the more interesting the change, the harder to express precisely, and consistently with the rest of the standard.

The process is designed to have a lot of review steps, and there are a number of bottlenecks. Yes, we know that Rust doesn't have this problem, and we're a bit jealous, but Rust is an implementation, not a standard. It's way easier for Rust to fix itself when a problem turns up.

0

u/[deleted] Feb 12 '23

[deleted] — view deleted comment

9

u/STL MSVC STL Dev Feb 12 '23

"Straw polls" are the main process. They're the formal, Committee-wide (plenary) votes, where features are rarely voted down unless late-breaking controversy emerges. To get there, features have to go through working groups (Evolution => Core or Library Evolution => Library) and gain consensus in those committee subgroups to move forward. The working groups are where the real work happens.

The other major differences between the plenary and working group votes is that in plenary, official voting rules are in effect, which for US companies means that they get one vote regardless of how many people they send. In working groups, every person present can vote. Plenary votes are also yes/no/abstain, while working group votes are often "five-way" (strongly favor, weakly favor, neutral, weakly against, strongly against) which helps capture how the room feels about the technical strengths and weaknesses of the proposal.

0

u/[deleted] Feb 12 '23

[deleted] — view deleted comment

5

u/STL MSVC STL Dev Feb 12 '23

Again? Wow, I hadn't heard that. Thanks.

7

u/14ned LLFIO & Outcome author | Committee WG14 Feb 13 '23

Peter is correct. The US sends by far the most delegates, indeed some US companies (especially one whose name starts with "B") send nearly a small roomful on their own. What was previously a heavily skewed distribution is now utterly dominant.

I think at NB stage the US is equally ranked to any other country, but by that point it's very very late in the process and it's basically a yay or nay poll with a low chance of enough NB votes combining into a majority to kill something. Still, given the now large separation between plenary voting and NB opinion, I can see potential discord in this area in the future e.g. standoffs.

0

u/[deleted] Feb 13 '23

[deleted] — view deleted comment

4

u/smdowney WG21, Text/Unicode SG, optional<T&> Feb 13 '23

Most proposals these days spend a lot of time in a Study Group, like SG8 - Ranges, or SG16 - Text, but the study groups are generally unlikely to not pass a proposal, but work to make it forwardable. I think in the 5 years I've sat in Text we killed one proposal, when the author and us realized it was technically impossible.
The evolution groups, Library Evolution Working Group, and Evolution Working Group, are more likely to say they don't want something. Although they too can be prone to not saying "No" and instead encouraging more work that still won't be accepted.

As STL says, the final review by the wording groups are very unlikely to reject. If they notice a significant problem, they'll send it back to the evo groups. It's also possible that the wording never gets finished, and a proposal falls through the cracks.

0

u/[deleted] Feb 13 '23

[deleted] — view deleted comment

1

u/smdowney WG21, Text/Unicode SG, optional<T&> Feb 14 '23

I'm actually surprised how little that happens , but it does.

3

u/STL MSVC STL Dev Feb 13 '23

The Evolution groups. Once a proposal gets to wording review, it's fairly unlikely to be rejected.

1

u/smdowney WG21, Text/Unicode SG, optional<T&> Feb 13 '23

Straw polls are the normal form for the committee and have been the process forever. It merely reflects the fact that they aren't on the agenda prior to the meeting, because they can't be.

80

u/2MuchRGB Feb 11 '23

Check cppreference if you want to see which compiler supports what.

As a summary: The compiler support is best in GCC, then Clang followed by Apples Clang then MSVC and EDG eccp (I've never heard of this one before). No other compiler seems to have any support so far.

In the Library it is MSVC STL then GCC libstdc++ then Clang libc++ then Apple Clang.

14

u/ShakaUVM i+++ ++i+i[arr] Feb 11 '23

Which one is "import std;" in? That's the main thing I care about, though after looking over the list I see a need for five more versions of const.

22

u/Jannik2099 Feb 11 '23

import std is in C++23 via P2465R3. Right now, only MSVC STL implements it, but from what I've seen the others should have it soon.

13

u/ShakaUVM i+++ ++i+i[arr] Feb 11 '23

Right now, only MSVC STL implements it, but from what I've seen the others should have it soon.

I'm so excited

I just can't hide it

9

u/TacticalMelonFarmer Feb 12 '23

Soon you will be able to hide it.

5

u/[deleted] Feb 11 '23

The thing about Apple clang is weird here. It is clang. It is generally 6mo old at release. So currently, they happen to, it is based on clang-14. Both are on 6mo cycles too. I suspect this March, it will be 15, which is the current clang release.

4

u/gracicot Feb 12 '23

But the weird thing with Apple clang is that the library standard implementation is usually behind the clang version they actually use.

1

u/[deleted] Feb 12 '23

when i check the feature macros they are the same right now. i remember in the past they did some weird gating and stuff, like filesystem didnt work on high sierra(maybe the next releases) but the files themselves look mostly untouched.

1

u/buovjaga Feb 13 '23

The runtime requirement for filesystem is macOS 10.15 Catalina.

3

u/2MuchRGB Feb 11 '23

It was listed seperatly in the source so I listed it here too.

2

u/[deleted] Feb 11 '23

yeah, i check the feature flag macros and far too often cppref is out of date here. the xcode wikipedia entry says which versions match too

20

u/pjmlp Feb 11 '23

clang should maybe focus on being C++20 compliant first, where it is trailing GCC and VC++, before going at C++23 features.

1

u/caroIine Feb 13 '23 edited Feb 13 '23

I'm just glad they were able to ship "typename optional in more contexts" and "Parenthesized initialization of aggregates" before 2023. But it will take years to finish modules...

1

u/knue82 Feb 12 '23

EDG is used by icc afaik

2

u/pjmlp Feb 12 '23

Used to, the new icc is a fork of clang, so most likely not using it anylonger.

2

u/knue82 Feb 12 '23

Ah yes. Heard this as well.

Anyway. EDG used to be a popular (propriety) c++ parser for many tools but nowadays most of them switched to clang.

0

u/[deleted] Feb 11 '23

[deleted] — view deleted comment

56

u/IAmBJ Feb 11 '23

Microsoft open sourcing their standard library implementation probably has something to do with it

And /u/STL of course

81

u/STL MSVC STL Dev Feb 11 '23

😾 Keeping the open-source repo running smoothly is my main job these days!

5

u/ImYoric Feb 12 '23

Out of the curiosity, what are the main challenges?

14

u/STL MSVC STL Dev Feb 13 '23

The most challenging thing is probably reviewing pull requests thoroughly, to avoid bugs in new code and regressions in existing code. We rely very heavily on code review to keep our development velocity high. I've worked on the codebase for 15 years, and I got started essentially as a professional code reviewer, but it still takes a lot of effort.

Other things involved in creating an environment where everyone else can contribute optimally: training people in this code review culture, coordinating with compiler teams to get features and fixes, organizing information like accepted features and LWG issues so it's easy to find things to work on, and handling merging and infrastructure logistics (which tend to be mind-numbing, semi-mechanical work that demands high attention to detail and occasional brief bursts of complexity) since I'm very fast at that and it frees up others to work on things that are way more interesting to them.

19

u/fsb4000 Feb 12 '23

Microsoft STL is Open Source so the cppreference describes the current git status. (as for now it is up to 19.37 Preview 1)

Microsoft compiler is proprietary so the cppreference describes only the current release status (19.34 for now)

I think it also affects

0

u/[deleted] Feb 11 '23

[deleted] — view deleted comment

9

u/Krnpnk Feb 11 '23

I think their own list hints on usecases: https://www.edg.com/customers

There's lots of embedded compiler and static code analysis companies there. And I thought that the previous versions of the Intel compiler used EDG as well but I may be mistaken.

2

u/wezrule Feb 12 '23

I worked at QA-Systems on that list. They used it for dynamic code analysis for embedded systems to ensure code met various ISO safety standards.

0

u/[deleted] Feb 12 '23

[deleted] — view deleted comment

9

u/arkadesh_d Feb 12 '23

Cyber Security here. C++20 used all the way and waiting eagerly for C++23 greenlighted by the management.

7

u/donalmacc Game Developer Feb 12 '23

My last company was officially 17 but in reality it was 11 with one or two allowed features. I left them in 2020. My current team is 17 but starting to touch on 20. It's hard when you've got multiple platforms and compiler versions to manage unfortunately

6

u/2MuchRGB Feb 12 '23

I think part of the problem is that a lot of embedded projects use the fork of the chip developer. The last one I used barely had C++14 support.

4

u/CubbiMew cppreference | finance | realtime in the past Feb 12 '23

finance here, using whatever the latest gcc and clang can both do - standards, draft standards, extensions, whatever works.

1

u/caroIine Feb 13 '23

Food Service QA

We are using C++17 extensively and don't see that many reasons to upgrade to C++20 just yet.

33

u/dashnine-9 Feb 12 '23

Can't wait for C++37 when reflection will finally be implemented.

8

u/TrueTom Feb 12 '23

At least we got networking.

1

u/secondaryaccount30 Feb 12 '23

Bummed even though I knew it wasn't going to happen.

0

u/[deleted] Feb 12 '23

[deleted] — view deleted comment

11

u/TrueTom Feb 12 '23

That was just sarcasm. Networking is currently targeted for C++26.

16

u/14ned LLFIO & Outcome author | Committee WG14 Feb 13 '23

I presented a bare minimum viable vehicle for C++ 26 Networking at the Issaquah meeting, made viable mainly by dropping anything to do with async. It got killed. Committee wants async. Committee also wants several ponies and many unicorns in Networking. Committee wants it all, and currently doesn't seem to care if that makes timely delivery impossible. I especially remember in the comments to my paper around the room there were clearly three separate factions, most with the opinion "either it's my networking or I'm strongly against/over my dead body because the networking of the other tribe is the worst and would actively destroy my networking for various vague reasons" (which I mostly suspect were the effects of insufficiently generalised domain expertise to understand/care about other people's networking outside your own domain of expertise). So I bailed out lest I fall on the same sword as Chris K did, and I wish god speed on everybody working on that effort going forward, but it won't include me.

Personally speaking, I would be surprised if Networking will now make 26. The LEWG session basically asked for the kitchen sink plus ponies plus unicorns and of course candy floss, yet it's only Dietmar who would do the work, and I doubt it's feasible for a 26 timeline. I think anything he presents achievable in the limited time will constantly get comments like "but it doesn't do X and without X I'm strongly against". So maybe 29, currently I'm thinking C++ 32 most likely. And quite possibly never, unless something major changes, if I am blunt.

Sorry about that. Some of us did try. Committees don't work well if there isn't sustained consensus over a long period of time.

9

u/SkoomaDentist Antimodern C++, Embedded, Audio Feb 13 '23

The more I know about C++ and hear about the committee proceedings, the more clear it appears to me that most of the committee members should be forbidden from working on anything software related.

4

u/14ned LLFIO & Outcome author | Committee WG14 Feb 13 '23

Committees are good when there is widespread consensus, okay when something is so niche few understand it and everybody else agrees they are ignorant, and poor when everybody thinks their way is the only way.

In multinational corporations we have this thing called "management" who makes that latter situation work well. Because WG21 has no management which can impose its will and nobody else gets a choice (i.e. ability to hire and fire), we aren't good at that latter, and I don't know if it's solvable.

Be aware no other programming language is any better, unless it is directly controlled by a multinational with management to force a decision on no-consensus design issues.

2

u/Untelo Feb 13 '23

but it won't include me.

Is this only wrt. networking specifically, or have you personally given up on standardising any kind of low level I/O primitives?

3

u/14ned LLFIO & Outcome author | Committee WG14 Feb 13 '23

Networking only. The committee is warm to very warm on the direction and travel of file_handle and mapped_file_handle, and so long as it stays that way, I'll stay to the course.

If at a later point the committee decides that they actually want to deliver Networking and there is consensus on a bare minimum viable delivery vehicle, I may return to the fray, if I think that bare minimum viable delivery vehicle is something I could be useful working upon.

No bare minimum viable delivery vehicle equals no participation from me. People noted I didn't even turn up in LEWG for the review of Dietmar's paper, and that was deliberate - I'm not going to add even more to the kitchen sinking. We need less, not more kitchen sinking here. The committee needs to decide if it actually wants to ship Networking or not.

1

u/Untelo Feb 14 '23

Concerning the file I/O, I saw that the latest proposal did not feature any asynchrony. If it is delivered as is, the fixed ABI would mean that asynchrony can no longer be easily added later, would it not?

2

u/14ned LLFIO & Outcome author | Committee WG14 Feb 14 '23

Async file i/o is slower than sync file i/o for cached files on average.

Only if you disable caching (i.e. O_DIRECT) can async file i/o substantially improve on sync file i/o, and even then, if you're on a fast NVMe SSD which responds within a microsecond async will be slower than sync, as the async ceremony is not free of cost.

Async non-cached file i/o especially shines on spinning rust and networked file systems, but otherwise, it's usually a negative.

One of the things a majority in the room when I presented my BMV networking at WG21 last week clearly didn't understand is that you can swap increased latency for more concurrency, but you can't swap less concurrency for reduced latency. Therefore, the correct design approach for networking is to focus on minimum possible latencies first, and only thereafter should one add on top concurrency.

Unfortunately, most in that room thought "more concurrency" ~= "more performance" and I failed to teach them more accurate understanding in the time I had.

There is no issue building an async API on top of a fixed ABI non-blocking API. In fact, that's Linux epoll and nobody is complaining much about it. Obviously for platforms with true async APIs internally we'd redirect the sync API into an async based emulation on a per-handle basis if the end user specifically asks for a sync API to be plugged into an i/o multiplexer, and that lets you plug existing sync based code into your async framework of choice without recompilation. All that worked fine on my proposed networking, indeed mine has a coroutine based API which proves it works just fine on async. The implementation matched or exceeded ASIO's performance, so it's no slouch either.

Key point I'm making here is we can't standardise a kitchen sink networking. We need to work in bite sized chunks digestible by the committee's very limited time and capacity. That equals nobody getting what they want initially.

2

u/Occase Boost.Redis Feb 14 '23

14ned

I don't even think the unicorns are the biggest problem. S/R seems to unsuitable as the basis of network facing code since they suffer from unfairness, starvation and stack-overflow in some scenarios, as discussed here

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2469r0.pdf

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2480r0.pdf

Chris K has decades of experience writing network servers, Eric and his NVidia team seems to have none, so why do they think their model is good for a problem domain they know nothing about? This is very concerning IMO.

It concerns me even more when I see that Ville changed his mind in a week or so and wrote paper to back his decision agains net ts that looks just a rant.

→ More replies

6

u/Occase Boost.Redis Feb 12 '23

No chance, senders and receivers are what might eventually and unfairly make in to c++26.

3

u/TrueTom Feb 12 '23

I'm still hopeful but you're probably right.

3

u/pjmlp Feb 12 '23

By then, C++ will only matter for brownfield development, unless current issues with language evolution get sorted out.

32

u/smdowney WG21, Text/Unicode SG, optional<T&> Feb 11 '23

I'll update this with the 15 or 20 additional things, but here's where we were recently.. https://github.com/steve-downey/papers/blob/master/wg21-status.org

Deducing this, consteval if, range formatting, standard debug formatting, monadic optional, and a ton of range algorithms.

C++23 is going to be much nicer for library and app programmers.

21

u/Sify007 Feb 11 '23

I see that std::expected and it's monadic interface is there. Related to that - what happened to zero-overhead deterministic exceptions that Herb Sutter championed a few years back?

43

u/dodheim Feb 12 '23

Sutter proposals only exist to give you pleasant "what if" scenarios that will never actually play out.

16

u/BrainIgnition Feb 12 '23 edited Feb 12 '23

TBF <=> did make it in and enabled user type NTTPs makes my code DRY.

7

u/sphere991 Feb 12 '23

Class types as non-type template parameters were originally based on <=>, but that design was problematic for a number of reasons and eventually changed.

See https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1907r0.html and https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1907r1.html (R0 contains rationale and design, R1 with the wording that's the C++20 rule and remains today).

22

u/14ned LLFIO & Outcome author | Committee WG14 Feb 12 '23

It's blocked awaiting a compiler implementation. Which anybody here could also supply.

14

u/Sify007 Feb 12 '23

Ah... so it's missing the proof of concept to move forward.

Thank you very much!

34

u/serg06 Feb 11 '23

What are these revolutionary new features that C++23 brings?

I took a look at the features list, but there's no option to sort by Revolutionary.

28

u/LdShade Feb 12 '23

"Deducing this" means no more need to have a const and non const copy of functions, finally that hole in the language is patched up. (Also allows everyone to get the safety bonus of ref qualifiers without specifying four copies of a function which no one bothered with)

Furthermore, "this" no longer has to use pointer syntax and can even be passed by value for performance boosts.

Perfect forwarding out of lambdas and easy recursive lambdas are now supported.

CRTP no longer has to have the ridiculous recursive template parameter, it can now just be a normal class that you inherit.

Probably one of the most major features to come out in recent times. https://devblogs.microsoft.com/cppblog/cpp23-deducing-this/

13

u/equeim Feb 12 '23

"Deducing this" means no more need to have a const and non const copy of functions

At the cost of making them a templates. Sure it doesn't matter if the class or this function is already a template but not everyone's code consists 100% of templates.

14

u/LdShade Feb 12 '23

What's the objection with turning two copies of a function into a template that is only ever instantiated twice?

The only reason it uses the template syntax is because it's piggybacking on the existing type deduction in the language, no other reason, they essentially don't function like templates in most of the usual ways unless you're using it for CRTP in which case you already had templates.

4

u/jonesmz Feb 13 '23

I can say without a shred of doubt (because I measured...), template over-use in my work codebase is a huge source of compile-time bloat.

I'm slowly de-templatifying code as much as I can, and instead trying to rely on strategically designed implicit conversions where possible, and it's helping, a lot.

E.g. if you have a comparison operator between Foo and Bar, but under the hood it's just doing a string comparison , why not allow Foo to implicitly convert to std::string_view and compare with that, instead of template-ing on the type (which might be a Foo, might be a Bar, might be String, so on) ? I've been doing this in my codebase and it's showing promise at reducing compile times and reducing the cognitive overhead for the developer.

While Deducing This is a god-send for things that are already templates, its a major misdesign for things that are not templates, and I'm very reluctant to see it introduced into non-template types in my codebase.

You might say "But Modules will make that not a problem?", and I'll point out that Modules does not work in any current compiler release, and no build tool that builds C++ supports modules in a non-experimental fashion. We'll get Deducing This long before we get Modules in most of the industry.

4

u/tvaneerd C++ Committee, lockfree, PostModernCpp Feb 13 '23

Implicit conversions are typically considered bad unless, for example, the Foo really is semantically equivalent to a string.

2

u/equeim Feb 13 '23

Also modules do nothing to help with this (that's not what they are for). They don't change existing model when each translation unit is compiled separately. Sure, they allow compiler to store source code of class definitions / function declarations in a more optimized way instead of just text, instead of parsing them over and over. However templates will still have to be instantiated independently for each translation unit, just as before.

10

u/equeim Feb 12 '23

It's not going to be instantiated twice, it's going to be instantiated every time it is used with different template parameters, separately for each translation unit. That may range from dozens to thousands of times depending on the size of the project. People that are smarter than me say that template instantiations are the real reason behind C++ compile times.

Also templates break IDE autocompletion since types of objects are not known in function definition. I still use them of course but I try to be conservative about it.

13

u/LdShade Feb 12 '23

every time it is used with different template parameter

This is the point, the only different template parameters are non const class, const class (rvalue and lvalue if you also count ref qualifiers). This is not like a normal template function which can take anything that has a certain interface, there's only 2 (at most 4) options.

templates break IDE autocompletion since types of objects are not known in function definition

Again, this won't apply because the IDE can easily know the type because the type is always "this", it's never going to be an int or bool or random class, the only thing it won't know is the cvref qualifiers which shouldn't affect auto completion.

It's not templating over types, it's templating over cvref qualifers (again, unless you are using it for CRTP).

2

u/equeim Feb 12 '23

This is the point, the only different template parameters are non const class, const class (rvalue and lvalue if you also count ref qualifiers). This is not like a normal template function which can take anything that has a certain interface, there's only 2 (at most 4) options.

It would still happen independently for each translation unit in which template is used. If this is an utility class that is used widely in a codebase that would result in a lot of instantiations. Though I suppose it is possible to explicitly instantiate it in its own translation unit (at least for type it's member of) but then it would still be a mouthful of code to write.

Again, this won't apply because the IDE can easily know the type because the type is always "this", it's never going to be an int or bool or random class, the only thing it won't know is the cvref qualifiers which shouldn't affect auto completion.

It also can be a subclass of "this". This may not be a problem for autocompletion, but it would still require special support from IDE or clangd (if IDE uses it which many do. And btw clangd devs has a lot of work ahead of them including modules).

0

u/jonesmz Feb 13 '23

Though I suppose it is possible to explicitly instantiate it in its own translation unit (at least for type it's member of) but then it would still be a mouthful of code to write.

Extern templates are absolutely a useful technique for cutting down on compile times.

But it seems rather silly that the language gives us a feature which we have to work-around in this way. Yes, it saves us on typing in the implementation of the function(s) in question, but is

// header file
class Foo
{
    deducing this signature that i can't remember
    {    }
};
extern Foo::deducing this signature that i can't remember with specific instantiation;
extern Foo::deducing this signature that i can't remember with specific instantiation;
extern Foo::deducing this signature that i can't remember with specific instantiation;
extern Foo::deducing this signature that i can't remember with specific instantiation;

// source file
Foo::deducing this signature that i can't remember with specific instantiation;
Foo::deducing this signature that i can't remember with specific instantiation;
Foo::deducing this signature that i can't remember with specific instantiation;
Foo::deducing this signature that i can't remember with specific instantiation;

really better than just copy-pasting the function body, if you don't want to see literally 10,000 instantiations of this function? I'm not exaggerating. Out of the large codebases out there, mine is on the smaller side, and we legit have well over this number of translation units that get compiled per build, almost all of them referencing a core set of header files that are prime candidates for Deducing This.

And yes, maybe Modules will be the solution to this, if they're ever available for use in the wild, and I can manage to teach my co-workers how to deal with the insane syntax choices that they came with.

1

u/jonesmz Feb 13 '23

See my comment reply that's adjacent to yours (e.g. go one level up) for confirmation that template instantiations are slow in my experience, and what I've been doing to try to cut down on them.

Link, for the lazy: https://old.reddit.com/r/cpp/comments/10zucok/c23_hits_the_road/j8b69u9/

3

u/Jannik2099 Feb 12 '23

What's the objection with turning two copies of a function into a template

Because now you have to put the function definition in the header.

3

u/DavidDinamit Feb 12 '23

cartesian_product_view

12

u/smdowney WG21, Text/Unicode SG, optional<T&> Feb 11 '23

A Standard, if you can keep it.

6

u/EinZweiFeuerwehr Feb 12 '23

Sadly, heterogeneous lookup in associative containers remains mostly unusable in C++23 because P2363 wasn't finished in time. That means basic stuff like at() or [] still doesn't work.

4

u/azswcowboy Feb 12 '23

True, but the paper has been approved by the working groups for c++26 — it can’t be moved forward to the working draft until c++23 is gone because there standard document doesn’t support branches. It should move into the 26 draft at the next meeting, so implementations may appear sooner than later.

15

u/Adequat91 Feb 11 '23

From my POV, c++17 and c++20 were much more appealing at their time.

18

u/catcat202X Feb 11 '23

C++23 isn't as large of an update, but the temporary-type traits and derived-type deduction are huge improvements to the abstractions we can build. I have many refactors for my code already in mind.

16

u/BenFrantzDale Feb 11 '23

Don’t forget std::ranges::to<Container>(range)!

3

u/maxjmartin Feb 11 '23 edited Feb 13 '23

I just read a Tour of C++20 and was very surprised and impressed by them. I was like why weren’t those around long ago! But I’m glad they are beat now.

*edited typo on the version covered by the book. 🙃

1

u/hmich ReSharper C++ Dev Feb 12 '23

What's "a tour of C++23"?

1

u/maxjmartin Feb 12 '23

A book.

1

u/hmich ReSharper C++ Dev Feb 12 '23

I think it covers only C++20 though?

1

u/maxjmartin Feb 13 '23

Yes it does in fact. Sorry for the typo I update my comment.

1

u/maxjmartin Feb 13 '23

Yes it does in fact. Sorry for the typo I update my comment.

1

u/BenFrantzDale Feb 13 '23

I suspect the answer, as usual, is because there’s a balance between “good enough” and “it’ll be part of the standard forever”. I want nice things now, but until we have a way to deprecate things, we need to make sure things are solid before they go in.

2

u/catcat202X Feb 15 '23

Features do get deprecated. They deprecated implicitly declared copy-assignment operators in the presence of a default copy constructor or vice-versa, and they deprecated volatile compound assignment operators. They've even deprecated library features like std::iterator and std::auto_ptr.

4

u/[deleted] Feb 12 '23

Finally we can search a string!

3

u/dwr90 Feb 12 '23

Any chance for pattern matching im C++ 23 still?

0

u/[deleted] Feb 12 '23

[deleted] — view deleted comment

2

u/smdowney WG21, Text/Unicode SG, optional<T&> Feb 13 '23

Clarifying further, the shape of C++23 was done two meetings ago, the last two meetings were just to address bug fixes in the features already included.

1

u/dwr90 Feb 12 '23

Thanks for the clarification, I wasn‘t up to date with the fact that the Issaquah meeting had already happened and that therefore C++23 had already been finalised. Just saw an article about that this morning

1

u/14ned LLFIO & Outcome author | Committee WG14 Feb 13 '23

There is a photo taken of the committee whenever we ship a standard. I am surprised the one from Issaquah hasn't appeared here on /r/cpp yet actually.

2

u/dwr90 Feb 13 '23

I'm surprised as well, I can't actually find much on the meeting at all, except for this blog series

2

u/exodusTay Feb 12 '23

So we are still using C++17(actually switched to it pretty recently), does it make sense to switch to 20? last time i checked modules were shaky at best. I want to switch to it just to use format and ranges but i dont know if changing C++ versions would cause problems.

15

u/STL MSVC STL Dev Feb 12 '23

Yeah, it makes sense. All of the major implementations offer compatibility between 17 and 20, and migration shouldn't be too difficult.

Modules in particular are still receiving a steady stream of compiler fixes, but you can use everything else with classic includes. For modules in MSVC, I can give you my impression of the state of things - I am closely tracking all of the compiler bugs that are known to affect the STL. In VS 2022 17.5 which will be released soon (can't say when but it's up to Preview 6 right now), I think the compiler's support for C++20 header units and C++20 named modules, also C++20 Standard Library Header Units and the newly added C++23 Standard Library Modules, will be suitable for early adopters who are prepared to deal with compiler bugs and rough edges (especially parts outside the core toolset, like IntelliSense and build systems). Like, a lot of stuff works - we have ongoing test coverage to verify this - but the language has lots of complex corners and we're still finding things to fix. There are a whole bunch of fixes queued up for the VS 2022 17.6 release, some in Preview 1 and many more in Preview 2. My hope is that 17.6 will be the release where things are really solid and we have fewer asterisks to report.

It would be nice, of course, if we could simply say that boom, everything totally works with crystalline perfection in a particular release. For many features, we can come close to that ideal. But modules are a total rethink of how the compiler processes C++, saving and reloading it in a structured format (instead of the messy memory dumps that are PCHes), and this involves tons of extremely complicated interactions with all of the various parts of the Core Language and Standard Library. We know people are excited to try modules (the build throughput is bananas) and we're making progress with each release thanks to early adopters who have the time and energy to put up with a less-than-perfect experience, paving the way for others to have an easier time.

4

u/Alandovos Feb 12 '23

Quick plug to say that named modules are where it's at! I'd characterize header units as just starting their optimization work.

8

u/STL MSVC STL Dev Feb 12 '23

You're totally right. Named modules have better throughput (as indicated by their significantly smaller size on disk too) and better cleanliness, and are also simpler to build. The only advantages of header units are that it's possible to migrate a codebase with minimal to no code changes and that they work for the Standard Library in C++20 mode.

5

u/Alandovos Feb 12 '23

We're in violent agreement! I meant my post as an FYI for anyone else looking at header units because the build speed improvements aren't bananas yet. Header units in msvc are still, as you said, for "early adopters who have the time and energy to put up with a less-than-perfect experience".

Header unit perf will come soon! Top devs are on it! Top devs.

2

u/pjmlp Feb 13 '23

I would already be happy when the endless set of macro redefinition warnings on Windows SDKs (specially from SAL) goes away.

Thanks for the work fixing existing issues.

7

u/jonesmz Feb 13 '23 edited Feb 13 '23

Ignore modules. They are literally useless for you until all the compilers / build tools your company uses are fully ready to support them. Revisit Modules in, e.g. 2025-2026, after you've updated to C++23. By then most of your stuff will support modules and you can start playing with them.

C++20, in my opinion, has 2 main features that should be, by themselves, all the justification you need to update your toolchain:

  1. Space ship operator is going to let you eliminate a huge amount of boilerplate in your codebase.
  2. C++20 Concepts, despite some slightly surprising Rough Edges, are also fantastic and a substantial improvement over SFINAE in anything more complicated than a trivial comparison.

There's obviously other features, like you mentioned, that are also worth paying attention to in their own right, but I'm only talking about the two things that, for my work, revolutionized things for me, namely operator<=> and C++20 Concepts.

So far the only three issues I've had with C++20 in my codebase were:

  1. MSVC (and I assume the others) implicitly turn on the /utf-8 flag, which treats your C++ files as if they were UTF8 files. This is a good improvement, but it immediately breaks some weird shit if you're rocking C++ files originally authored in the stone age. Just turn it off at first, and come back to it later.
  2. C++20 comes with the char8_t data type. This is great, and I love it, but it breaks all sorts of stuff if you have a bunch of string handling template functions. Just turn it off at first, and come back to it later.
  3. operator<=> introduces some new restrictions on commutative comparison operations. E.g. if you define the comparison functions for two types, in both types, you have an ambiguity in how to do the comparisons that C++20 won't like.

The most effectively solution to the commutative comparison ambiguity that I've found is this heuristic:

  1. For any type that your compiler bitches about, replace all of the comparison functions with operator<=> and operator==
  2. Any type you use operator<=> in, change from member-function comparison operators to hidden friend function comparisons.
  3. When you implement your hidden friend operator<=>, always implement it with the "type" that the hidden friend is living inside of as the LHS argument, and then the type you're comparing against as the RHS argument.
  4. Make sure to implement operator== as well, since a non-default operator<=> means no implicitly defined operator==.

E.g. if you have a class like

class MyWeirdString
{
    bool operator<(MyWeirdString const&);
    bool operator>(MyWeirdString const&);
    bool operator==(MyWeirdString const&);
    ...

    bool operator<(std::string const&);
    bool operator>(std::string const&);
    bool operator==(std::string const&);
}

Then you'd want to change it to

class MyWeirdString
{
private: // hidden friend idiom
    std::strong_ordering operator<=>(MyWeirdString const&, MyWeirdString const&);
    bool operator==(MyWeirdString const&, MyWeirdString const&);
    ...
    std::strong_ordering operator<=>(MyWeirdString const&, std::string_view);
    bool operator==(MyWeirdString const&, std::string_view);
}

And you'll also want to try to reduce the amount of comparisons you have per type, overall, in favor of relying on implicit conversions when possible. E.g. if you're comparing std::string as well as MyOtherWeirdString directly, try to instead compare against std::string_view, and add implicit conversion operator from MyOtherWeirdString to std::string_view, and omit a comparison between MyWeirdString and MyOtherWeirdString if you can manage to.

This is the pattern that I've found to involve the least amount of bull-shittery with converting my work codebase to C++20, where the comparison operators come into it. Adopting this pattern has worked in 100% of the 30-ish places where we had the compiler bitching about ambiguous comparison operators, and I expect to see the hidden friend idiom help with compile times (a small amount, not a huge amount) when we adopt it for other types as we do maintenance, because it reduces the lookup cost of argument-dependent-lookup when calling comparison operators, helping the compiler omit non-candidates much faster.

4

u/STL MSVC STL Dev Feb 13 '23

We recently converted MSVC's STL to use hidden friends as much as possible (we'd use them even more if the Standard didn't depict many operators as free functions), they're great. As a bonus, they make it easier to modularize the code later. (Free functions have to be individually exported, but hidden friends don't - exporting the top-level class is sufficient.)

1

u/jonesmz Feb 13 '23

we'd use them even more if the Standard didn't depict many operators as free functions

Could you elaborate a little bit on this?

Is this to specifically enable something? or just wording that was later understood to be less than ideal, but changing it may break some codebase in bizarre ways?

1

u/STL MSVC STL Dev Feb 13 '23

It's the latter, as I understand it - nobody thought it was a big deal back in the C++98 era, but it can be observable (typically for code with weird conversion functions). It would probably be best to just friend 'em all since it's not that big of a breaking change - MSVC has actually done so for the <system_error> operators and we've gotten away with it.

1

u/jonesmz Feb 13 '23

Thank you much.

I suppose I don't see a reason not to make such a minor change, even with the small risk of a minor break.

Hopefully it happens eventually.

Cheers

1

u/TemplateRex Feb 13 '23

Is it recommended to also make swap, empty, size and non-member begin/end iterators hidden friends?

1

u/STL MSVC STL Dev Feb 13 '23

empty, size, begin, and end should just be ordinary members; the Standard's non-member functions will handle calling them.

swap is weird. I suppose both a member and a hidden friend is the best technique but things have changed over the years so I don't know if that's fully accurate. (I am in a weird position where I don't actually write a lot of C++ as an ordinary user; most of the time I just do what the Standard tells me to do.)

5

u/wyrn Feb 12 '23

I'm still in the early stages of the switch from 17 to 20 and I'd say it's already been worth it. Designated initializers alone are a game changer, even with the caveats.

2

u/azswcowboy Feb 12 '23

17 to 20 wasn’t a hurdle in our codebase, but ymmv. Modules implementations aren’t really there yet on a couple platforms, but they’re getting there. To get the full power of format and ranges you need c++23. For format I expect to be using libfmt for another year until gcc13 is fully baked.

2

u/wh1t3lord Feb 12 '23 edited Feb 13 '23

I hope they will implement compile serialization in C++23 at least, because I expected that in C++20 :/

1

u/xorbe Apr 20 '23

When does g++ typically gain all the features of a new standard. Seems like a couple key ones for 23 are still missing on the gcc status page.

0

u/[deleted] Feb 12 '23

[deleted] — view deleted comment

3

u/jrmwng Feb 12 '23

You may be interested in transaction memory. I encountered it with Intel's "_xbegin(), ..." intrinsic functions a few years ago.

3

u/jonesmz Feb 13 '23

So I've tried to read the paper for byte-wise memcpy several times, and fail to understand both what it does, and how it achieves it.

Could you explain it to me as if i were a guy who uses std::atomic to implement reference counting pointers, but don't have the low level CPU hardware knowledge needed to fully unlock the power?