• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15 
16 #include <type_traits>
17 
18 #include "pw_polyfill/standard_library/namespace.h"
19 
20 _PW_POLYFILL_BEGIN_NAMESPACE_STD
21 
22 // Defines std:foo_t aliases for typename foo::type. This is a small subset of
23 // <type_traits> which may be expanded as needed.
24 #ifndef __cpp_lib_transformation_trait_aliases
25 #define __cpp_lib_transformation_trait_aliases 201304L
26 
27 template <decltype(sizeof(int)) Len, decltype(sizeof(int)) Align>
28 using aligned_storage_t = typename aligned_storage<Len, Align>::type;
29 
30 template <typename... T>
31 using common_type_t = typename common_type<T...>::type;
32 
33 template <bool B, typename T, typename F>
34 using conditional_t = typename conditional<B, T, F>::type;
35 
36 template <typename T>
37 using decay_t = typename decay<T>::type;
38 
39 template <bool B, typename T = void>
40 using enable_if_t = typename enable_if<B, T>::type;
41 
42 template <typename T>
43 using make_signed_t = typename make_signed<T>::type;
44 
45 template <typename T>
46 using make_unsigned_t = typename make_unsigned<T>::type;
47 
48 template <typename T>
49 using remove_cv_t = typename remove_cv<T>::type;
50 
51 template <typename T>
52 using remove_pointer_t = typename remove_pointer<T>::type;
53 
54 template <typename T>
55 using remove_reference_t = typename remove_reference<T>::type;
56 
57 #endif  // __cpp_lib_transformation_trait_aliases
58 
59 #ifndef __cpp_lib_is_null_pointer
60 #define __cpp_lib_is_null_pointer 201309L
61 
62 template <typename T>
63 struct is_null_pointer : std::is_same<decltype(nullptr), std::remove_cv_t<T>> {
64 };
65 
66 #endif  // __cpp_lib_is_null_pointer
67 
68 #ifndef __cpp_lib_bool_constant
69 #define __cpp_lib_bool_constant 201505L
70 template <bool value>
71 using bool_constant = integral_constant<bool, value>;
72 #endif  // __cpp_lib_bool_constant
73 
74 #ifndef __cpp_lib_logical_traits
75 #define __cpp_lib_logical_traits 201510L
76 template <typename value>
77 struct negation : bool_constant<!bool(value::value)> {};
78 
79 template <typename...>
80 struct conjunction : std::true_type {};
81 template <typename B1>
82 struct conjunction<B1> : B1 {};
83 template <typename B1, typename... Bn>
84 struct conjunction<B1, Bn...>
85     : std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
86 
87 template <typename...>
88 struct disjunction : std::false_type {};
89 template <typename B1>
90 struct disjunction<B1> : B1 {};
91 template <typename B1, typename... Bn>
92 struct disjunction<B1, Bn...>
93     : std::conditional_t<bool(B1::value), B1, disjunction<Bn...>> {};
94 
95 #endif  // __cpp_lib_logical_traits
96 
97 _PW_POLYFILL_END_NAMESPACE_STD
98