MtFmt 1.0.0
MtFmt is a format library on embed. system and wrote by pure C.
载入中...
搜索中...
未找到
mm_type.hpp
浏览该文件的文档.
1// SPDX-License-Identifier: LGPL-3.0
12#if !defined(_INCLUDE_MM_TYPE_HPP_)
13#define _INCLUDE_MM_TYPE_HPP_ 1
14#include "mm_cfg.h"
15#include <cstddef>
16#include <exception>
17#include <tuple>
18#include <type_traits>
19#include <utility>
20namespace mtfmt
21{
22namespace details
23{
28struct unit_t
29{
30 constexpr bool operator==(unit_t) noexcept
31 {
32 return true;
33 }
34
35 constexpr bool operator!=(unit_t) noexcept
36 {
37 return false;
38 }
39
40 constexpr bool operator<(unit_t) noexcept
41 {
42 return false;
43 }
44
45 constexpr bool operator>(unit_t) noexcept
46 {
47 return false;
48 }
49
50 constexpr bool operator<=(unit_t) noexcept
51 {
52 return true;
53 }
54
55 constexpr bool operator>=(unit_t) noexcept
56 {
57 return true;
58 }
59};
60
64template <typename Ret, typename... Args> struct function_traits_base
65{
69 static constexpr size_t NArgs = sizeof...(Args);
71 using arg_tuple_t = std::tuple<Args...>;
72};
73
74template <typename F> struct function_trait_impl;
75
76template <typename F>
78 : public function_trait_impl<F>
79{
80};
81
82// for: function pointer
83template <typename Ret, typename... Args>
85 : public function_traits_base<Ret, Args...>
86{
87};
88
89// for: member function pointer
90template <typename Ret, typename Cl, typename... Args>
91struct function_trait_impl<Ret (Cl::*)(Args...)>
92 : public function_traits_base<Ret, Args...>
93{
94};
95
96// for: const member function pointer
97template <typename Ret, typename Cl, typename... Args>
98struct function_trait_impl<Ret (Cl::*)(Args...) const>
99 : public function_traits_base<Ret, Args...>
100{
101};
102
103// 除去如上三种情况的case
104template <typename F>
106 : public function_trait_impl<decltype(&F::operator())>
107{
108};
109
114template <typename F>
116 : public function_trait_impl<typename std::decay<F>::type>
117{
118};
119
124template <typename F>
127
132template <typename F>
134
139template <typename F> struct function_arg_count
140{
141 static constexpr std::size_t N = function_trait<F>::NArgs;
142};
143
148template <template <typename...> typename Tt, typename Ti>
150{
151 static constexpr bool value = false;
152};
153
154// 判断Ti是否为模板Tt的实例化
155template <template <typename...> typename Tt, typename... Ti>
156struct is_instance_of<Tt, Tt<Ti...>>
157{
158 static constexpr bool value = true;
159};
160
165template <typename F, std::size_t N> struct function_has_n_args
166{
167 static constexpr bool value = function_arg_count<F>::N == N;
168};
169
174template <typename F, std::size_t N, typename T>
176{
177 static constexpr bool value = std::is_same<
178 // 取得第n个参数
179 typename std::tuple_element<N, function_arg_tuple_t<F>>::type,
180 // 并检查其拥有的类型
181 T>::value;
182};
183
188template <typename F, typename R, typename... T> struct holds_prototype
189{
192 using Targs = std::tuple<typename std::decay<T>::type...>;
193
194 static constexpr bool value =
195 function_has_n_args<F, sizeof...(T)>::value &&
196 std::is_same<_Ret, R>::value &&
197 std::is_same<_Args, Targs>::value;
198};
199
204template <bool cond, typename T>
205using enable_if_t = typename std::enable_if<cond, T>::type;
206
211template <std::size_t A1, std::size_t... An> struct max_value;
212
213template <std::size_t A1> struct max_value<A1>
214{
215 static constexpr size_t value = A1;
216};
217
218template <std::size_t A1, std::size_t A2, std::size_t... An>
219struct max_value<A1, A2, An...>
220{
221 static constexpr size_t value = A1 >= A2 ?
222 max_value<A1, An...>::value :
223 max_value<A2, An...>::value;
224};
225
232template <bool A1, bool... An> struct disjunction;
233
234template <bool A1> struct disjunction<A1>
235{
236 static constexpr bool value = A1;
237};
238
239template <bool A1, bool A2, bool... An>
240struct disjunction<A1, A2, An...>
241{
242 static constexpr bool value = A1 && disjunction<A2, An...>::value;
243};
244
245} // namespace details
246} // namespace mtfmt
247#endif // _INCLUDE_MM_TYPE_HPP_
结果类
Definition mm_result.hpp:415
配置选项
typename function_trait< F >::return_type_t function_return_type_t
取得函数的返回值类型
Definition mm_type.hpp:126
typename function_trait< F >::arg_tuple_t function_arg_tuple_t
取得函数的参数类型
Definition mm_type.hpp:133
typename std::enable_if< cond, T >::type enable_if_t
enable_if_t, 和cpp14一样(但是这里是cpp11呜呜呜)
Definition mm_type.hpp:205
Definition mm_parser.hpp:17
取得and
Definition mm_type.hpp:232
取得函数的参数的个数
Definition mm_type.hpp:140
static constexpr std::size_t N
Definition mm_type.hpp:141
表示第n个参数应该拥有类型T
Definition mm_type.hpp:176
static constexpr bool value
Definition mm_type.hpp:177
表示检查函数参数有多少个
Definition mm_type.hpp:166
static constexpr bool value
Definition mm_type.hpp:167
Definition mm_type.hpp:107
取得函数的各种细节
Definition mm_type.hpp:117
用于存放函数类型信息的东东
Definition mm_type.hpp:65
std::tuple< Args... > arg_tuple_t
参数(元组)
Definition mm_type.hpp:71
static constexpr size_t NArgs
参数数目
Definition mm_type.hpp:69
检查函数F的类型为 ( T1, T2 ...) -> R
Definition mm_type.hpp:189
static constexpr bool value
Definition mm_type.hpp:194
std::tuple< typename std::decay< T >::type... > Targs
Definition mm_type.hpp:192
details::function_return_type_t< F > _Ret
Definition mm_type.hpp:190
details::function_arg_tuple_t< F > _Args
Definition mm_type.hpp:191
判断Ti是否为模板Tt的实例化
Definition mm_type.hpp:150
static constexpr bool value
Definition mm_type.hpp:151
取得最大值
Definition mm_type.hpp:211
单位类型
Definition mm_type.hpp:29
constexpr bool operator!=(unit_t) noexcept
Definition mm_type.hpp:35
constexpr bool operator>=(unit_t) noexcept
Definition mm_type.hpp:55
constexpr bool operator<=(unit_t) noexcept
Definition mm_type.hpp:50
constexpr bool operator==(unit_t) noexcept
Definition mm_type.hpp:30
constexpr bool operator>(unit_t) noexcept
Definition mm_type.hpp:45
constexpr bool operator<(unit_t) noexcept
Definition mm_type.hpp:40