1#ifndef CPP_UTILITIES_TRAITS_H
2#define CPP_UTILITIES_TRAITS_H
20template <
typename If,
typename Then,
typename Else>
using Conditional =
typename std::conditional<If::value, Then, Else>::type;
23template <
bool B,
typename...>
struct Bool : std::integral_constant<bool, B> {};
29template <
typename... T>
struct Any :
Bool<false> {};
34template <
typename... T>
struct All :
Bool<true> {};
39template <
typename... T>
struct None :
Bool<true> {};
55template <
typename T,
template <
typename...>
class Template>
struct IsSpecializationOfHelper :
Bool<false> {};
56template <
template <
typename...>
class Template,
typename... Args>
struct IsSpecializationOfHelper<Template<Args...>, Template> :
Bool<true> {};
60template <
typename Type,
template <
typename...>
class...
TemplateTypes>
62 : Detail::IsSpecializationOfHelper<typename std::remove_cv<typename std::remove_reference<Type>::type>::type, TemplateTypes...> {};
68 :
Conditional<IsSpecializationOf<Type, TemplateType>, Bool<true>, IsSpecializingAnyOf<Type, RemainingTemplateTypes...>> {};
84 :
Bool<std::is_same<char const *, typename std::decay<T>::type>::value || std::is_same<char *, typename std::decay<T>::type>::value> {};
89 :
Bool<IsCString<T>::value || IsSpecializationOf<T, std::basic_string>::value || IsSpecializationOf<T, std::basic_string_view>::value> {};
100#define CPP_UTILITIES_PP_COMMA ,
108#define CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK(CheckName, CheckCode) \
110 template <typename T> auto CheckName(int) -> decltype(CheckCode, ::CppUtilities::Traits::Bool<true>{}); \
111 template <typename T>::CppUtilities::Traits::Bool<false> CheckName(...); \
113 template <typename T> using CheckName = decltype(Detail::CheckName<T>(0))
133 std::begin(std::declval<T &>())
140 void(*
begin(std::declval<T &>())));
143template <
typename T, EnableIf<IsDereferencable<T>> * =
nullptr>
constexpr auto &
dereferenceMaybe(T &&value)
149template <
typename T, DisableIf<IsDereferencable<T>> * =
nullptr>
constexpr auto &
dereferenceMaybe(T &&value)
typename std::enable_if<!All< Condition... >::value, Detail::Enabler >::type DisableIf
Shortcut for std::enable_if to negate the condition and omit ::value and ::type.
typename std::enable_if< Any< Condition... >::value, Detail::Enabler >::type EnableIfAny
Shortcut for std::enable_if to apply Traits::Any and omit ::value and ::type.
constexpr auto & dereferenceMaybe(T &&value)
Dereferences the specified value if possible; otherwise just returns value itself.
typename std::conditional< If::value, Then, Else >::type Conditional
Shortcut for std::conditional to omit ::value and ::type.
typename std::enable_if< All< Condition... >::value, Detail::Enabler >::type EnableIf
Shortcut for std::enable_if to omit ::value and ::type.
typename std::enable_if<!Any< Condition... >::value, Detail::Enabler >::type DisableIfAny
Shortcut for std::enable_if to apply Traits::Any, negate the condition and omit ::value and ::type.
Contains all utilities provides by the c++utilities library.
IntegralType stringToNumber(const StringType &string, BaseType base=10)
Converts the given string to an unsigned/signed number assuming string uses the specified base.
Evaluates to Bool<true> if all specified conditions are true; otherwise evaluates to Bool<false>.
Evaluates to Bool<true> if at least one of the specified conditions is true; otherwise evaluates to B...
Wraps a static boolean constant.
Evaluates to Bool<true> if the specified type is any of the specified types; otherwise evaluates to B...
Evaluates to Bool<true> if the specified type is a C-string (char * or const char *); otherwise evalu...
Evaluates to Bool<true> if the specified type is complete; if the type is only forward-declared it ev...
Evaluates to Bool<true> if the specified type is none of the specified types; otherwise evaluates to ...
Evaluates to Bool<true> if the specified type is based on the specified template; otherwise evaluates...
Evaluates to Bool<true> if the specified type is based on one of the specified templates; otherwise e...
Evaluates to Bool<true> if the specified type is a standard string, standard string view or C-string ...
Evaluates to Bool<true> if none of the specified conditions are true; otherwise evaluates to Bool<fal...
#define CPP_UTILITIES_PP_COMMA
The CPP_UTILITIES_PP_COMMA macro helps passing "," as a macro argument.
#define CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK(CheckName, CheckCode)
The CPP_UTILITIES_TRAITS_DEFINE_TYPE_CHECK macro defines a type trait for checking whether some opera...