-
Notifications
You must be signed in to change notification settings - Fork 0
/
same_unit.hpp
125 lines (97 loc) · 3.15 KB
/
same_unit.hpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//This program (i.e. the unit_lite library) is free software:
//you can redistribute it and/or modify it under the terms of
//the GNU General Public License as published by the Free
//Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with this program. If not, see the two following links
//https://www.gnu.org/licenses/
//https://www.gnu.org/licenses/lgpl-3.0.txt
//This program was written by Pierre Blavy.
//Documentation is available on
//https://tentacule.be/fossil/cpp-msmodels/wiki?name=unit_lite
#ifndef SRC_LIB_UNIT_LITE_SAME_UNIT_HPP_
#define SRC_LIB_UNIT_LITE_SAME_UNIT_HPP_
#include<tuple>
//static type check
namespace unit_lite{
template<typename T, typename U> struct same_unit;
template<typename T, typename U> struct Quantity;
template<typename T, typename U> struct Compose_unit;
namespace impl{
template<typename T, typename U> struct Compose_unit_add;
}
}
namespace unit_lite{
//specialize same_unit for quantities
template<
typename T1, typename R1, typename V1,
typename T2, typename R2, typename V2
>
struct same_unit<
Quantity< Compose_unit<T1,R1>,V1> ,
Quantity< Compose_unit<T2,R2>,V2>
>{
private:
typedef unit_lite::Compose_unit<T1,R1> c1;
typedef unit_lite::Compose_unit<T2,R2> c2;
typedef unit_lite::impl::Compose_unit_add<c1,c2> checker_t;
public:
static constexpr bool value = checker_t::run();
};
//specialize same_unit for Compose_unit
template<typename T1, typename R1, typename T2, typename R2>
struct same_unit<
Compose_unit<T1,R1> ,
Compose_unit<T2,R2>
>{
private:
typedef unit_lite::Compose_unit<T1,R1> c1;
typedef unit_lite::Compose_unit<T2,R2> c2;
typedef unit_lite::impl::Compose_unit_add<c1,c2> checker_t;
public:
static constexpr bool value = checker_t::run();
};
template<>
struct same_unit<
Compose_unit<std::tuple<>,std::tuple<>> ,
Compose_unit<std::tuple<>,std::tuple<>>
>{
static constexpr bool value = true;
};
//specialize for a mix of Compose_unit and Quantity
template<
typename T1, typename R1,
typename T2, typename R2,typename V2>
struct same_unit<
Compose_unit<T1,R1> ,
Quantity< Compose_unit<T2,R2>,V2>
>{
private:
typedef unit_lite::Compose_unit<T1,R1> c1;
typedef unit_lite::Compose_unit<T2,R2> c2;
typedef unit_lite::impl::Compose_unit_add<c1,c2> checker_t;
public:
static constexpr bool value = checker_t::run();
};
//specialize for a mix of Quantity and Compose_unit
template<
typename T1, typename R1,typename V1,
typename T2, typename R2>
struct same_unit<
Quantity< Compose_unit<T1,R1>,V1> ,
Compose_unit<T2,R2>
>{
private:
typedef unit_lite::Compose_unit<T1,R1> c1;
typedef unit_lite::Compose_unit<T2,R2> c2;
typedef unit_lite::impl::Compose_unit_add<c1,c2> checker_t;
public:
static constexpr bool value = checker_t::run();
};
}//end namespace unit_lite
#endif /* SRC_LIB_UNIT_LITE_SAME_UNIT_HPP_ */