1 | // |
2 | // MetaProgramming.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Core |
6 | // Module: MetaProgramming |
7 | // |
8 | // Common definitions useful for Meta Template Programming |
9 | // |
10 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Foundation_MetaProgramming_INCLUDED |
18 | #define Foundation_MetaProgramming_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | |
23 | |
24 | namespace Poco { |
25 | |
26 | |
27 | template <typename T> |
28 | struct IsReference |
29 | /// Use this struct to determine if a template type is a reference. |
30 | { |
31 | enum |
32 | { |
33 | VALUE = 0 |
34 | }; |
35 | }; |
36 | |
37 | |
38 | template <typename T> |
39 | struct IsReference<T&> |
40 | { |
41 | enum |
42 | { |
43 | VALUE = 1 |
44 | }; |
45 | }; |
46 | |
47 | |
48 | template <typename T> |
49 | struct IsReference<const T&> |
50 | { |
51 | enum |
52 | { |
53 | VALUE = 1 |
54 | }; |
55 | }; |
56 | |
57 | |
58 | template <typename T> |
59 | struct IsConst |
60 | /// Use this struct to determine if a template type is a const type. |
61 | { |
62 | enum |
63 | { |
64 | VALUE = 0 |
65 | }; |
66 | }; |
67 | |
68 | |
69 | template <typename T> |
70 | struct IsConst<const T&> |
71 | { |
72 | enum |
73 | { |
74 | VALUE = 1 |
75 | }; |
76 | }; |
77 | |
78 | |
79 | template <typename T> |
80 | struct IsConst<const T> |
81 | { |
82 | enum |
83 | { |
84 | VALUE = 1 |
85 | }; |
86 | }; |
87 | |
88 | |
89 | template <typename T, int i> |
90 | struct IsConst<const T[i]> |
91 | /// Specialization for const char arrays |
92 | { |
93 | enum |
94 | { |
95 | VALUE = 1 |
96 | }; |
97 | }; |
98 | |
99 | |
100 | template <typename T> |
101 | struct TypeWrapper |
102 | /// Use the type wrapper if you want to decouple constness and references from template types. |
103 | { |
104 | typedef T TYPE; |
105 | typedef const T CONSTTYPE; |
106 | typedef T& REFTYPE; |
107 | typedef const T& CONSTREFTYPE; |
108 | }; |
109 | |
110 | |
111 | template <typename T> |
112 | struct TypeWrapper<const T> |
113 | { |
114 | typedef T TYPE; |
115 | typedef const T CONSTTYPE; |
116 | typedef T& REFTYPE; |
117 | typedef const T& CONSTREFTYPE; |
118 | }; |
119 | |
120 | |
121 | template <typename T> |
122 | struct TypeWrapper<const T&> |
123 | { |
124 | typedef T TYPE; |
125 | typedef const T CONSTTYPE; |
126 | typedef T& REFTYPE; |
127 | typedef const T& CONSTREFTYPE; |
128 | }; |
129 | |
130 | |
131 | template <typename T> |
132 | struct TypeWrapper<T&> |
133 | { |
134 | typedef T TYPE; |
135 | typedef const T CONSTTYPE; |
136 | typedef T& REFTYPE; |
137 | typedef const T& CONSTREFTYPE; |
138 | }; |
139 | |
140 | |
141 | } // namespace Poco |
142 | |
143 | |
144 | #endif // Foundation_MetaProgramming_INCLUDED |
145 | |