userver: userver/utils/meta_light.hpp Source File
Loading...
Searching...
No Matches
meta_light.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/utils/meta_light.hpp
4/// @brief Lightweight concepts
5/// @see userver/utils/meta.hpp for more concepts
6/// @ingroup userver_universal
7
8// Don't add new includes here! Put concepts that require them in meta.hpp.
9#include <type_traits>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace meta {
14
15namespace impl {
16
17template <template <typename...> typename Template, typename T>
18struct IsInstantiationOf : std::false_type {};
19
20template <template <typename...> typename Template, typename... Args>
21struct IsInstantiationOf<Template, Template<Args...>> : std::true_type {};
22
23} // namespace impl
24
25#ifndef ARCADIA_ROOT
26
27/// @brief Checks whether a trait is correct for the given template args
28///
29/// @deprecated Use a `requires` expression directly:
30/// @code
31/// if constexpr (requires { typename T::ValueType; }) { ... }
32/// @endcode
33template <template <typename...> typename Trait, typename... Args>
34concept IsDetected = requires { typename Trait<Args...>; };
35
36#endif
37
38/// @brief Returns `true` if the type is an instantiation of the specified template.
39template <typename T, template <typename...> typename Template>
40concept IsInstantiationOf = impl::IsInstantiationOf<Template, T>::value;
41
42/// @brief Returns `true` if the type (with remove cv-qualifiers) is an instantiation of the specified template.
43template <typename T, template <typename...> typename Template>
44concept IsCvInstantiationOf = IsInstantiationOf<std::remove_cv_t<T>, Template>;
45
46/// Returns `true` if the type is a fundamental character type.
47/// `signed char` and `unsigned char` are not character types.
48template <typename T>
49concept IsCharacter =
50 std::is_same_v<T, char> || std::is_same_v<T, wchar_t> || std::is_same_v<T, char16_t> || std::is_same_v<T, char32_t>;
51
52/// Returns `true` if the type is a true integer type (not `*char*` or `bool`)
53/// `signed char` and `unsigned char` are integer types
54template <typename T>
55concept IsInteger = std::is_integral_v<T> && !IsCharacter<T> && !std::is_same_v<T, bool>;
56
57/// @brief Returns `true` if the type is an instantiation of the specified template.
58/// @deprecated Use @ref meta::IsInstantiationOf instead.
59template <template <typename...> typename Template, typename T>
60// NOLINTNEXTLINE(readability-identifier-naming)
61concept kIsInstantiationOf = IsInstantiationOf<T, Template>;
62
63/// @brief Returns `true` if the type (with remove cv-qualifiers) is an instantiation of the specified template.
64/// @deprecated Use @ref meta::IsCvInstantiationOf instead.
65template <template <typename...> typename Template, typename T>
66// NOLINTNEXTLINE(readability-identifier-naming)
67concept kIsCvInstantiationOf = IsCvInstantiationOf<T, Template>;
68
69/// @brief Returns `true` if the type is a true integer type (not `*char*` or `bool`)
70/// `signed char` and `unsigned char` are integer types
71/// @deprecated Use @ref meta::IsInteger instead.
72template <typename T>
73// NOLINTNEXTLINE(readability-identifier-naming)
74concept kIsInteger = IsInteger<T>;
75
76} // namespace meta
77
78USERVER_NAMESPACE_END