#include <iostream>
#include <iomanip>
#include <list>
#include <string>
using namespace std;
template<class T>
class Member{
private:
T last_n, first_n;
public:
Member(T f, T l) :first_n(f), last_n(l){}
void print();
friend bool operator < (Member& m1, Member& m2){
return m1.last_n < m2.last_n;
}
};
template<class T>
void Member<T>::print(){
cout.setf(ios::left);
cout << setw(15) << last_n << " " << first_n << endl;
}
typedef Member<string> M;
int main(){
list<M> li;
li.push_back(M("Linda", "Smith"));
li.push_back(M("Frost", "Robert"));
li.push_back(M("Alex","Amstrong"));
cout << "Before sorting by last name:
";
cout << "==============================" << endl;
list<M>::iterator it = li.begin();
while (it != li.end()){
(it++)->print();
}
cout << endl;
li.sort();
cout << "After sorting by last name:
";
cout << "==========================" << endl;
it = li.begin();
while (it != li.end()){
(it++)->print();
}
cout << endl;
return 0;
}