Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use int = 0 SFINAE in <memory> to improve compiler throughput #2124

Merged
merged 14 commits into from
Aug 22, 2022
Merged
18 changes: 0 additions & 18 deletions stl/inc/functional
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,6 @@ private:
_Callable _Callee;
};

#ifdef __CUDACC__ // TRANSITION, CUDA
#define _USE_FUNCTION_INT_0_SFINAE 0
#else
#define _USE_FUNCTION_INT_0_SFINAE 1
#endif // __CUDACC__

template <class _Ret, class... _Types>
class _Func_class : public _Arg_types<_Types...> {
public:
Expand Down Expand Up @@ -1042,11 +1036,7 @@ public:
this->_Reset_copy(_Right);
}

#if _USE_FUNCTION_INT_0_SFINAE
template <class _Fx, typename _Mybase::template _Enable_if_callable_t<_Fx, function> = 0>
#else // ^^^ _USE_FUNCTION_INT_0_SFINAE // !_USE_FUNCTION_INT_0_SFINAE vvv
template <class _Fx, class = typename _Mybase::template _Enable_if_callable_t<_Fx, function>>
#endif // _USE_FUNCTION_INT_0_SFINAE
function(_Fx&& _Func) {
this->_Reset(_STD forward<_Fx>(_Func));
}
Expand All @@ -1063,11 +1053,7 @@ public:
this->_Reset_alloc(_Right, _Ax);
}

#if _USE_FUNCTION_INT_0_SFINAE
template <class _Fx, class _Alloc, typename _Mybase::template _Enable_if_callable_t<_Fx, function> = 0>
#else // ^^^ _USE_FUNCTION_INT_0_SFINAE // !_USE_FUNCTION_INT_0_SFINAE vvv
template <class _Fx, class _Alloc, class = typename _Mybase::template _Enable_if_callable_t<_Fx, function>>
#endif // _USE_FUNCTION_INT_0_SFINAE
function(allocator_arg_t, const _Alloc& _Ax, _Fx&& _Func) {
this->_Reset_alloc(_STD forward<_Fx>(_Func), _Ax);
}
Expand Down Expand Up @@ -1097,11 +1083,7 @@ public:
return *this;
}

#if _USE_FUNCTION_INT_0_SFINAE
template <class _Fx, typename _Mybase::template _Enable_if_callable_t<_Fx, function> = 0>
#else // ^^^ _USE_FUNCTION_INT_0_SFINAE // !_USE_FUNCTION_INT_0_SFINAE vvv
template <class _Fx, class = typename _Mybase::template _Enable_if_callable_t<_Fx, function>>
#endif // _USE_FUNCTION_INT_0_SFINAE
function& operator=(_Fx&& _Func) {
function(_STD forward<_Fx>(_Func)).swap(*this);
return *this;
Expand Down
26 changes: 14 additions & 12 deletions stl/inc/memory
Original file line number Diff line number Diff line change
Expand Up @@ -3311,21 +3311,22 @@ public:
template <class _Uty, class _Is_nullptr = is_same<_Uty, nullptr_t>>
using _Enable_ctor_reset =
enable_if_t<is_same_v<_Uty, pointer> //
|| _Is_nullptr::value //
|| (is_same_v<pointer, element_type*> //
&& is_pointer_v<_Uty> //
&& is_convertible_v<remove_pointer_t<_Uty> (*)[], element_type (*)[]>)>; // TRANSITION, GH-248
|| _Is_nullptr::value //
|| (is_same_v<pointer, element_type*> //
&& is_pointer_v<_Uty> //
&& is_convertible_v<remove_pointer_t<_Uty> (*)[], element_type (*)[]>),
int>;

template <class _Uty, class _Dx2 = _Dx, _Unique_ptr_enable_default_t<_Dx2> = 0, class = _Enable_ctor_reset<_Uty>>
template <class _Uty, class _Dx2 = _Dx, _Unique_ptr_enable_default_t<_Dx2> = 0, _Enable_ctor_reset<_Uty> = 0>
_CONSTEXPR23 explicit unique_ptr(_Uty _Ptr) noexcept : _Mypair(_Zero_then_variadic_args_t{}, _Ptr) {}

template <class _Uty, class _Dx2 = _Dx, enable_if_t<is_constructible_v<_Dx2, const _Dx2&>, int> = 0,
class = _Enable_ctor_reset<_Uty>>
_Enable_ctor_reset<_Uty> = 0>
_CONSTEXPR23 unique_ptr(_Uty _Ptr, const _Dx& _Dt) noexcept : _Mypair(_One_then_variadic_args_t{}, _Dt, _Ptr) {}

template <class _Uty, class _Dx2 = _Dx,
enable_if_t<conjunction_v<negation<is_reference<_Dx2>>, is_constructible<_Dx2, _Dx2>>, int> = 0,
class = _Enable_ctor_reset<_Uty>>
_Enable_ctor_reset<_Uty> = 0>
_CONSTEXPR23 unique_ptr(_Uty _Ptr, _Dx&& _Dt) noexcept
: _Mypair(_One_then_variadic_args_t{}, _STD move(_Dt), _Ptr) {}

Expand All @@ -3351,15 +3352,16 @@ public:
class _UP_element_type = typename unique_ptr<_Uty, _Ex>::element_type>
using _Enable_conversion = enable_if_t<
conjunction_v<is_array<_Uty>, is_same<pointer, element_type*>, is_same<_UP_pointer, _UP_element_type*>,
is_convertible<_UP_element_type (*)[], element_type (*)[]>, _More>>; // TRANSITION, GH-248
is_convertible<_UP_element_type (*)[], element_type (*)[]>, _More>,
int>;

template <class _Uty, class _Ex,
class = _Enable_conversion<_Uty, _Ex,
conditional_t<is_reference_v<_Dx>, is_same<_Ex, _Dx>, is_convertible<_Ex, _Dx>>>>
_Enable_conversion<_Uty, _Ex, conditional_t<is_reference_v<_Dx>, is_same<_Ex, _Dx>, is_convertible<_Ex, _Dx>>> =
0>
_CONSTEXPR23 unique_ptr(unique_ptr<_Uty, _Ex>&& _Right) noexcept
: _Mypair(_One_then_variadic_args_t{}, _STD forward<_Ex>(_Right.get_deleter()), _Right.release()) {}

template <class _Uty, class _Ex, class = _Enable_conversion<_Uty, _Ex, is_assignable<_Dx&, _Ex>>>
template <class _Uty, class _Ex, _Enable_conversion<_Uty, _Ex, is_assignable<_Dx&, _Ex>> = 0>
_CONSTEXPR23 unique_ptr& operator=(unique_ptr<_Uty, _Ex>&& _Right) noexcept {
reset(_Right.release());
_Mypair._Get_first() = _STD forward<_Ex>(_Right._Mypair._Get_first());
Expand Down Expand Up @@ -3413,7 +3415,7 @@ public:
return _STD exchange(_Mypair._Myval2, nullptr);
}

template <class _Uty, class = _Enable_ctor_reset<_Uty, false_type>>
template <class _Uty, _Enable_ctor_reset<_Uty, false_type> = 0>
_CONSTEXPR23 void reset(_Uty _Ptr) noexcept {
pointer _Old = _STD exchange(_Mypair._Myval2, _Ptr);
if (_Old) {
Expand Down