Namespaces | Classes | Macros | Typedefs | Variables
Type Traits

Namespaces

 cpp17
 C++ STL code present in C++17.
 
 cpp20
 C++ STL code present in C++20.
 
 tt
 A collection of useful type traits.
 

Classes

struct  db::is_databox< T >
 Determines if a type T is as db::DataBox. More...
 
struct  is_any_spin_weighted< T >
 This is a std::true_type if the provided type is a SpinWeighted of any type and spin, otherwise is a std::false_type. More...
 
struct  is_spin_weighted_of< InternalType, T >
 This is a std::true_type if the provided type T is a SpinWeighted of InternalType and any spin, otherwise is a std::false_type. More...
 
struct  is_spin_weighted_of_same_type< T1, T2 >
 This is a std::true_type if the provided type T1 is a SpinWeighted and T2 is a SpinWeighted, and both have the same internal type, but any combination of spin weights. More...
 
struct  tt::is_tensor_index< T >
 Check if a type T is a TensorIndex used in TensorExpressions. More...
 
struct  get_vector_element_type< T, bool >
 Helper struct to determine the element type of a VectorImpl or container of VectorImpl. More...
 
struct  cpp17::conjunction<... >
 A logical AND on the template parameters. More...
 
struct  cpp17::disjunction<... >
 A logical OR on the template parameters. More...
 
struct  cpp17::negation< B >
 Negate a bool_constant. More...
 
struct  tt::can_be_copy_constructed< T, typename >
 Check if T is copy constructible. More...
 
struct  tt::is_std_array< T >
 Check if type T is a std::array. More...
 
struct  tt::is_std_array_of_size< N, T >
 Check if type T is a std::array of a given size. More...
 
struct  tt::is_a< U, T >
 Check if type T is a template specialization of U More...
 
struct  tt::is_iterable< T, typename >
 Check if type T has a begin() and end() function. More...
 
struct  tt::is_comparable< T, typename >
 Check if type T has <, <=, >, >=, ==, !=. More...
 
struct  tt::has_equivalence< T, typename >
 Check if type T has operator== defined. More...
 
struct  tt::has_inequivalence< T, U >
 Check if type T has operator!= defined. More...
 
class  tt::is_callable< TT, TArgs >
 Check if a type T is callable, i.e. T(Args...) is evaluable. More...
 
struct  tt::is_hashable< T, typename >
 Check if std::hash and std::equal_to are defined for type T. More...
 
struct  tt::is_maplike< T, typename >
 Check if type T is like a std::map or std::unordored_map. More...
 
struct  tt::is_streamable< S, T, typename >
 Check if type T has operator<<(S, T) defined. More...
 
struct  tt::is_string_like< T, typename >
 Check if type T is a std::string, or a C-style string. More...
 
struct  tt::has_get_clone< T, typename, typename >
 Check if type T has a get_clone() member function. More...
 
struct  tt::has_clone< T, typename, typename >
 Check if type T has a clone() member function. More...
 
struct  tt::has_size< T, typename >
 Check if type T has a size() member function. More...
 
struct  tt::is_integer< I >
 Check if I is an integer type (non-bool, non-character), unlike std::is_integral. More...
 
struct  tt::remove_reference_wrapper< T >
 Gets the underlying type if the type is a std::reference_wrapper, otherwise returns the type itself. More...
 
struct  tt::remove_cvref_wrap< T >
 Removes std::reference_wrapper, references, and cv qualifiers. More...
 
struct  tt::get_fundamental_type< T, Enable >
 Extracts the fundamental type for a container. More...
 
struct  tt::is_complex_of_fundamental< T, typename >
 Determines if a type T is a std::complex of a fundamental type, is a std::true_type if so, and otherwise is a std::false_type More...
 

Macros

#define CREATE_IS_CALLABLE(METHOD_NAME)
 Generate a type trait to check if a class has a member function that can be invoked with arguments of type TArgs... More...
 

Typedefs

template<typename T >
using is_derived_of_vector_impl = decltype(detail::is_derived_of_vector_impl_impl(std::declval< T * >()))
 This is std::true_type if the provided type possesses an implicit conversion to any VectorImpl, which is the primary feature of SpECTRE vectors generally. Otherwise, it is std::false_type.
 
template<bool B>
using cpp17::bool_constant = std::integral_constant< bool, B >
 A compile-time boolean. More...
 
template<typename... Ts>
using cpp17::void_t = void
 Given a set of types, returns void More...
 
template<class T , class... Args>
using cpp17::is_constructible_t = typename std::is_constructible< T, Args... >::type
 
template<typename F >
using tt::function_info = tt_detail::function_info_impl< F >
 Returns a struct that contains the return type, argument types, and the class type if the F is a non-static member function. More...
 
template<typename T , size_t = 0>
using tt::identity_t = T
 Given a type T and possibly a size_t evaluates to T. Useful for turning a std::index_sequence into a pack expansion of types. More...
 

Variables

template<typename T , typename U >
constexpr bool cpp17::is_same_v = std::is_same<T, U>::value
 Variable template for is_same.
 
template<typename T >
constexpr bool cpp17::is_lvalue_reference_v = std::is_lvalue_reference<T>::value
 
template<typename T >
constexpr bool cpp17::is_rvalue_reference_v = std::is_rvalue_reference<T>::value
 
template<typename T >
constexpr bool cpp17::is_reference_v = std::is_reference<T>::value
 
template<class T , class... Args>
constexpr bool cpp17::is_constructible_v = std::is_constructible<T, Args...>::value
 
template<class T , class... Args>
constexpr bool cpp17::is_trivially_constructible_v
 
template<class T , class... Args>
constexpr bool cpp17::is_nothrow_constructible_v
 
template<class T >
constexpr bool cpp17::is_default_constructible_v
 
template<class T >
constexpr bool cpp17::is_trivially_default_constructible_v
 
template<class T >
constexpr bool cpp17::is_nothrow_default_constructible_v
 
template<class T >
constexpr bool cpp17::is_copy_constructible_v = std::is_copy_constructible<T>::value
 
template<class T >
constexpr bool cpp17::is_trivially_copy_constructible_v
 
template<class T >
constexpr bool cpp17::is_nothrow_copy_constructible_v
 
template<class T >
constexpr bool cpp17::is_move_constructible_v = std::is_move_constructible<T>::value
 
template<class T >
constexpr bool cpp17::is_trivially_move_constructible_v
 
template<class T >
constexpr bool cpp17::is_nothrow_move_constructible_v
 
template<class T , class U >
constexpr bool cpp17::is_assignable_v = std::is_assignable<T, U>::value
 
template<class T , class U >
constexpr bool cpp17::is_trivially_assignable_v
 
template<class T , class U >
constexpr bool cpp17::is_nothrow_assignable_v
 
template<class From , class To >
constexpr bool cpp17::is_convertible_v = std::is_convertible<From, To>::value
 
template<class T >
constexpr bool cpp17::is_copy_assignable_v = std::is_copy_assignable<T>::value
 
template<class T >
constexpr bool cpp17::is_trivially_copy_assignable_v
 
template<class T >
constexpr bool cpp17::is_nothrow_copy_assignable_v
 
template<class T >
constexpr bool cpp17::is_move_assignable_v = std::is_move_assignable<T>::value
 
template<class T >
constexpr bool cpp17::is_trivially_move_assignable_v
 
template<class T >
constexpr bool cpp17::is_nothrow_move_assignable_v
 
template<class Base , class Derived >
constexpr bool cpp17::is_base_of_v = std::is_base_of<Base, Derived>::value
 
template<class T >
constexpr bool cpp17::is_unsigned_v = std::is_unsigned<T>::value
 
template<class T >
constexpr bool cpp17::is_arithmetic_v = std::is_arithmetic<T>::value
 
template<class T >
constexpr bool cpp17::is_floating_point_v = std::is_floating_point<T>::value
 
template<class T >
constexpr bool cpp17::is_integral_v = std::is_integral<T>::value
 
template<class T >
constexpr bool cpp17::is_fundamental_v = std::is_fundamental<T>::value
 
template<typename T >
constexpr bool tt::is_complex_or_fundamental_v
 Evaluates to true if type T is a std::complex of a fundamental type or if T is a fundamental type. More...
 
template<typename Array >
using tt::array_size = decltype(TypeTraits_detail::array_size_impl(std::declval< const Array & >()))
 Get the size of a std::array as a std::integral_constant. More...
 

Detailed Description

A collection of useful type traits, including C++14 and C++17 additions to the standard library.

Macro Definition Documentation

◆ CREATE_IS_CALLABLE

#define CREATE_IS_CALLABLE (   METHOD_NAME)
Value:
template <typename TT, typename... TArgs> \
class is_##METHOD_NAME##_callable { \
private: \
template <typename T, typename... Args> \
static auto test_callable(int) noexcept \
-> decltype(std::declval<T>().METHOD_NAME(std::declval<Args>()...), \
template <typename, typename...> \
static auto test_callable(...) noexcept -> std::false_type; \
\
public: \
static constexpr bool value = \
decltype(test_callable<TT, TArgs...>(0))::value; \
using type = std::integral_constant<bool, value>; \
}; \
template <typename T, typename... Args> \
static constexpr const bool is_##METHOD_NAME##_callable_v = \
is_##METHOD_NAME##_callable<T, Args...>::value; \
template <typename T, typename... Args> \
using is_##METHOD_NAME##_callable_t = \
typename is_##METHOD_NAME##_callable<T, Args...>::type;

Generate a type trait to check if a class has a member function that can be invoked with arguments of type TArgs...

The usage of the type trait is identical to the usage of the tt::is_callable type trait. The name of the type trait is is_METHOD_NAME_callable and is not placed in the tt namespace. To avoid collisions it is highly recommended that type traits generated with this macro are generated into _detail namespaces. This will reduce redefinition compilation errors. Note that a variable template is_METHOD_NAME_callable_v, and a is_METHOD_NAME_callable_t that is either std::true_type or std::false_type is also generated.

Example

struct bar {
void foo(int /*unused*/, double /*unused*/) {}
};
static_assert(is_foo_callable_v<bar, int, double>,
"Failed testing CREATE_IS_CALLABLE");
static_assert(not is_foo_callable_v<bar, int>,
"Failed testing CREATE_IS_CALLABLE");
static_assert(not is_foo_callable_v<bar>,
"Failed testing CREATE_IS_CALLABLE");
static_assert(not is_foobar_callable_v<bar, int, double>,
"Failed testing CREATE_IS_CALLABLE");
See also
tt::is_callable

Typedef Documentation

◆ array_size

template<typename Array >
using tt::array_size = typedef decltype(TypeTraits_detail::array_size_impl(std::declval<const Array&>()))

Get the size of a std::array as a std::integral_constant.

Details

Given a std::array, Array, returns a std::integral_constant that has the size of the array as its value

Usage

For a std::array T

using result = tt::array_size<T>;

Returns: std::integral_constant<std::size_t>

Semantics: For a type T,

Example

static_assert(tt::array_size<std::array<double, 3>>::value == 3,
"Failed testing type trait array_size");
static_assert(tt::array_size<std::array<A, 4>>::value == 4,
"Failed testing type trait array_size");
Template Parameters
Arraythe whose size should be stored in value of array_size

◆ bool_constant

template<bool B>
using cpp17::bool_constant = typedef std::integral_constant<bool, B>

A compile-time boolean.

Usage

For any bool B

using result = cpp17::bool_constant<B>;
See also
std::bool_constant std::integral_constant std::true_type std::false_type

◆ function_info

template<typename F >
using tt::function_info = typedef tt_detail::function_info_impl<F>

Returns a struct that contains the return type, argument types, and the class type if the F is a non-static member function.

The return class has member type aliases:

  • return_type The return type of the function
  • argument_types A tmpl::list of the arguments types of the function
  • class_type The type of the class if the function is a non-static member function, otherwise void
Note
For static member variables the class will be void because they are effectively free functions.

◆ identity_t

template<typename T , size_t = 0>
using tt::identity_t = typedef T

Given a type T and possibly a size_t evaluates to T. Useful for turning a std::index_sequence into a pack expansion of types.

template <size_t... Is>
struct IdentityPackExample<std::index_sequence<Is...>> {
};

◆ void_t

template<typename... Ts>
using cpp17::void_t = typedef void

Given a set of types, returns void

Details

Given a list of types, returns void. This is very useful for controlling name lookup resolution via partial template specialization.

Usage

For any set of types Ti,

Returns: void

Semantics: For any set of types Ti,

using result = void;

Example

static_assert(std::is_same<cpp17::void_t<char, bool, double>, void>::value,
"Failed testing type trait void_t");
See also
std::void_t
Template Parameters
Tsthe set of types

Variable Documentation

◆ is_complex_or_fundamental_v

template<typename T >
constexpr bool tt::is_complex_or_fundamental_v
Initial value:
=
is_complex_of_fundamental_v<T> or cpp17::is_fundamental_v<T>

Evaluates to true if type T is a std::complex of a fundamental type or if T is a fundamental type.

◆ is_default_constructible_v

template<class T >
constexpr bool cpp17::is_default_constructible_v

◆ is_nothrow_assignable_v

template<class T , class U >
constexpr bool cpp17::is_nothrow_assignable_v

◆ is_nothrow_constructible_v

template<class T , class... Args>
constexpr bool cpp17::is_nothrow_constructible_v

◆ is_nothrow_copy_assignable_v

template<class T >
constexpr bool cpp17::is_nothrow_copy_assignable_v

◆ is_nothrow_copy_constructible_v

template<class T >
constexpr bool cpp17::is_nothrow_copy_constructible_v

◆ is_nothrow_default_constructible_v

template<class T >
constexpr bool cpp17::is_nothrow_default_constructible_v

◆ is_nothrow_move_assignable_v

template<class T >
constexpr bool cpp17::is_nothrow_move_assignable_v

◆ is_nothrow_move_constructible_v

template<class T >
constexpr bool cpp17::is_nothrow_move_constructible_v

◆ is_trivially_assignable_v

template<class T , class U >
constexpr bool cpp17::is_trivially_assignable_v

◆ is_trivially_constructible_v

template<class T , class... Args>
constexpr bool cpp17::is_trivially_constructible_v

◆ is_trivially_copy_assignable_v

template<class T >
constexpr bool cpp17::is_trivially_copy_assignable_v

◆ is_trivially_copy_constructible_v

template<class T >
constexpr bool cpp17::is_trivially_copy_constructible_v

◆ is_trivially_default_constructible_v

template<class T >
constexpr bool cpp17::is_trivially_default_constructible_v

◆ is_trivially_move_assignable_v

template<class T >
constexpr bool cpp17::is_trivially_move_assignable_v

◆ is_trivially_move_constructible_v

template<class T >
constexpr bool cpp17::is_trivially_move_constructible_v