-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.cpccDerivedOperators.h
47 lines (33 loc) · 1.4 KB
/
math.cpccDerivedOperators.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
/* *****************************************
* File: math.cpccDerivedOperators.h
* Purpose: Portable (cross-platform), light-weight, help class with templated operators
* *****************************************
* Library: Cross Platform C++ Classes (cpcc)
* Copyright: 2014 StarMessage software.
* License: Free for opensource projects.
* Commercial license for closed source projects.
* Web: http://www.StarMessageSoftware.com
* Download: https://code.google.com/p/cpcc/
* https://github.com/starmessage/cpcc
* email: sales -at- starmessage.info
* *****************************************
*/
/**
Helper class with derived operators: + , -, >= , >, <=
Can be used to complete the operators of classes that only have
the following operators: ==, <, +=, -=, *=, /=
*/
template <class T>
class cpccDerivedOperators
{
friend T operator+(T const& lhs, T const& rhs)
{ T tmp = lhs; tmp += rhs; return tmp; }
friend T operator-(T const& lhs, T const& rhs)
{ T tmp = lhs; tmp -= rhs; return tmp; }
friend inline bool operator>=(T const& lhs, T const& rhs)
{ return !(lhs < rhs); }
friend inline bool operator<=(T const& lhs, T const& rhs)
{ return !(lhs > rhs); }
friend inline bool operator>(T const& lhs, T const& rhs)
{ return (rhs < lhs); }
};