This sample is licensed under the CC0 Public Domain Dedication.
Implement a lexicographic ordering over class members.
Getting an ordering relation right with 3 elements or more is
tedious and error-prone. Fortunately, the standard library
provides a lexicographic ordering over
std::tuple, which we can utilise.
The less-than operator for
foo defined on lines 10–14 compares the
n first, then
c if the
ns are equal, and finally the
d if both the
cs are equal. To achieve this,
std::tie on line 12 and line 13 to
std::tuples containing references to the members of
the left operand and right operand respectively. The comparison
std::tuples provides a lexicographic ordering over