Skip to content

Commit f966e89

Browse files
committed
[libc++][NFC] Replace structs with variable templates in <__memory/allocator_traits.h>
1 parent 1adb001 commit f966e89

File tree

5 files changed

+64
-84
lines changed

5 files changed

+64
-84
lines changed

libcxx/include/__flat_map/flat_map.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <__functional/invoke.h>
3434
#include <__functional/is_transparent.h>
3535
#include <__functional/operations.h>
36+
#include <__fwd/memory.h>
3637
#include <__fwd/vector.h>
3738
#include <__iterator/concepts.h>
3839
#include <__iterator/distance.h>

libcxx/include/__memory/allocator_traits.h

Lines changed: 49 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ using __is_always_equal _LIBCPP_NODEBUG =
149149
// __allocator_traits_rebind
150150
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
151151
template <class _Tp, class _Up, class = void>
152-
struct __has_rebind_other : false_type {};
152+
inline const bool __has_rebind_other_v = false;
153153
template <class _Tp, class _Up>
154-
struct __has_rebind_other<_Tp, _Up, __void_t<typename _Tp::template rebind<_Up>::other> > : true_type {};
154+
inline const bool __has_rebind_other_v<_Tp, _Up, __void_t<typename _Tp::template rebind<_Up>::other> > = true;
155155

156-
template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
156+
template <class _Tp, class _Up, bool = __has_rebind_other_v<_Tp, _Up> >
157157
struct __allocator_traits_rebind {
158-
static_assert(__has_rebind_other<_Tp, _Up>::value, "This allocator has to implement rebind");
158+
static_assert(__has_rebind_other_v<_Tp, _Up>, "This allocator has to implement rebind");
159159
using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other;
160160
};
161161
template <template <class, class...> class _Alloc, class _Tp, class... _Args, class _Up>
@@ -173,53 +173,52 @@ using __allocator_traits_rebind_t _LIBCPP_NODEBUG = typename __allocator_traits_
173173

174174
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
175175

176-
// __has_allocate_hint
176+
// __has_allocate_hint_v
177177
template <class _Alloc, class _SizeType, class _ConstVoidPtr, class = void>
178-
struct __has_allocate_hint : false_type {};
178+
inline const bool __has_allocate_hint_v = false;
179179

180180
template <class _Alloc, class _SizeType, class _ConstVoidPtr>
181-
struct __has_allocate_hint<
181+
inline const bool __has_allocate_hint_v<
182182
_Alloc,
183183
_SizeType,
184184
_ConstVoidPtr,
185-
decltype((void)std::declval<_Alloc>().allocate(std::declval<_SizeType>(), std::declval<_ConstVoidPtr>()))>
186-
: true_type {};
185+
decltype((void)std::declval<_Alloc>().allocate(std::declval<_SizeType>(), std::declval<_ConstVoidPtr>()))> = true;
187186

188-
// __has_construct
187+
// __has_construct_v
189188
template <class, class _Alloc, class... _Args>
190-
struct __has_construct_impl : false_type {};
189+
inline const bool __has_construct_impl = false;
191190

192191
template <class _Alloc, class... _Args>
193-
struct __has_construct_impl<decltype((void)std::declval<_Alloc>().construct(std::declval<_Args>()...)),
194-
_Alloc,
195-
_Args...> : true_type {};
192+
inline const bool
193+
__has_construct_impl<decltype((void)std::declval<_Alloc>().construct(std::declval<_Args>()...)), _Alloc, _Args...> =
194+
true;
196195

197196
template <class _Alloc, class... _Args>
198-
struct __has_construct : __has_construct_impl<void, _Alloc, _Args...> {};
197+
inline const bool __has_construct_v = __has_construct_impl<void, _Alloc, _Args...>;
199198

200-
// __has_destroy
199+
// __has_destroy_v
201200
template <class _Alloc, class _Pointer, class = void>
202-
struct __has_destroy : false_type {};
201+
inline const bool __has_destroy_v = false;
203202

204203
template <class _Alloc, class _Pointer>
205-
struct __has_destroy<_Alloc, _Pointer, decltype((void)std::declval<_Alloc>().destroy(std::declval<_Pointer>()))>
206-
: true_type {};
204+
inline const bool
205+
__has_destroy_v<_Alloc, _Pointer, decltype((void)std::declval<_Alloc>().destroy(std::declval<_Pointer>()))> = true;
207206

208-
// __has_max_size
207+
// __has_max_size_v
209208
template <class _Alloc, class = void>
210-
struct __has_max_size : false_type {};
209+
inline const bool __has_max_size_v = false;
211210

212211
template <class _Alloc>
213-
struct __has_max_size<_Alloc, decltype((void)std::declval<_Alloc&>().max_size())> : true_type {};
212+
inline const bool __has_max_size_v<_Alloc, decltype((void)std::declval<_Alloc&>().max_size())> = true;
214213

215-
// __has_select_on_container_copy_construction
214+
// __has_select_on_container_copy_construction_v
216215
template <class _Alloc, class = void>
217-
struct __has_select_on_container_copy_construction : false_type {};
216+
inline const bool __has_select_on_container_copy_construction_v = false;
218217

219218
template <class _Alloc>
220-
struct __has_select_on_container_copy_construction<
219+
inline const bool __has_select_on_container_copy_construction_v<
221220
_Alloc,
222-
decltype((void)std::declval<_Alloc>().select_on_container_copy_construction())> : true_type {};
221+
decltype((void)std::declval<_Alloc>().select_on_container_copy_construction())> = true;
223222

224223
_LIBCPP_SUPPRESS_DEPRECATED_POP
225224

@@ -270,16 +269,14 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {
270269
return __a.allocate(__n);
271270
}
272271

273-
template <class _Ap = _Alloc, __enable_if_t<__has_allocate_hint<_Ap, size_type, const_void_pointer>::value, int> = 0>
272+
template <class _Ap = _Alloc, __enable_if_t<__has_allocate_hint_v<_Ap, size_type, const_void_pointer>, int> = 0>
274273
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
275274
allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) {
276275
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
277276
return __a.allocate(__n, __hint);
278277
_LIBCPP_SUPPRESS_DEPRECATED_POP
279278
}
280-
template <class _Ap = _Alloc,
281-
class = void,
282-
__enable_if_t<!__has_allocate_hint<_Ap, size_type, const_void_pointer>::value, int> = 0>
279+
template <class _Ap = _Alloc, __enable_if_t<!__has_allocate_hint_v<_Ap, size_type, const_void_pointer>, int> = 0>
283280
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
284281
allocate(allocator_type& __a, size_type __n, const_void_pointer) {
285282
return __a.allocate(__n);
@@ -302,52 +299,47 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {
302299
__a.deallocate(__p, __n);
303300
}
304301

305-
template <class _Tp, class... _Args, __enable_if_t<__has_construct<allocator_type, _Tp*, _Args...>::value, int> = 0>
302+
template <class _Tp, class... _Args, __enable_if_t<__has_construct_v<allocator_type, _Tp*, _Args...>, int> = 0>
306303
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void
307304
construct(allocator_type& __a, _Tp* __p, _Args&&... __args) {
308305
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
309306
__a.construct(__p, std::forward<_Args>(__args)...);
310307
_LIBCPP_SUPPRESS_DEPRECATED_POP
311308
}
312-
template <class _Tp,
313-
class... _Args,
314-
class = void,
315-
__enable_if_t<!__has_construct<allocator_type, _Tp*, _Args...>::value, int> = 0>
309+
template <class _Tp, class... _Args, __enable_if_t<!__has_construct_v<allocator_type, _Tp*, _Args...>, int> = 0>
316310
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void
317311
construct(allocator_type&, _Tp* __p, _Args&&... __args) {
318312
std::__construct_at(__p, std::forward<_Args>(__args)...);
319313
}
320314

321-
template <class _Tp, __enable_if_t<__has_destroy<allocator_type, _Tp*>::value, int> = 0>
315+
template <class _Tp, __enable_if_t<__has_destroy_v<allocator_type, _Tp*>, int> = 0>
322316
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void destroy(allocator_type& __a, _Tp* __p) {
323317
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
324318
__a.destroy(__p);
325319
_LIBCPP_SUPPRESS_DEPRECATED_POP
326320
}
327-
template <class _Tp, class = void, __enable_if_t<!__has_destroy<allocator_type, _Tp*>::value, int> = 0>
321+
template <class _Tp, __enable_if_t<!__has_destroy_v<allocator_type, _Tp*>, int> = 0>
328322
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void destroy(allocator_type&, _Tp* __p) {
329323
std::__destroy_at(__p);
330324
}
331325

332-
template <class _Ap = _Alloc, __enable_if_t<__has_max_size<const _Ap>::value, int> = 0>
326+
template <class _Ap = _Alloc, __enable_if_t<__has_max_size_v<const _Ap>, int> = 0>
333327
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type max_size(const allocator_type& __a) _NOEXCEPT {
334328
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
335329
return __a.max_size();
336330
_LIBCPP_SUPPRESS_DEPRECATED_POP
337331
}
338-
template <class _Ap = _Alloc, class = void, __enable_if_t<!__has_max_size<const _Ap>::value, int> = 0>
332+
template <class _Ap = _Alloc, __enable_if_t<!__has_max_size_v<const _Ap>, int> = 0>
339333
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type max_size(const allocator_type&) _NOEXCEPT {
340334
return numeric_limits<size_type>::max() / sizeof(value_type);
341335
}
342336

343-
template <class _Ap = _Alloc, __enable_if_t<__has_select_on_container_copy_construction<const _Ap>::value, int> = 0>
337+
template <class _Ap = _Alloc, __enable_if_t<__has_select_on_container_copy_construction_v<const _Ap>, int> = 0>
344338
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static allocator_type
345339
select_on_container_copy_construction(const allocator_type& __a) {
346340
return __a.select_on_container_copy_construction();
347341
}
348-
template <class _Ap = _Alloc,
349-
class = void,
350-
__enable_if_t<!__has_select_on_container_copy_construction<const _Ap>::value, int> = 0>
342+
template <class _Ap = _Alloc, __enable_if_t<!__has_select_on_container_copy_construction_v<const _Ap>, int> = 0>
351343
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static allocator_type
352344
select_on_container_copy_construction(const allocator_type& __a) {
353345
return __a;
@@ -370,40 +362,27 @@ struct __check_valid_allocator : true_type {
370362
"original allocator");
371363
};
372364

373-
// __is_default_allocator
365+
// __is_default_allocator_v
374366
template <class _Tp>
375-
struct __is_default_allocator : false_type {};
376-
377-
template <class>
378-
class allocator;
367+
inline const bool __is_std_allocator_v = false;
379368

380369
template <class _Tp>
381-
struct __is_default_allocator<allocator<_Tp> > : true_type {};
382-
383-
// __is_cpp17_move_insertable
384-
template <class _Alloc, class = void>
385-
struct __is_cpp17_move_insertable : is_move_constructible<typename _Alloc::value_type> {};
370+
inline const bool __is_std_allocator_v<allocator<_Tp> > = true;
386371

372+
// __is_cpp17_move_insertable_v
387373
template <class _Alloc>
388-
struct __is_cpp17_move_insertable<
389-
_Alloc,
390-
__enable_if_t< !__is_default_allocator<_Alloc>::value &&
391-
__has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value > >
392-
: true_type {};
393-
394-
// __is_cpp17_copy_insertable
395-
template <class _Alloc, class = void>
396-
struct __is_cpp17_copy_insertable
397-
: integral_constant<bool,
398-
is_copy_constructible<typename _Alloc::value_type>::value &&
399-
__is_cpp17_move_insertable<_Alloc>::value > {};
374+
inline const bool __is_cpp17_move_insertable_v =
375+
is_move_constructible<typename _Alloc::value_type>::value ||
376+
(!__is_std_allocator_v<_Alloc> &&
377+
__has_construct_v<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>);
400378

379+
// __is_cpp17_copy_insertable_v
401380
template <class _Alloc>
402-
struct __is_cpp17_copy_insertable<
403-
_Alloc,
404-
__enable_if_t< !__is_default_allocator<_Alloc>::value &&
405-
__has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value > >
406-
: __is_cpp17_move_insertable<_Alloc> {};
381+
inline const bool __is_cpp17_copy_insertable_v =
382+
__is_cpp17_move_insertable_v<_Alloc> &&
383+
(is_copy_constructible<typename _Alloc::value_type>::value ||
384+
(!__is_std_allocator_v<_Alloc> &&
385+
__has_construct_v<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>));
407386

408387
#undef _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX
409388

libcxx/include/__memory/uninitialized_algorithms.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <__algorithm/unwrap_range.h>
1717
#include <__config>
1818
#include <__cstddef/size_t.h>
19+
#include <__fwd/memory.h>
1920
#include <__iterator/iterator_traits.h>
2021
#include <__iterator/reverse_iterator.h>
2122
#include <__memory/addressof.h>
@@ -32,7 +33,6 @@
3233
#include <__type_traits/is_trivially_constructible.h>
3334
#include <__type_traits/is_trivially_relocatable.h>
3435
#include <__type_traits/is_unbounded_array.h>
35-
#include <__type_traits/negation.h>
3636
#include <__type_traits/remove_const.h>
3737
#include <__type_traits/remove_extent.h>
3838
#include <__utility/exception_guard.h>
@@ -549,17 +549,17 @@ __uninitialized_allocator_copy_impl(_Alloc& __alloc, _Iter1 __first1, _Sent1 __l
549549
}
550550

551551
template <class _Alloc, class _Type>
552-
struct __allocator_has_trivial_copy_construct : _Not<__has_construct<_Alloc, _Type*, const _Type&> > {};
552+
inline const bool __allocator_has_trivial_copy_construct_v = !__has_construct_v<_Alloc, _Type*, const _Type&>;
553553

554554
template <class _Type>
555-
struct __allocator_has_trivial_copy_construct<allocator<_Type>, _Type> : true_type {};
555+
inline const bool __allocator_has_trivial_copy_construct_v<allocator<_Type>, _Type> = true;
556556

557557
template <class _Alloc,
558558
class _In,
559559
class _Out,
560560
__enable_if_t<is_trivially_copy_constructible<_In>::value && is_trivially_copy_assignable<_In>::value &&
561561
is_same<__remove_const_t<_In>, __remove_const_t<_Out> >::value &&
562-
__allocator_has_trivial_copy_construct<_Alloc, _In>::value,
562+
__allocator_has_trivial_copy_construct_v<_Alloc, _In>,
563563
int> = 0>
564564
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Out*
565565
__uninitialized_allocator_copy_impl(_Alloc&, _In* __first1, _In* __last1, _Out* __first2) {
@@ -585,16 +585,16 @@ __uninitialized_allocator_copy(_Alloc& __alloc, _Iter1 __first1, _Sent1 __last1,
585585
}
586586

587587
template <class _Alloc, class _Type>
588-
struct __allocator_has_trivial_move_construct : _Not<__has_construct<_Alloc, _Type*, _Type&&> > {};
588+
inline const bool __allocator_has_trivial_move_construct_v = !__has_construct_v<_Alloc, _Type*, _Type&&>;
589589

590590
template <class _Type>
591-
struct __allocator_has_trivial_move_construct<allocator<_Type>, _Type> : true_type {};
591+
inline const bool __allocator_has_trivial_move_construct_v<allocator<_Type>, _Type> = true;
592592

593593
template <class _Alloc, class _Tp>
594-
struct __allocator_has_trivial_destroy : _Not<__has_destroy<_Alloc, _Tp*> > {};
594+
inline const bool __allocator_has_trivial_destroy_v = !__has_destroy_v<_Alloc, _Tp*>;
595595

596596
template <class _Tp, class _Up>
597-
struct __allocator_has_trivial_destroy<allocator<_Tp>, _Up> : true_type {};
597+
inline const bool __allocator_has_trivial_destroy_v<allocator<_Tp>, _Up> = true;
598598

599599
// __uninitialized_allocator_relocate relocates the objects in [__first, __last) into __result.
600600
// Relocation means that the objects in [__first, __last) are placed into __result as-if by move-construct and destroy,
@@ -613,11 +613,11 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __uninitialized_allocat
613613
_Alloc& __alloc, _ContiguousIterator __first, _ContiguousIterator __last, _ContiguousIterator __result) {
614614
static_assert(__libcpp_is_contiguous_iterator<_ContiguousIterator>::value, "");
615615
using _ValueType = typename iterator_traits<_ContiguousIterator>::value_type;
616-
static_assert(__is_cpp17_move_insertable<_Alloc>::value,
617-
"The specified type does not meet the requirements of Cpp17MoveInsertable");
616+
static_assert(
617+
__is_cpp17_move_insertable_v<_Alloc>, "The specified type does not meet the requirements of Cpp17MoveInsertable");
618618
if (__libcpp_is_constant_evaluated() || !__libcpp_is_trivially_relocatable<_ValueType>::value ||
619-
!__allocator_has_trivial_move_construct<_Alloc, _ValueType>::value ||
620-
!__allocator_has_trivial_destroy<_Alloc, _ValueType>::value) {
619+
!__allocator_has_trivial_move_construct_v<_Alloc, _ValueType> ||
620+
!__allocator_has_trivial_destroy_v<_Alloc, _ValueType>) {
621621
auto __destruct_first = __result;
622622
auto __guard = std::__make_exception_guard(
623623
_AllocatorDestroyRangeReverse<_Alloc, _ContiguousIterator>(__alloc, __destruct_first, __result));

libcxx/include/__vector/container_traits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct __container_traits<vector<_Tp, _Allocator> > {
3131
// there are no effects. Otherwise, if an exception is thrown by the move constructor of a non-Cpp17CopyInsertable T,
3232
// the effects are unspecified.
3333
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
34-
_Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value;
34+
is_nothrow_move_constructible<_Tp>::value || __is_cpp17_copy_insertable_v<_Allocator>;
3535
};
3636

3737
_LIBCPP_END_NAMESPACE_STD

libcxx/include/deque

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,7 @@ struct __container_traits<deque<_Tp, _Allocator> > {
26252625
// either end, there are no effects. Otherwise, if an exception is thrown by the move constructor of a
26262626
// non-Cpp17CopyInsertable T, the effects are unspecified.
26272627
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
2628-
_Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value;
2628+
is_nothrow_move_constructible<_Tp>::value || __is_cpp17_copy_insertable_v<_Allocator>;
26292629
};
26302630

26312631
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)