πŸ’¬ Reply by flying_gel

2024-11-16 πŸ”„ programmerhumor ┃ RE: GetOffMyLan

Maybe to a non C++ dev, but a lot of C++ is probably incomprehensible to a non C++ dev, just like there are other laguages that are incomprehensible to C++ devs. To me it makes perfect sense as it works just like all the other operator overloads.
auto - let the compiler deduce return type
operator<=> - override the spaceship operator (pretty sure it exists in python too)
(const ClassName&) - compare this class, presumably defined in Class name, with a const reference of type Class name, i.e. its own type.
const - comparison can be made for const objects
= default; - Use the default implementation, which is comparing all the member variables.
An alternate more explicit version, which is actually what people recommend:
auto operator<=>(const ClassName&, const ClassName&) = default;
if I just want to have less than comparison for example I would:
This one makes it explicit that you’re comparing two Class name objects.
if I just want to have less than comparison for example I would:
auto operator<(const ClassName&, const ClassName&) = default;
If I need to compare against another class I could define:
auto operator<(const ClassName&, const OtherClass&)

flying_gel

GetOffMyLan

πŸ”„ programmerhumor

πŸ’¬ Replies

No replies.

────

View parent post

View first post in thread

────

πŸ“‘ Local feed

πŸ•οΈ Communities

πŸ”₯ Hashtags

πŸ”Ž Search posts

πŸ”‘ Sign in

πŸ“Š Status

πŸ›Ÿ Help