#ifndef USER_DATA_HPP #define USER_DATA_HPP #include #include // TODO: This is a so-called "POD" (Plain Old Data) type. It's a struct that only contains data members; it is essentially a named tuple. // Define an operator< so it gets sorted by age, then by name length, then by name lexicographically. struct UserData { std::string name; int age; double height; }; // ------------------------------------------------------------------ enum class UserDataComparison { Name, Age, Height }; // TODO: Define the UserDataComparator class so that it compares UserData objects by the field specified in the constructor. class UserDataComparator { public: UserDataComparator(UserDataComparison comparison) {} // TODO: reimplement this constructor bool operator()(const UserData& lhs, const UserData& rhs) const { return false; // TODO: reimplement this function } }; // TODO: what is the meaning of the `inline` keyword here? inline void sort_user_data(std::vector& users, UserDataComparison comparison) { // TODO: sort the users vector using the UserDataComparator } struct dummy_set { // pointers are technically iterators; but do not do this // this dummy set returns iterators representing an empty range (both are the iterator past the end) const UserData* begin() const { return nullptr; } const UserData* end() const { return nullptr; } void emplace(const std::string& name, int age, double height) { // do nothing } void emplace_back(std::string&& name, int age, double height) { // do nothing } }; inline auto set_sorted_by_criterion(UserDataComparison comparison) { // TODO: create a set of UserData objects sorted by the specified criterion return dummy_set{}; } // ------------------------------------------------------------------ #endif // USER_DATA_HPP