50 template <
class T,
class =
void>
58 T, typename std::enable_if<
59 sizeof(decltype(std::begin(std::declval<T>()))) &&
60 sizeof(decltype(std::end(std::declval<T>())))>::type>
72 template <
class F,
class = void,
class... Args>
78 template <
class F,
class... Args>
80 typename std::enable_if<
82 decltype(std::declval<F>()(std::declval<Args>()...)),
95 template <
class T,
class =
void>
104 typename std::iterator_traits<T>::
105 iterator_category)>::type>
117 template <
class T,
class Idx,
class =
void>
123 template <
class T,
class Idx>
125 typename std::enable_if<
126 sizeof(decltype(std::declval<T>()
127 [std::declval<Idx>()]))>::type>
138 template <
class T,
class =
void>
146 struct is_string<char *> : std::true_type
150 struct is_string<signed char *> : std::true_type
154 struct is_string<unsigned char *> : std::true_type
158 struct is_string<wchar_t *> : std::true_type
162 struct is_string<char16_t *> : std::true_type
166 struct is_string<char32_t *> : std::true_type
170 struct is_string<const char *> : std::true_type
174 struct is_string<const signed char *> : std::true_type
178 struct is_string<const unsigned char *> : std::true_type
182 struct is_string<const wchar_t *> : std::true_type
186 struct is_string<const char16_t *> : std::true_type
190 struct is_string<const char32_t *> : std::true_type
194 template <
class CharT,
class Traits,
class Alloc>
195 struct is_string<std::basic_string<CharT, Traits, Alloc>> : std::true_type
199#if __cplusplus >= 201703L
200 template <
class CharT,
class Traits>
201 struct is_string<std::basic_string_view<CharT, Traits>> : std::true_type
212 template <
class T,
class =
void>
221 decltype(std::declval<std::ostream &>()
222 << std::declval<T>()))>::type>
233 template <class T, class = void>
234 struct is_char : std::false_type
241 struct is_char<char> : std::true_type
245 struct is_char<signed char> : std::true_type
249 struct is_char<unsigned char> : std::true_type
253 struct is_char<wchar_t> : std::true_type
257 struct is_char<char16_t> : std::true_type
261 struct is_char<char32_t> : std::true_type
271 template <typename T, typename = void>
272 struct uniform_distribution_impl;
276 template <typename T>
277 struct uniform_distribution_impl<T, typename std::enable_if<std::is_integral<T>::value>::type>
279 using type = std::uniform_int_distribution<T>;
283 template <typename T>
284 struct uniform_distribution_impl<T, typename std::enable_if<std::is_floating_point<T>::value>::type>
286 using type = std::uniform_real_distribution<T>;
295 using enable_if_container =
296 typename std::enable_if<is_container<T>::value>::type;
302 using enable_if_not_container =
303 typename std::enable_if<!is_container<T>::value>::type;
308 template <class F, class... Args>
309 using enable_if_callable =
310 typename std::enable_if<is_callable<F, Args...>::value>::type;
315 template <class F, class... Args>
316 using enable_if_not_callable =
317 typename std::enable_if<!is_callable<F, Args...>::value>::type;
323 using enable_if_iterator =
324 typename std::enable_if<is_iterator<T>::value>::type;
330 using enable_if_not_iterator =
331 typename std::enable_if<!is_iterator<T>::value>::type;
337 using enable_if_string =
338 typename std::enable_if<is_string<
339 typename std::decay<T>::type>::value>::type;
345 using enable_if_not_string =
346 typename std::enable_if<!is_string<
347 typename std::decay<T>::type>::value>::type;
353 using enable_if_printable =
354 typename std::enable_if<is_printable<T>::value>::type;
360 using enable_if_not_printable =
361 typename std::enable_if<!is_printable<T>::value>::type;
367 using enable_if_char = typename std::enable_if<is_char<
368 typename std::decay<T>::type>::value>::type;
374 using enable_if_not_char = typename std::enable_if<!is_char<
375 typename std::decay<T>::type>::value>::type;
380 template <typename T>
381 using uniform_distribution_t = typename uniform_distribution_impl<T>::type;
检测类型是否支持下标操作符(如 T[Idx])。
Definition sfinae.h:119
检测类型是否可作为函数对象以给定参数调用(返回 void 或可转换为 void)。
Definition sfinae.h:74
检测类型是否为容器(支持 std::begin 和 std::end)。
Definition sfinae.h:52
检测类型是否为迭代器(具有 iterator_category)。
Definition sfinae.h:97
检测类型是否支持输出到 std::ostream(即定义了 operator<<)。
Definition sfinae.h:214
检测类型是否为字符串类型(char*、stdstring、std::string_view 等)。
Definition sfinae.h:140