Code:
#include<iosfwd>
#include<algorithm>
class boring
{
int x_;
public:
boring() : x_(0) {}
boring(int x) : x_(x) {}
boring(const boring& rhs) : x_(rhs.x_) {}
boring& operator =(const boring& rhs)
{
boring temp(*this);
std::swap (temp.x_ , rhs.x_);
return *this;
}
boring& operator++() //prefix
{
++x_;
return *this;
}
boring& operator --()
{
--x_;
return *this;
}
const boring operator ++(int) //postfix
{
boring temp(*this);
++(*this); // always implement post in terms of pre
return temp;
}
const boring operator --(int)
{
boring temp(*this);
--(*this);
return temp;
}
const boring operator+( const boring& lhs,const boring& rhs)
{
return boring( lhs.x_ + rhs.x_ );
}
const boring operator -( const boring& lhs, const boring& rhs)
{
return boring( lhs.x_ - rhs.x_ );
}
std::ostream& print( std::ostream& os )const
{
os<<x_;
return os;
}
std::istream& get( std::istream& is)
{
is>>x_;
return is;
}
std::ostream& operator <<( std::ostream& os, const boring& b)
{
return b.print(os);
}
std::istream& operator >>( std::istream& is, boring& b)
{
return b.get(os);
}
};