Skip to content

Instantly share code, notes, and snippets.

@loliGothicK
Last active March 13, 2017 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loliGothicK/2d40c8214e8fa34f109322ac9f4eab0a to your computer and use it in GitHub Desktop.
Save loliGothicK/2d40c8214e8fa34f109322ac9f4eab0a to your computer and use it in GitHub Desktop.
#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