Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
TypeTraits.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Foundation/PrimitiveTypes.h"
10
14
15namespace SC
16{
18namespace TypeTraits
19{
20// clang-format off
23
25template <bool B, class T = void> struct EnableIf {};
26template <class T> struct EnableIf<true, T> { using type = T; };
27
29template <typename T, typename U> struct IsSame { static constexpr bool value = false; };
30template <typename T> struct IsSame<T, T> { static constexpr bool value = true; };
31
33template <class T> struct AddPointer { using type = typename RemoveReference<T>::type*; };
34
36template <class T> struct RemoveConst { using type = T;};
37template <class T> struct RemoveConst<const T> { using type = T; };
38
40template <typename T> struct IsConst { using type = T; static constexpr bool value = false; };
41template <typename T> struct IsConst<const T> { using type = T; static constexpr bool value = true; };
42
44template <typename T> struct IsTriviallyCopyable { static constexpr bool value = __is_trivially_copyable(T); };
45
47template <bool B, class T, class F> struct Conditional { using type = T; };
48template <class T, class F> struct Conditional<false, T, F> { using type = F; };
49
51template <typename U, typename T> struct SameConstnessAs { using type = typename Conditional<IsConst<U>::value, const T, T>::type; };
52
54// clang-format on
55} // namespace TypeTraits
56} // namespace SC
AddPointer adds a pointer qualification to a type T if it is not already a pointer.
Definition TypeTraits.h:33
Conditional defines a type to be T if a boolean value is true, F otherwise.
Definition TypeTraits.h:47
EnableIf conditionally defines a type if a boolean template parameter is true.
Definition TypeTraits.h:25
IsConst evaluates to true if the provided type T is const, false otherwise.
Definition TypeTraits.h:40
IsSame evaluates to true if the provided types T and U are the same, false otherwise.
Definition TypeTraits.h:29
IsTriviallyCopyable evaluates to true if the type T can be trivially copied, false otherwise.
Definition TypeTraits.h:44
RemoveConst removes the const qualification from a type T.
Definition TypeTraits.h:36
SameConstnessAs modifies type T to have the const-qualification of U.
Definition TypeTraits.h:51