All Classes Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
meta/meta.hpp
1 // The MIT License (MIT)
2 
3 // Copyright (c) 2012-2014 Danny Y., Rapptz
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal in
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 // the Software, and to permit persons to whom the Software is furnished to do so,
10 // subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 
22 #ifndef GEARS_META_META_HPP
23 #define GEARS_META_META_HPP
24 
25 #include <type_traits>
26 #include <utility>
27 
28 namespace gears {
29 namespace meta {
34 template<typename T>
35 using Type = typename T::type;
36 
41 template<typename... Args>
42 using CommonType = Type<std::common_type<Args...>>;
43 
44 
49 template<typename T>
51 
52 
57 template<typename T, T t>
58 using Const = std::integral_constant<T,t>;
59 
60 
65 template<int i>
67 
68 struct deduced {};
69 
70 template<typename T>
71 using is_deduced = std::is_same<T, deduced>;
72 
81 template<typename T>
82 struct identity {
83  using type = T;
84 };
85 
93 template<typename...>
94 struct void_ {
95  using type = void;
96 };
97 
102 template<typename... T>
103 using Void = Type<void_<T...>>;
104 
109 template<bool B>
111 
125 template<typename Condition, typename Then, typename Else>
127 
132 template<typename Condition, typename Then, typename Else>
134 
151 template<typename T>
152 struct Not : Bool<!T::value> {};
153 
169 template<typename... Args>
170 struct Any : Bool<false> {};
171 
172 template<typename T, typename... Args>
173 struct Any<T, Args...> : If<T, Bool<true>, Any<Args...>> {};
174 
190 template<typename... Args>
191 struct All : Bool<true> {};
192 
193 template<typename T, typename... Args>
194 struct All<T, Args...> : If<T, All<Args...>, Bool<false>> {};
195 
196 template<typename Signature, typename Anon = void>
197 struct result_of_impl {};
198 
199 template<typename Function, typename... Args>
200 struct result_of_impl<Function(Args...), Void<decltype(std::declval<Function>()(std::declval<Args>()...))>> {
201  using type = decltype(std::declval<Function>()(std::declval<Args>()...));
202 };
203 
208 template<typename Signature>
210 
236 template<typename T>
237 struct class_of {};
238 
239 template<typename Signature, typename Class>
240 struct class_of<Signature Class::*> : identity<Class> {};
241 
246 template<typename T>
248 
256 template<typename T>
257 constexpr const T& as_const(T& t) {
258  return t;
259 }
260 
261 template<typename T>
262 constexpr T&& cforward(typename std::remove_reference<T>::type& t) noexcept {
263  return static_cast<T&&>(t);
264 }
265 
274 template<typename T>
275 constexpr T&& cforward(typename std::remove_reference<T>::type&& t) noexcept {
276  static_assert(!std::is_lvalue_reference<T>(), "error");
277  return static_cast<T&&>(t);
278 }
279 
288 template<typename T>
289 constexpr typename std::remove_reference<T>::type&& cmove(T&& t) noexcept {
290  return static_cast<typename std::remove_reference<T>::type&&>(t);
291 }
292 } // meta
293 } // gears
294 
295 #endif // GEARS_META_META_HPP