this post was submitted on 15 Nov 2024
279 points (92.9% liked)

Programmer Humor

32558 readers
60 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] flying_gel 33 points 1 week ago (13 children)

I do appreciate how newer C++ standards have made these kinds of things a lot easier too.

Define all comparison operators with just one one line using C++20

auto operator<=>(const ClassName&) const = default;

[–] qaz 3 points 1 week ago* (last edited 1 week ago) (1 children)

Is there a way to avoid having to write copy and move twice every time yet?

[–] flying_gel 1 points 1 week ago

You mean copy/move constructor and assignment operator?

Unless you have any special handling the ones generated by the compiler automatically should work just fine. But if you do have to define them for some reason (which is becoming increasingly rare) you would need to define both if you need both copy/move construction and copy/move assignment.

load more comments (11 replies)