Real-World Example 1

Understand real-world applications of projections and comparison operators.

We will end this chapter by examining two examples where std::tuple, std::tie() and some template metaprogramming can help us write clean and efficient code.

Example 1: projections and comparison operators

The need to implement comparison operators for classes dramatically decreased with C++20, but there are still cases where we need to provide a custom comparison function when we want to sort objects in some custom order for a specific scenario. Consider the following class:

Get hands-on with 1400+ tech skills courses.