Mastering C++20: The Spaceship or Three-Way Comparison Operator

Опубликовано: 18 Май 2026
на канале: MyCodingDays
499
15

🔍 Dive into the world of spaceship operator (the game-changing three-way comparison operator) in C++! In this video, I'll cover:
Why do we need the three-way comparison operator?
What does spaceship operator return?
How does the defaulted spaceship operator work?
How to define our own spaceship operator?

I will go through these topics using practical examples.

I have used CMake and GoogleTest for the examples.

Source code is available.

Learn how to streamline your code and make comparisons a breeze. 💡

Timestamps:
00:00 Intro
00:32 Problem
02:17 Defaulted 🚀 Operator
06:31 What does it return?
13:55 Non-defaulted 🚀 Operator
16:41 Source Code of Examples
17:12 Ending

📁 Explore the example codes discussed in this video on my GitHub repository.

🔗 GitHub Repository: https://github.com/mrezabayat/cpp20-s...

👍 Don't forget to like, subscribe, and hit the notification bell for more in-depth C++ tutorials!

🌐 Visit our website for more resources and articles on C++ programming: https://mycodingdays.com/

📌 Topics Covered:

Motivation for Spaceship Operator
Significance of Spaceship Operator
Defaulted three-way comparison
Defining our own definition of the three-way comparison
Understanding Return Types of three-way comparison
Real-world Application with Practical Examples

Do you have questions or suggestions for future videos? Drop a comment below! 👇

Happy coding! 🚀💻