Skip to content

Commit 5d84ee4

Browse files
committed
[libc++] Use enable_if_t to constrain make_unique{,_for_overwrite}
1 parent 05b6c2e commit 5d84ee4

File tree

5 files changed

+21
-38
lines changed

5 files changed

+21
-38
lines changed

libcxx/include/__memory/shared_ptr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ struct __unbounded_array_control_block<_Tp[], _Alloc> : __shared_weak_count {
957957
template <class _Array, class _Alloc, class... _Arg>
958958
_LIBCPP_HIDE_FROM_ABI shared_ptr<_Array>
959959
__allocate_shared_unbounded_array(const _Alloc& __a, size_t __n, _Arg&&... __arg) {
960-
static_assert(__libcpp_is_unbounded_array<_Array>::value);
960+
static_assert(__is_unbounded_array_v<_Array>);
961961
// We compute the number of bytes necessary to hold the control block and the
962962
// array elements. Then, we allocate an array of properly-aligned dummy structs
963963
// large enough to hold the control block and array. This allows shifting the
@@ -1034,7 +1034,7 @@ struct __bounded_array_control_block<_Tp[_Count], _Alloc> : __shared_weak_count
10341034

10351035
template <class _Array, class _Alloc, class... _Arg>
10361036
_LIBCPP_HIDE_FROM_ABI shared_ptr<_Array> __allocate_shared_bounded_array(const _Alloc& __a, _Arg&&... __arg) {
1037-
static_assert(__libcpp_is_bounded_array<_Array>::value);
1037+
static_assert(__is_bounded_array_v<_Array>);
10381038
using _ControlBlock = __bounded_array_control_block<_Array, _Alloc>;
10391039
using _ControlBlockAlloc = __allocator_traits_rebind_t<_Alloc, _ControlBlock>;
10401040

libcxx/include/__memory/uninitialized_algorithms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ __allocator_destroy_multidimensional(_Alloc& __alloc, _BidirIter __first, _Bidir
375375
return;
376376

377377
if constexpr (is_array_v<_ValueType>) {
378-
static_assert(!__libcpp_is_unbounded_array<_ValueType>::value,
378+
static_assert(!__is_unbounded_array_v<_ValueType>,
379379
"arrays of unbounded arrays don't exist, but if they did we would mess up here");
380380

381381
using _Element = remove_extent_t<_ValueType>;

libcxx/include/__memory/unique_ptr.h

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <__type_traits/integral_constant.h>
3131
#include <__type_traits/is_array.h>
3232
#include <__type_traits/is_assignable.h>
33+
#include <__type_traits/is_bounded_array.h>
3334
#include <__type_traits/is_constant_evaluated.h>
3435
#include <__type_traits/is_constructible.h>
3536
#include <__type_traits/is_convertible.h>
@@ -39,6 +40,7 @@
3940
#include <__type_traits/is_same.h>
4041
#include <__type_traits/is_swappable.h>
4142
#include <__type_traits/is_trivially_relocatable.h>
43+
#include <__type_traits/is_unbounded_array.h>
4244
#include <__type_traits/is_void.h>
4345
#include <__type_traits/remove_extent.h>
4446
#include <__type_traits/type_identity.h>
@@ -757,55 +759,36 @@ operator<=>(const unique_ptr<_T1, _D1>& __x, nullptr_t) {
757759

758760
#if _LIBCPP_STD_VER >= 14
759761

760-
template <class _Tp>
761-
struct __unique_if {
762-
typedef unique_ptr<_Tp> __unique_single;
763-
};
764-
765-
template <class _Tp>
766-
struct __unique_if<_Tp[]> {
767-
typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
768-
};
769-
770-
template <class _Tp, size_t _Np>
771-
struct __unique_if<_Tp[_Np]> {
772-
typedef void __unique_array_known_bound;
773-
};
774-
775-
template <class _Tp, class... _Args>
776-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_single
777-
make_unique(_Args&&... __args) {
762+
template <class _Tp, class... _Args, enable_if_t<!is_array<_Tp>::value, int> = 0>
763+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp> make_unique(_Args&&... __args) {
778764
return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...));
779765
}
780766

781-
template <class _Tp>
782-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_array_unknown_bound
783-
make_unique(size_t __n) {
767+
template <class _Tp, enable_if_t<__is_unbounded_array_v<_Tp>, int> = 0>
768+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp> make_unique(size_t __n) {
784769
typedef __remove_extent_t<_Tp> _Up;
785770
return unique_ptr<_Tp>(__private_constructor_tag(), new _Up[__n](), __n);
786771
}
787772

788-
template <class _Tp, class... _Args>
789-
typename __unique_if<_Tp>::__unique_array_known_bound make_unique(_Args&&...) = delete;
773+
template <class _Tp, class... _Args, enable_if_t<__is_bounded_array_v<_Tp>, int> = 0>
774+
void make_unique(_Args&&...) = delete;
790775

791776
#endif // _LIBCPP_STD_VER >= 14
792777

793778
#if _LIBCPP_STD_VER >= 20
794779

795-
template <class _Tp>
796-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_single
797-
make_unique_for_overwrite() {
780+
template <class _Tp, enable_if_t<!is_array_v<_Tp>, int> = 0>
781+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp> make_unique_for_overwrite() {
798782
return unique_ptr<_Tp>(new _Tp);
799783
}
800784

801-
template <class _Tp>
802-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_array_unknown_bound
803-
make_unique_for_overwrite(size_t __n) {
785+
template <class _Tp, enable_if_t<is_unbounded_array_v<_Tp>, int> = 0>
786+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp> make_unique_for_overwrite(size_t __n) {
804787
return unique_ptr<_Tp>(__private_constructor_tag(), new __remove_extent_t<_Tp>[__n], __n);
805788
}
806789

807-
template <class _Tp, class... _Args>
808-
typename __unique_if<_Tp>::__unique_array_known_bound make_unique_for_overwrite(_Args&&...) = delete;
790+
template <class _Tp, class... _Args, enable_if_t<is_bounded_array_v<_Tp>, int> = 0>
791+
void make_unique_for_overwrite(_Args&&...) = delete;
809792

810793
#endif // _LIBCPP_STD_VER >= 20
811794

libcxx/include/__type_traits/is_bounded_array.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
_LIBCPP_BEGIN_NAMESPACE_STD
2121

2222
template <class>
23-
struct _LIBCPP_TEMPLATE_VIS __libcpp_is_bounded_array : false_type {};
23+
inline const bool __is_bounded_array_v = false;
2424
template <class _Tp, size_t _Np>
25-
struct _LIBCPP_TEMPLATE_VIS __libcpp_is_bounded_array<_Tp[_Np]> : true_type {};
25+
inline const bool __is_bounded_array_v<_Tp[_Np]> = true;
2626

2727
#if _LIBCPP_STD_VER >= 20
2828

libcxx/include/__type_traits/is_unbounded_array.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
_LIBCPP_BEGIN_NAMESPACE_STD
2020

2121
template <class>
22-
struct _LIBCPP_TEMPLATE_VIS __libcpp_is_unbounded_array : false_type {};
22+
inline const bool __is_unbounded_array_v = false;
2323
template <class _Tp>
24-
struct _LIBCPP_TEMPLATE_VIS __libcpp_is_unbounded_array<_Tp[]> : true_type {};
24+
inline const bool __is_unbounded_array_v<_Tp[]> = true;
2525

2626
#if _LIBCPP_STD_VER >= 20
2727

0 commit comments

Comments
 (0)