qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
type_traits.h File Reference

Advanced type traits and metaprogramming utilities for the QB Framework. More...

#include <string_view>
#include <type_traits>
#include <utility>
#include <valarray>
Include dependency graph for type_traits.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  qb::crtp< T >
 Base class for implementing the Curiously Recurring Template Pattern (CRTP). More...
struct  qb::detail::has_const_iterator< T >
 Type trait to detect whether T has a const_iterator type. More...
struct  qb::detail::has_begin_end< T >
 Type trait to detect whether T has begin() and end() methods. More...
struct  qb::detail::is_mappish_impl< T, U >
 Internal implementation to detect map-like types. More...
struct  qb::detail::is_mappish_impl< T, std::void_t< typename T::key_type, typename T::mapped_type, decltype(std::declval< T & >()[std::declval< const typename T::key_type & >()])> >
 Specialization for types that have key_type, mapped_type, and operator[]. More...
struct  qb::is_container< T >
 Type trait to check if a type T is a container. More...
struct  qb::is_container< T[N]>
 Specialization for array types, which are containers. More...
struct  qb::is_container< char[N]>
 Specialization for character arrays, which are not considered containers. More...
struct  qb::is_container< std::valarray< T > >
 Specialization for std::valarray, which is a container. More...
struct  qb::is_container< std::pair< T1, T2 > >
 Specialization for std::pair, which is a container. More...
struct  qb::is_container< std::tuple< Args... > >
 Specialization for std::tuple, which is a container. More...
struct  qb::remove_reference_if< T, cond >
 Conditionally removes a reference from type T if cond is true. More...
struct  qb::remove_reference_if< T, true >
 Specialization that actually removes the reference. More...
struct  qb::is_mappish< T >
 Type trait to check if a type T is map-like. More...
struct  qb::is_pair<... >
 Type trait to check if a type is a std::pair. More...
struct  qb::is_pair< std::pair< T, U > >
 Specialization for std::pair, which returns true. More...
struct  qb::is_inserter< T, U >
 Type trait to check if a type T is an inserter iterator (e.g., std::back_inserter). More...
struct  qb::is_inserter< T, typename std::enable_if<!std::is_void< typename T::container_type >::value >::type >
 Specialization for types that have a container_type. More...
struct  qb::iterator_type< Iter, T >
 Type trait to extract the value_type from an iterator Iter. More...
struct  qb::iterator_type< Iter, typename std::enable_if< is_inserter< Iter >::value >::type >
 Specialization for inserter iterators. More...
struct  qb::is_terator< Iter, T >
 Type trait to check if a type Iter is an iterator. More...
struct  qb::is_terator< Iter, typename std::enable_if< is_inserter< Iter >::value >::type >
 Specialization for inserter iterators. More...
struct  qb::is_terator< Iter, typename std::enable_if<!std::is_void< typename std::iterator_traits< Iter >::value_type >::value >::type >
 Specialization for standard iterators. More...
struct  qb::is_map_iterator< T >
 Type trait to check if an iterator T points to map elements (i.e., std::pair). More...
struct  qb::has_push_back< T, typename >
 Type trait to check if a type T has a push_back(T::value_type) member function. More...
struct  qb::has_push_back< T, typename std::enable_if< std::is_void< decltype(std::declval< T >().push_back(std::declval< typename T::value_type >()))>::value >::type >
 Specialization for types with a valid push_back method. More...
struct  qb::has_insert< T, typename >
 Type trait to check if a type T has an insert(T::const_iterator, T::value_type) member function. More...
struct  qb::has_insert< T, typename std::enable_if< std::is_same< decltype(std::declval< T >().insert(std::declval< typename T::const_iterator >(), std::declval< typename T::value_type >())), typename T::iterator >::value >::type >
 Specialization for types with a valid insert method. More...
struct  qb::is_sequence_container< T >
 Type trait to check if type T is a sequence container. More...
struct  qb::is_associative_container< T >
 Type trait to check if type T is an associative container. More...
struct  qb::nth_type< num, T, Y... >
 Recursive case for nth_type template. More...
struct  qb::nth_type< 0, T, Y... >
 Base case for nth_type template. More...
struct  qb::indexes_tuple< Indexes >
 Represents a compile-time tuple of size_t indexes. More...
struct  qb::index_builder< num, indexes_tuple< Indexes... > >
 Recursive case for index_builder. More...
struct  qb::index_builder< 0, indexes_tuple< Indexes... > >
 Base case for index_builder. More...
struct  qb::expand
 Utility for forcing parameter pack expansion in certain contexts. More...
struct  ambiguate< Args >
 Helper class to force ambiguity of class members. More...
struct  got_type< A, typename >
 Type trait to check if a type exists. More...
struct  got_type< A >
 Specialization that indicates the type exists. More...
struct  sig_check< T, T >
 Helper for signature checking. More...
struct  has_member< Alias, AmbiguitySeed >
 Type trait to check if a type has a specific member. More...

Macros

#define CREATE_MEMBER_CHECK(member)
 Macro to create a type trait to check for any member with a given name.
#define CREATE_MEMBER_VAR_CHECK(var_name)
 Macro to create a type trait to check for a member variable with given name.
#define CREATE_MEMBER_CLASS_CHECK(class_name)
 Macro to create a type trait to check for a member class with given name.
#define CREATE_MEMBER_UNION_CHECK(union_name)
 Macro to create a type trait to check for a member union with given name.
#define CREATE_MEMBER_ENUM_CHECK(enum_name)
 Macro to create a type trait to check for a member enum with given name.
#define CREATE_MEMBER_FUNC_CHECK(func)
 Macro to create a type trait to check for a member function with given name.
#define CREATE_MEMBER_CHECKS(member)
 Macro to create all member check variants for a single member name.
#define GENERATE_HAS_METHOD(method)
 Macro to generate a type trait to check for a method with a specific signature.
#define GENERATE_HAS_MEMBER(member)
 Macro to generate a type trait to check for a member of any kind.
#define GENERATE_HAS_MEMBER_TYPE(Type)
 Macro to generate a type trait to check for a member type.

Typedefs

template<typename...>
using qb::Void = void
 Helper alias to void for SFINAE purposes.

Functions

template<typename T>
std::remove_reference_t< T > && mv (T &&t) noexcept
 Alias for std::move with a concise syntax.
template<typename T>
T && fwd (std::remove_reference_t< T > &t) noexcept
 Alias for std::forward with a concise syntax (lvalue overload).
template<typename T>
T && fwd (std::remove_reference_t< T > &&t) noexcept
 Alias for std::forward with a concise syntax (rvalue overload).
 CREATE_MEMBER_CHECKS (is_alive)
 CREATE_MEMBER_CHECKS (is_broadcast)
 CREATE_MEMBER_CHECKS (is_valid)
 CREATE_MEMBER_CHECKS (disconnect)

Detailed Description

Advanced type traits and metaprogramming utilities for the QB Framework.

This file extends the standard library's <type_traits> with additional type traits and metaprogramming utilities. These are used for compile-time introspection and template metaprogramming, enabling features such as:

  • Detection of container properties (e.g., is_container, is_sequence_container).
  • Iterator category detection and value type extraction (is_map_iterator, iterator_type).
  • CRTP (Curiously Recurring Template Pattern) base helper (qb::crtp).
  • SFINAE utilities for detecting member types and functions (e.g., has_push_back, macros like CREATE_MEMBER_CHECK).
  • Helper aliases for std::move and std::forward (qb::mv, qb::fwd).
  • Utilities for variadic template expansion (qb::indexes_tuple, qb::expand).

These utilities are primarily for internal framework use but can also be leveraged by application code for advanced template programming.

Macro Definition Documentation

◆ CREATE_MEMBER_CHECK

#define CREATE_MEMBER_CHECK ( member)
Value:
\
template <typename T, typename = std::true_type> \
struct Alias_##member; \
\
template <typename T> \
struct Alias_##member< \
T, std::integral_constant<bool, got_type<decltype(&T::member)>::value>> { \
static const decltype(&T::member) value; \
}; \
\
struct AmbiguitySeed_##member { \
char member; \
}; \
\
template <typename T> \
struct has_member_##member { \
static const bool value = \
has_member<Alias_##member<ambiguate<T, AmbiguitySeed_##member>>, \
Alias_##member<AmbiguitySeed_##member>>::value; \
}

Macro to create a type trait to check for any member with a given name.

Creates has_member_[member] trait that can detect variables, functions, classes, unions, or enums.

Parameters
memberName of the member to check for

◆ CREATE_MEMBER_VAR_CHECK

#define CREATE_MEMBER_VAR_CHECK ( var_name)
Value:
\
template <typename T, typename = std::true_type> \
struct has_member_var_##var_name : std::false_type {}; \
\
template <typename T> \
struct has_member_var_##var_name< \
T, std::integral_constant< \
bool, !std::is_member_function_pointer<decltype(&T::var_name)>::value>> \
: std::true_type {}

Macro to create a type trait to check for a member variable with given name.

Creates has_member_var_[var_name] trait.

Parameters
var_nameName of the variable to check for

◆ CREATE_MEMBER_CLASS_CHECK

#define CREATE_MEMBER_CLASS_CHECK ( class_name)
Value:
\
template <typename T, typename = std::true_type> \
struct has_member_class_##class_name : std::false_type {}; \
\
template <typename T> \
struct has_member_class_##class_name< \
T, std::integral_constant<bool, std::is_class<typename got_type< \
typename T::class_name>::type>::value>> \
: std::true_type {}

Macro to create a type trait to check for a member class with given name.

Creates has_member_class_[class_name] trait.

Parameters
class_nameName of the class to check for

◆ CREATE_MEMBER_UNION_CHECK

#define CREATE_MEMBER_UNION_CHECK ( union_name)
Value:
\
template <typename T, typename = std::true_type> \
struct has_member_union_##union_name : std::false_type {}; \
\
template <typename T> \
struct has_member_union_##union_name< \
T, std::integral_constant<bool, std::is_union<typename got_type< \
typename T::union_name>::type>::value>> \
: std::true_type {}

Macro to create a type trait to check for a member union with given name.

Creates has_member_union_[union_name] trait.

Parameters
union_nameName of the union to check for

◆ CREATE_MEMBER_ENUM_CHECK

#define CREATE_MEMBER_ENUM_CHECK ( enum_name)
Value:
\
template <typename T, typename = std::true_type> \
struct has_member_enum_##enum_name : std::false_type {}; \
\
template <typename T> \
struct has_member_enum_##enum_name< \
T, \
std::integral_constant< \
bool, std::is_enum<typename got_type<typename T::enum_name>::type>::value>> \
: std::true_type {}

Macro to create a type trait to check for a member enum with given name.

Creates has_member_enum_[enum_name] trait.

Parameters
enum_nameName of the enum to check for

◆ CREATE_MEMBER_FUNC_CHECK

#define CREATE_MEMBER_FUNC_CHECK ( func)
Value:
template <typename T> \
struct has_member_func_##func { \
static const bool value = \
has_member_##func<T>::value && !has_member_var_##func<T>::value && \
!has_member_class_##func<T>::value && !has_member_union_##func<T>::value && \
!has_member_enum_##func<T>::value; \
}

Macro to create a type trait to check for a member function with given name.

Creates has_member_func_[func] trait that identifies functions specifically (not variables, classes, unions, or enums).

Parameters
funcName of the function to check for

◆ CREATE_MEMBER_CHECKS

#define CREATE_MEMBER_CHECKS ( member)
Value:
CREATE_MEMBER_VAR_CHECK(member); \
CREATE_MEMBER_CLASS_CHECK(member); \
CREATE_MEMBER_UNION_CHECK(member); \
CREATE_MEMBER_ENUM_CHECK(member); \
CREATE_MEMBER_FUNC_CHECK(member)
#define CREATE_MEMBER_CHECK(member)
Macro to create a type trait to check for any member with a given name.
Definition type_traits.h:669

Macro to create all member check variants for a single member name.

Creates checks for any member type, variables, classes, unions, enums, and functions.

Parameters
memberName of the member to check for

◆ GENERATE_HAS_METHOD

#define GENERATE_HAS_METHOD ( method)
Value:
\
template <typename C, typename Ret, typename... Args> \
class has_method_##method { \
template <typename T> \
static constexpr auto check(T *) -> typename std::is_same< \
decltype(std::declval<T>().method(std::declval<Args>()...)), Ret>::type; \
\
template <typename> \
static constexpr std::false_type check(...); \
\
typedef decltype(check<C>(0)) type; \
\
public: \
static constexpr bool value = type::value; \
};

Macro to generate a type trait to check for a method with a specific signature.

Creates has_method_[method] trait that checks if a type has a method with the given name and matches the specified signature (return type and parameters).

Parameters
methodName of the method to check for

◆ GENERATE_HAS_MEMBER

#define GENERATE_HAS_MEMBER ( member)
Value:
\
template <class T> \
class HasMember_##member { \
private: \
using Yes = char[2]; \
using No = char[1]; \
\
struct Fallback { \
int member; \
}; \
struct Derived \
: T \
, Fallback {}; \
\
template <class U> \
static No &test(decltype(U::member) *); \
template <typename U> \
static Yes &test(U *); \
\
public: \
static constexpr bool RESULT = sizeof(test<Derived>(nullptr)) == sizeof(Yes); \
}; \
\
template <class T> \
struct has_member_##member \
: public std::integral_constant<bool, HasMember_##member<T>::RESULT> {};

Macro to generate a type trait to check for a member of any kind.

Creates has_member_[member] trait using a different technique that avoids ambiguity issues in some contexts.

Parameters
memberName of the member to check for

◆ GENERATE_HAS_MEMBER_TYPE

#define GENERATE_HAS_MEMBER_TYPE ( Type)
Value:
\
template <class T> \
class HasMemberType_##Type { \
private: \
using Yes = char[2]; \
using No = char[1]; \
\
struct Fallback { \
struct Type {}; \
}; \
struct Derived \
: T \
, Fallback {}; \
\
template <class U> \
static No &test(typename U::Type *); \
template <typename U> \
static Yes &test(U *); \
\
public: \
static constexpr bool RESULT = sizeof(test<Derived>(nullptr)) == sizeof(Yes); \
}; \
\
template <class T> \
struct has_member_type_##Type \
: public std::integral_constant<bool, HasMemberType_##Type<T>::RESULT> {};

Macro to generate a type trait to check for a member type.

Creates has_member_type_[Type] trait that checks if a type has a nested type definition with the given name.

Parameters
TypeName of the type to check for