Skip to content

Commit f1b7d00

Browse files
derekmaurocopybara-github
authored andcommitted
Remove the polyfill implementations for many type traits and alias
them to their std equivalents. It is recommended that clients now simple use the std equivalents. PiperOrigin-RevId: 731931492 Change-Id: I1f204dd659f12c4d9cc183f230ce13052a523625
1 parent b22423e commit f1b7d00

File tree

2 files changed

+27
-587
lines changed

2 files changed

+27
-587
lines changed

absl/meta/type_traits.h

Lines changed: 27 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,6 @@ struct is_detected_impl<typename VoidTImpl<Op<Args...>>::type, Op, Args...> {
9797
template <template <class...> class Op, class... Args>
9898
struct is_detected : is_detected_impl<void, Op, Args...>::type {};
9999

100-
template <class Enabler, class To, template <class...> class Op, class... Args>
101-
struct is_detected_convertible_impl {
102-
using type = std::false_type;
103-
};
104-
105-
template <class To, template <class...> class Op, class... Args>
106-
struct is_detected_convertible_impl<
107-
typename std::enable_if<std::is_convertible<Op<Args...>, To>::value>::type,
108-
To, Op, Args...> {
109-
using type = std::true_type;
110-
};
111-
112-
template <class To, template <class...> class Op, class... Args>
113-
struct is_detected_convertible
114-
: is_detected_convertible_impl<void, To, Op, Args...>::type {};
115-
116100
} // namespace type_traits_internal
117101

118102
// void_t()
@@ -121,103 +105,50 @@ struct is_detected_convertible
121105
// metafunction allows you to create a general case that maps to `void` while
122106
// allowing specializations that map to specific types.
123107
//
124-
// This metafunction is designed to be a drop-in replacement for the C++17
125-
// `std::void_t` metafunction.
126-
//
127-
// NOTE: `absl::void_t` does not use the standard-specified implementation so
128-
// that it can remain compatible with gcc < 5.1. This can introduce slightly
129-
// different behavior, such as when ordering partial specializations.
108+
// This metafunction is not 100% compatible with the C++17 `std::void_t`
109+
// metafunction. It has slightly different behavior, such as when ordering
110+
// partial specializations. It is recommended to use `std::void_t` instead.
130111
template <typename... Ts>
131112
using void_t = typename type_traits_internal::VoidTImpl<Ts...>::type;
132113

133-
// conjunction
134-
//
135-
// Performs a compile-time logical AND operation on the passed types (which
136-
// must have `::value` members convertible to `bool`. Short-circuits if it
137-
// encounters any `false` members (and does not compare the `::value` members
138-
// of any remaining arguments).
139-
//
140-
// This metafunction is designed to be a drop-in replacement for the C++17
141-
// `std::conjunction` metafunction.
142-
template <typename... Ts>
143-
struct conjunction : std::true_type {};
144-
145-
template <typename T, typename... Ts>
146-
struct conjunction<T, Ts...>
147-
: std::conditional<T::value, conjunction<Ts...>, T>::type {};
148-
149-
template <typename T>
150-
struct conjunction<T> : T {};
151-
152-
// disjunction
153-
//
154-
// Performs a compile-time logical OR operation on the passed types (which
155-
// must have `::value` members convertible to `bool`. Short-circuits if it
156-
// encounters any `true` members (and does not compare the `::value` members
157-
// of any remaining arguments).
158-
//
159-
// This metafunction is designed to be a drop-in replacement for the C++17
160-
// `std::disjunction` metafunction.
161-
template <typename... Ts>
162-
struct disjunction : std::false_type {};
163-
164-
template <typename T, typename... Ts>
165-
struct disjunction<T, Ts...>
166-
: std::conditional<T::value, T, disjunction<Ts...>>::type {};
167-
168-
template <typename T>
169-
struct disjunction<T> : T {};
170-
171-
// negation
172-
//
173-
// Performs a compile-time logical NOT operation on the passed type (which
174-
// must have `::value` members convertible to `bool`.
175-
//
176-
// This metafunction is designed to be a drop-in replacement for the C++17
177-
// `std::negation` metafunction.
178-
template <typename T>
179-
struct negation : std::integral_constant<bool, !T::value> {};
180-
181-
// is_function()
182-
//
183-
// Determines whether the passed type `T` is a function type.
184-
//
185-
// This metafunction is designed to be a drop-in replacement for the C++11
186-
// `std::is_function()` metafunction for platforms that have incomplete C++11
187-
// support (such as libstdc++ 4.x).
188-
//
189-
// This metafunction works because appending `const` to a type does nothing to
190-
// function types and reference types (and forms a const-qualified type
191-
// otherwise).
192-
template <typename T>
193-
struct is_function
194-
: std::integral_constant<
195-
bool, !(std::is_reference<T>::value ||
196-
std::is_const<typename std::add_const<T>::type>::value)> {};
197-
198-
// is_copy_assignable()
199-
// is_move_assignable()
200-
// is_trivially_destructible()
201-
// is_trivially_default_constructible()
202-
// is_trivially_move_constructible()
203-
// is_trivially_copy_constructible()
204-
// is_trivially_move_assignable()
205-
// is_trivially_copy_assignable()
206-
//
207114
// Historical note: Abseil once provided implementations of these type traits
208115
// for platforms that lacked full support. New code should prefer to use the
209116
// std variants.
210117
//
211118
// See the documentation for the STL <type_traits> header for more information:
212119
// https://en.cppreference.com/w/cpp/header/type_traits
120+
using std::add_const_t;
121+
using std::add_cv_t;
122+
using std::add_lvalue_reference_t;
123+
using std::add_pointer_t;
124+
using std::add_rvalue_reference_t;
125+
using std::add_volatile_t;
126+
using std::common_type_t;
127+
using std::conditional_t;
128+
using std::conjunction;
129+
using std::decay_t;
130+
using std::enable_if_t;
131+
using std::disjunction;
213132
using std::is_copy_assignable;
133+
using std::is_function;
214134
using std::is_move_assignable;
215135
using std::is_trivially_copy_assignable;
216136
using std::is_trivially_copy_constructible;
217137
using std::is_trivially_default_constructible;
218138
using std::is_trivially_destructible;
219139
using std::is_trivially_move_assignable;
220140
using std::is_trivially_move_constructible;
141+
using std::make_signed_t;
142+
using std::make_unsigned_t;
143+
using std::negation;
144+
using std::remove_all_extents_t;
145+
using std::remove_const_t;
146+
using std::remove_cv_t;
147+
using std::remove_extent_t;
148+
using std::remove_pointer_t;
149+
using std::remove_reference_t;
150+
using std::remove_volatile_t;
151+
using std::underlying_type_t;
221152

222153
#if defined(__cpp_lib_remove_cvref) && __cpp_lib_remove_cvref >= 201711L
223154
template <typename T>
@@ -240,70 +171,6 @@ template <typename T>
240171
using remove_cvref_t = typename remove_cvref<T>::type;
241172
#endif
242173

243-
// -----------------------------------------------------------------------------
244-
// C++14 "_t" trait aliases
245-
// -----------------------------------------------------------------------------
246-
247-
template <typename T>
248-
using remove_cv_t = typename std::remove_cv<T>::type;
249-
250-
template <typename T>
251-
using remove_const_t = typename std::remove_const<T>::type;
252-
253-
template <typename T>
254-
using remove_volatile_t = typename std::remove_volatile<T>::type;
255-
256-
template <typename T>
257-
using add_cv_t = typename std::add_cv<T>::type;
258-
259-
template <typename T>
260-
using add_const_t = typename std::add_const<T>::type;
261-
262-
template <typename T>
263-
using add_volatile_t = typename std::add_volatile<T>::type;
264-
265-
template <typename T>
266-
using remove_reference_t = typename std::remove_reference<T>::type;
267-
268-
template <typename T>
269-
using add_lvalue_reference_t = typename std::add_lvalue_reference<T>::type;
270-
271-
template <typename T>
272-
using add_rvalue_reference_t = typename std::add_rvalue_reference<T>::type;
273-
274-
template <typename T>
275-
using remove_pointer_t = typename std::remove_pointer<T>::type;
276-
277-
template <typename T>
278-
using add_pointer_t = typename std::add_pointer<T>::type;
279-
280-
template <typename T>
281-
using make_signed_t = typename std::make_signed<T>::type;
282-
283-
template <typename T>
284-
using make_unsigned_t = typename std::make_unsigned<T>::type;
285-
286-
template <typename T>
287-
using remove_extent_t = typename std::remove_extent<T>::type;
288-
289-
template <typename T>
290-
using remove_all_extents_t = typename std::remove_all_extents<T>::type;
291-
292-
template <typename T>
293-
using decay_t = typename std::decay<T>::type;
294-
295-
template <bool B, typename T = void>
296-
using enable_if_t = typename std::enable_if<B, T>::type;
297-
298-
template <bool B, typename T, typename F>
299-
using conditional_t = typename std::conditional<B, T, F>::type;
300-
301-
template <typename... T>
302-
using common_type_t = typename std::common_type<T...>::type;
303-
304-
template <typename T>
305-
using underlying_type_t = typename std::underlying_type<T>::type;
306-
307174
namespace type_traits_internal {
308175

309176
#if (defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703L) || \

0 commit comments

Comments
 (0)