-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_traits.hpp
79 lines (66 loc) · 4.92 KB
/
type_traits.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* type_traits.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mannouao <mannouao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/01 18:08:44 by mannouao #+# #+# */
/* Updated: 2022/07/29 15:14:31 by mannouao ### ########.fr */
/* */
/* ************************************************************************** */
# ifndef TYPE_TRAITS_HPP
# define TYPE_TRAITS_HPP
# include <__config>
# include "utility.hpp"
# include <iterator>
namespace ft
{
// enable_if ---------------------------------------------------------------------------------------------------------------------------
template <bool, typename _Tp = void> struct enable_if { };
template <typename _Tp> struct enable_if<true, _Tp> { typedef _Tp type; };
// -------------------------------------------------------------------------------------------------------------------------------------
// integral_constant -------------------------------------------------------------------------------------------------------------------
template<typename _Tp, _Tp __v>
struct integral_constant
{
static const _Tp value = __v;
typedef _Tp value_type;
typedef integral_constant type;
operator value_type() const { return value; }
};
typedef ft::integral_constant<bool, true> true_type; // true_type
typedef ft::integral_constant<bool, false> false_type; // false_type
// -------------------------------------------------------------------------------------------------------------------------------------
// remove_const ------------------------------------------------------------------------------------------------------------------------
template<typename _Tp> struct remove_const { typedef _Tp type; };
template<typename _Tp> struct remove_const <const _Tp> { typedef _Tp type; };
// -------------------------------------------------------------------------------------------------------------------------------------
// remove_volatile ---------------------------------------------------------------------------------------------------------------------
template<typename _Tp> struct remove_volatile { typedef _Tp type; };
template<typename _Tp> struct remove_volatile <volatile _Tp> { typedef _Tp type; };
// -------------------------------------------------------------------------------------------------------------------------------------
// remove_cv ---------------------------------------------------------------------------------------------------------------------------
template<typename _Tp> struct remove_cv { typedef typename ft::remove_volatile<typename ft::remove_const<_Tp>::type>::type type; };
// -------------------------------------------------------------------------------------------------------------------------------------
// is_integral -------------------------------------------------------------------------------------------------------------------------
template<typename _Tp> struct tmp_is_integral : public ft::false_type {};
template<> struct tmp_is_integral<bool> : public ft::true_type {};
template<> struct tmp_is_integral<char> : public ft::true_type {};
template<> struct tmp_is_integral<signed char> : public ft::true_type {};
template<> struct tmp_is_integral<unsigned char> : public ft::true_type {};
template<> struct tmp_is_integral<wchar_t> : public ft::true_type {};
template<> struct tmp_is_integral<char16_t> : public ft::true_type {};
template<> struct tmp_is_integral<char32_t> : public ft::true_type {};
template<> struct tmp_is_integral<short> : public ft::true_type {};
template<> struct tmp_is_integral<unsigned short> : public ft::true_type {};
template<> struct tmp_is_integral<int> : public ft::true_type {};
template<> struct tmp_is_integral<unsigned int> : public ft::true_type {};
template<> struct tmp_is_integral<long> : public ft::true_type {};
template<> struct tmp_is_integral<unsigned long> : public ft::true_type {};
template<> struct tmp_is_integral<long long> : public ft::true_type {};
template<> struct tmp_is_integral<unsigned long long> : public ft::true_type {};
template<typename _Tp> struct is_integral : public tmp_is_integral<typename ft::remove_cv<_Tp>::type> {};
// -------------------------------------------------------------------------------------------------------------------------------------
} // ft
# endif