Reference documentation for deal.II version 9.6.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
std_cxx20::type_identity< T > Struct Template Reference

#include <deal.II/base/std_cxx20/type_traits.h>

Public Types

using type = T
 

Detailed Description

template<typename T>
struct std_cxx20::type_identity< T >

A template class that simply exports its template argument as a local alias. This class, while at first appearing useless, makes sense in the following context: if you have a function template as follows:

template <typename T>
void f(T, T);

then it can't be called in an expression like f(1, 3.141) because the type T of the template can not be deduced in a unique way from the types of the arguments. However, if the template is written as

template <typename T>
typename type_identity< T >::type type_identity_t
Definition type_traits.h:95

then the call becomes valid: the type T is not deducible from the second argument to the function, so only the first argument participates in template type resolution.

The context for this feature is as follows: consider

template <typename RT, typename A>
void forward_call(RT (*p) (A), A a)
{
p(a);
}
void h (double);
void g()
{
forward_call(&h, 1);
}

This code fails to compile because the compiler can't decide whether the template type A should be double (from the signature of the function given as first argument to forward_call, or int because the expression 1 has that type. Of course, what we would like the compiler to do is simply cast the 1 to double. We can achieve this by writing the code as follows:

template <typename RT, typename A>
void forward_call(RT (*p) (A), std_cxx20::type_identity_t<A> a)
{
p(a);
}
void h (double);
void g()
{
forward_call(&h, 1);
}

Definition at line 89 of file type_traits.h.

Member Typedef Documentation

◆ type

template<typename T >
using std_cxx20::type_identity< T >::type = T

Definition at line 91 of file type_traits.h.


The documentation for this struct was generated from the following file: