Use operator overloading best practices.

Not all files covered.

Refer to StackOverflow for details: http://stackoverflow.com/a/4421719
This commit is contained in:
Jason Felds
2014-11-26 14:51:21 -05:00
parent 1a51b06934
commit 3451b2f2d5
10 changed files with 218 additions and 97 deletions
+21 -6
View File
@@ -51,14 +51,29 @@ struct DeviceButtonPair
InputDevice device;
DeviceButton button;
DeviceButtonPair( InputDevice d, DeviceButton b ): device(d), button(b){ }
bool operator<( const DeviceButtonPair &other ) const
{
if( device != other.device )
return device < other.device;
return button < other.button;
}
};
inline bool operator<(DeviceButtonPair const &lhs, DeviceButtonPair const &rhs)
{
if (lhs.device != rhs.device)
{
return lhs.device < rhs.device;
}
return lhs.button < rhs.button;
}
inline bool operator>(DeviceButtonPair const &lhs, DeviceButtonPair const &rhs)
{
return operator<(rhs, lhs);
}
inline bool operator<=(DeviceButtonPair const &lhs, DeviceButtonPair const &rhs)
{
return !operator<(rhs, lhs);
}
inline bool operator>=(DeviceButtonPair const &lhs, DeviceButtonPair const &rhs)
{
return !operator<(lhs, rhs);
}
namespace
{
/* Maintain a set of all interesting buttons: buttons which are being held