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/// @brief Returns `true` if the type is an instantiation of the specified template.
26template <typename T, template <typename...> typename Template>
27concept IsInstantiationOf = impl::IsInstantiationOf<Template, T>::value;
28
29/// @brief Returns `true` if the type (with remove cv-qualifiers) is an instantiation of the specified template.
30template <typename T, template <typename...> typename Template>
31concept IsCvInstantiationOf = IsInstantiationOf<std::remove_cv_t<T>, Template>;
32
33/// Returns `true` if the type is a fundamental character type.
34/// `signed char` and `unsigned char` are not character types.
35template <typename T>
36concept IsCharacter =
37 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>;
38
39/// Returns `true` if the type is a true integer type (not `*char*` or `bool`)
40/// `signed char` and `unsigned char` are integer types
41template <typename T>
42concept IsInteger = std::is_integral_v<T> && !IsCharacter<T> && !std::is_same_v<T, bool>;
43
44} // namespace meta
45
46USERVER_NAMESPACE_END