#include #include #include using namespace std; class Ordinal { public: Ordinal(): ordinal{} {} string to_string() const { if( ordinal.empty() ) { return ""; } stringstream strstream{}; strstream << ordinal[0]; for( auto it{ ++ordinal.cbegin() }; it != ordinal.cend(); ++it ) { strstream << ", " << *it; } return strstream.str(); } Ordinal successor() const { Ordinal successor{}; return ++successor; } Ordinal& operator++() { ordinal.push_back(ordinal.size()); return *this; } Ordinal operator++(int) { Ordinal tmp { *this }; ++(*this); return tmp; } Ordinal operator+(Ordinal const& other) const { Ordinal sum{*this}; for( long unsigned int i{0}; i ordinal; }; ostream& operator<<(ostream& os, Ordinal const& ordinal) { return os << ordinal.to_string(); } int main() { Ordinal zero{}; cout << "0: " << zero << endl; Ordinal const one{zero.successor()}; cout << "1: " << one << endl; // three starts as 0 Ordinal three{}; // increment it to two ++(++three); // copy the current three, thus getting two and then increment three Ordinal two { three++ }; cout << "2: " << zero + two << endl; cout << "2: " << two + zero << endl; cout << "3: " << three << endl; cout << "4: " << two + two << endl; }