-
Notifications
You must be signed in to change notification settings - Fork 7
/
inheritable_behaviors.h
52 lines (44 loc) · 1.23 KB
/
inheritable_behaviors.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef INHERITABLE_BEHAVIORS_HPP_IMPL_OSIJFD987
#define INHERITABLE_BEHAVIORS_HPP_IMPL_OSIJFD987
namespace ihb
{
/**
* @ struct relational
* @ brief Comparison operator provider
* Intended to be inherited from, by classes that implement
* "operator<". Provides default (usual) implementations
* of the relational operators : { >, ==, !=, <=, >= }
*
* The operators defined here have weaker precedence in overload resolution
* than the ones already defined in the inheriting structure.
*/
template<typename T>
struct relational
{
friend bool operator> (relational const &lhs, relational const &rhs)
{
return (T const&)rhs < (T const&)lhs;
}
friend bool operator==(relational const &lhs, relational const &rhs)
{
return !((T const&)lhs < (T const&)rhs || (T const&)lhs > (T const&)rhs);
}
friend bool operator!=(relational const &lhs, relational const &rhs)
{
return !((T const&)rhs == (T const&)lhs);
}
friend bool operator<=(relational const &lhs, relational const &rhs)
{
return !((T const&)rhs < (T const&)lhs);
}
friend bool operator>=(relational const &lhs, relational const &rhs)
{
return !((T const&)lhs < (T const&)rhs);
}
protected:
~relational()
{
}
};
}
#endif