Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::type_identity< T > Class Template Reference

Polyfill of std::type_identity added in C++20. More...

Public Types

using type = T
 an alias for T
 

Detailed Description

template<typename T>
class arene::base::type_identity< T >

Polyfill of std::type_identity added in C++20.

Template Parameters
TThe type to preserve

Typically used to prevent parameters from being deduced in order to avoid ambiguities in type-deduction.

Can also be used as the identity metafunction in some template metaprogramming expressions.

For example:

/// @brief A function that takes two parameters of the same type
/// @tparam T The type of the arguments
template <typename T>
void foo(T, T);
/// @brief A function that takes two parameters of the same type, but only uses the first for type deduction
/// @tparam T The type of the arguments
template <typename T>
void example() {
// foo(1, 2u); // error: Ambiguous what T should deduce to.
foo(1u, 2u); // OK, T is deduced to unsigned
bar(1, 2u); // Ok. T is deduced to type of first argument only (i.e. int)
}

Member Typedef Documentation

◆ type

template<typename T>
using arene::base::type_identity< T >::type = T

an alias for T


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