type_traits
#
Header: <pressio/type_traits.hpp>
Public namespace: pressio
Scope#
Provides functionalities for type introspection and detection. One of the main design features of pressio is that it supports arbitrary types via generic programming and type introspection, but also provides special support for some data types commonly used.
Traits class#
todo: finish
One of the most important things inside type_traits
is the Traits
class:
namespace pressio{
template<class T, class = void> struct Traits;
}
To understand the purpose and usage of the traits pattern in C++ there are several resources online.
Quoting Bjarne Stroustrup: “Think of a trait as a small object whose main purpose
is to carry information used by another object or algorithm
to determine “policy” or “implementation details”.
Pressio uses specializations of this class to gather in a uniform way
compile-time information enabling it to reason about types.
The key point here is that different TPLs use a variety of naming conventions
for nested typedefs and related things, so there is not easy way to access
similar information from types of various libraries.
This is what motivated us to implement this type_traits
component.
We need a standard, uniform way to query types for compile-time information.
We currently have traits specialized for types of a few TPLs, like Trilinos, Kokkos, Eigen.
An example of one such specialization (in this case for Eigen) is:
template <typename T>
struct Traits<
T, ::pressio::mpl::enable_if_t<is_dynamic_vector_eigen<T>::value>
>
{
using scalar_type = typename T::Scalar;
static constexpr int rank = 1;
};
This Traits
class play a key role when users want to use arbitrary types (i.e. types
which are not known to presso) and to do so, users shoud specialize this class and make
these specialization visibile to pressio to provide information about their generic types.
For practical examples of how this class is used, see:
finish
Type detection and identification#
We support several metafunctions for detecting data types commonly used from existing TPLs. The following list is partial, and more will be added as we continue the development.
Name |
Description |
---|---|
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |
|
Provides static member constant |