Last active
March 13, 2017 17:35
-
-
Save loliGothicK/2d40c8214e8fa34f109322ac9f4eab0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <tuple> | |
#include <string> | |
#include <iostream> | |
#include <iomanip> | |
class Person { | |
std::string first_name_; | |
std::string last_name_; | |
int age_; | |
public: | |
Person() = default; | |
Person(const Person&) = default; | |
Person(Person&&) = default; | |
Person(std::string a, std::string b, int c) : first_name_{a}, last_name_{b}, age_{c} {} | |
std::string first_name() const { return first_name_; } | |
std::string last_name() const { return last_name_; } | |
int age() const { return age_; } | |
}; | |
bool operator<(const Person& x, const Person& y) | |
{ | |
// OK!forward_as_tupleがいいかんじに束縛してくれる! | |
return std::forward_as_tuple(x.last_name(), x.first_name(), x.age()) < std::forward_as_tuple(y.last_name(), y.first_name(), y.age()); | |
} | |
int main(){ | |
Person a = { "Y", "W", 21 }; | |
Person b = { "G", "W", 21 }; | |
std::cout << std::boolalpha << (a < b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment