diff --git a/libcxx/include/__functional/bind_back.h b/libcxx/include/__functional/bind_back.h --- a/libcxx/include/__functional/bind_back.h +++ b/libcxx/include/__functional/bind_back.h @@ -31,12 +31,15 @@ template struct __bind_back_op<_NBound, index_sequence<_Ip...>> { - template - _LIBCPP_HIDE_FROM_ABI - constexpr auto operator()(_Fn&& __f, _Bound&& __bound, _Args&& ...__args) const - noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_Bound>(__bound))...))) - -> decltype( _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_Bound>(__bound))...)) - { return _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_Bound>(__bound))...); } + template + _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&& __f, _BoundArgs&& __bound_args, _Args&&... __args) const + noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., + _VSTD::get<_Ip>(_VSTD::forward<_BoundArgs>(__bound_args))...))) + -> decltype(_VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., + _VSTD::get<_Ip>(_VSTD::forward<_BoundArgs>(__bound_args))...)) { + return _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., + _VSTD::get<_Ip>(_VSTD::forward<_BoundArgs>(__bound_args))...); + } }; template diff --git a/libcxx/include/__functional/perfect_forward.h b/libcxx/include/__functional/perfect_forward.h --- a/libcxx/include/__functional/perfect_forward.h +++ b/libcxx/include/__functional/perfect_forward.h @@ -25,63 +25,64 @@ #if _LIBCPP_STD_VER > 14 -template +template struct __perfect_forward_impl; -template -struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _Bound...> { +template +struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _BoundArgs...> { private: - tuple<_Bound...> __bound_; + tuple<_BoundArgs...> __bound_args_; public: - template , _BoundArgs&&...> - >> - explicit constexpr __perfect_forward_impl(_BoundArgs&& ...__bound) - : __bound_(_VSTD::forward<_BoundArgs>(__bound)...) - { } - - __perfect_forward_impl(__perfect_forward_impl const&) = default; - __perfect_forward_impl(__perfect_forward_impl&&) = default; - - __perfect_forward_impl& operator=(__perfect_forward_impl const&) = default; - __perfect_forward_impl& operator=(__perfect_forward_impl&&) = default; - - template >> - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) & - noexcept(noexcept(_Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...))) - -> decltype( _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...)) - { return _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...); } - - template >> - auto operator()(_Args&&...) & = delete; - - template >> - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const& - noexcept(noexcept(_Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...))) - -> decltype( _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...)) - { return _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...); } - - template >> - auto operator()(_Args&&...) const& = delete; - - template >> - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) && - noexcept(noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...))) - -> decltype( _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...)) - { return _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...); } - - template >> - auto operator()(_Args&&...) && = delete; - - template >> - _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&& - noexcept(noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...))) - -> decltype( _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...)) - { return _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...); } - - template >> - auto operator()(_Args&&...) const&& = delete; + template , _Args&&...>>> + explicit constexpr __perfect_forward_impl(_Args&&... __bound_args) + : __bound_args_(_VSTD::forward<_Args>(__bound_args)...) {} + + __perfect_forward_impl(__perfect_forward_impl const&) = default; + __perfect_forward_impl(__perfect_forward_impl&&) = default; + + __perfect_forward_impl& operator=(__perfect_forward_impl const&) = default; + __perfect_forward_impl& operator=(__perfect_forward_impl&&) = default; + + template >> + _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) & noexcept( + noexcept(_Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...))) + -> decltype(_Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...)) { + return _Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...); + } + + template >> + auto operator()(_Args&&...) & = delete; + + template >> + _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const& noexcept( + noexcept(_Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...))) + -> decltype(_Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...)) { + return _Op()(_VSTD::get<_Idx>(__bound_args_)..., _VSTD::forward<_Args>(__args)...); + } + + template >> + auto operator()(_Args&&...) const& = delete; + + template >> + _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) && noexcept( + noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...))) + -> decltype(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...)) { + return _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...); + } + + template >> + auto operator()(_Args&&...) && = delete; + + template >> + _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&& noexcept( + noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...))) + -> decltype(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...)) { + return _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_args_))..., _VSTD::forward<_Args>(__args)...); + } + + template >> + auto operator()(_Args&&...) const&& = delete; }; // __perfect_forward implements a perfect-forwarding call wrapper as explained in [func.require]. diff --git a/libcxx/include/__iterator/advance.h b/libcxx/include/__iterator/advance.h --- a/libcxx/include/__iterator/advance.h +++ b/libcxx/include/__iterator/advance.h @@ -117,47 +117,46 @@ } } - // Preconditions: Either `assignable_from || sized_sentinel_for` is modeled, or [i, bound) denotes a range. + // Preconditions: Either `assignable_from || sized_sentinel_for` is modeled, or [i, bound_sentinel) denotes a range. template _Sp> - _LIBCPP_HIDE_FROM_ABI - constexpr void operator()(_Ip& __i, _Sp __bound) const { - // If `I` and `S` model `assignable_from`, equivalent to `i = std::move(bound)`. + _LIBCPP_HIDE_FROM_ABI constexpr void operator()(_Ip& __i, _Sp __bound_sentinel) const { + // If `I` and `S` model `assignable_from`, equivalent to `i = std::move(bound_sentinel)`. if constexpr (assignable_from<_Ip&, _Sp>) { - __i = _VSTD::move(__bound); + __i = _VSTD::move(__bound_sentinel); } - // Otherwise, if `S` and `I` model `sized_sentinel_for`, equivalent to `ranges::advance(i, bound - i)`. + // Otherwise, if `S` and `I` model `sized_sentinel_for`, equivalent to `ranges::advance(i, bound_sentinel - i)`. else if constexpr (sized_sentinel_for<_Sp, _Ip>) { - (*this)(__i, __bound - __i); + (*this)(__i, __bound_sentinel - __i); } - // Otherwise, while `bool(i != bound)` is true, increments `i`. + // Otherwise, while `bool(i != bound_sentinel)` is true, increments `i`. else { - while (__i != __bound) { + while (__i != __bound_sentinel) { ++__i; } } } // Preconditions: - // * If `n > 0`, [i, bound) denotes a range. - // * If `n == 0`, [i, bound) or [bound, i) denotes a range. - // * If `n < 0`, [bound, i) denotes a range, `I` models `bidirectional_iterator`, and `I` and `S` model `same_as`. + // * If `n > 0`, [i, bound_sentinel) denotes a range. + // * If `n == 0`, [i, bound_sentinel) or [bound_sentinel, i) denotes a range. + // * If `n < 0`, [bound_sentinel, i) denotes a range, `I` models `bidirectional_iterator`, and `I` and `S` model `same_as`. // Returns: `n - M`, where `M` is the difference between the ending and starting position. template _Sp> - _LIBCPP_HIDE_FROM_ABI - constexpr iter_difference_t<_Ip> operator()(_Ip& __i, iter_difference_t<_Ip> __n, _Sp __bound) const { + _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip& __i, iter_difference_t<_Ip> __n, + _Sp __bound_sentinel) const { _LIBCPP_ASSERT((__n >= 0) || (bidirectional_iterator<_Ip> && same_as<_Ip, _Sp>), "If `n < 0`, then `bidirectional_iterator && same_as` must be true."); // If `S` and `I` model `sized_sentinel_for`: if constexpr (sized_sentinel_for<_Sp, _Ip>) { - // If |n| >= |bound - i|, equivalent to `ranges::advance(i, bound)`. + // If |n| >= |bound_sentinel - i|, equivalent to `ranges::advance(i, bound_sentinel)`. // __magnitude_geq(a, b) returns |a| >= |b|, assuming they have the same sign. auto __magnitude_geq = [](auto __a, auto __b) { return __a == 0 ? __b == 0 : __a > 0 ? __a >= __b : __a <= __b; }; - if (const auto __M = __bound - __i; __magnitude_geq(__n, __M)) { - (*this)(__i, __bound); + if (const auto __M = __bound_sentinel - __i; __magnitude_geq(__n, __M)) { + (*this)(__i, __bound_sentinel); return __n - __M; } @@ -165,16 +164,16 @@ (*this)(__i, __n); return 0; } else { - // Otherwise, if `n` is non-negative, while `bool(i != bound)` is true, increments `i` but at + // Otherwise, if `n` is non-negative, while `bool(i != bound_sentinel)` is true, increments `i` but at // most `n` times. - while (__i != __bound && __n > 0) { + while (__i != __bound_sentinel && __n > 0) { ++__i; --__n; } - // Otherwise, while `bool(i != bound)` is true, decrements `i` but at most `-n` times. + // Otherwise, while `bool(i != bound_sentinel)` is true, decrements `i` but at most `-n` times. if constexpr (bidirectional_iterator<_Ip> && same_as<_Ip, _Sp>) { - while (__i != __bound && __n < 0) { + while (__i != __bound_sentinel && __n < 0) { --__i; ++__n; } diff --git a/libcxx/include/__iterator/next.h b/libcxx/include/__iterator/next.h --- a/libcxx/include/__iterator/next.h +++ b/libcxx/include/__iterator/next.h @@ -58,16 +58,14 @@ } template _Sp> - _LIBCPP_HIDE_FROM_ABI - constexpr _Ip operator()(_Ip __x, _Sp __bound) const { - ranges::advance(__x, __bound); + _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const { + ranges::advance(__x, __bound_sentinel); return __x; } template _Sp> - _LIBCPP_HIDE_FROM_ABI - constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound) const { - ranges::advance(__x, __n, __bound); + _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const { + ranges::advance(__x, __n, __bound_sentinel); return __x; } }; diff --git a/libcxx/include/__iterator/prev.h b/libcxx/include/__iterator/prev.h --- a/libcxx/include/__iterator/prev.h +++ b/libcxx/include/__iterator/prev.h @@ -57,9 +57,8 @@ } template - _LIBCPP_HIDE_FROM_ABI - constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Ip __bound) const { - ranges::advance(__x, -__n, __bound); + _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Ip __bound_iter) const { + ranges::advance(__x, -__n, __bound_iter); return __x; } }; diff --git a/libcxx/include/__ranges/iota_view.h b/libcxx/include/__ranges/iota_view.h --- a/libcxx/include/__ranges/iota_view.h +++ b/libcxx/include/__ranges/iota_view.h @@ -90,9 +90,9 @@ using iterator_category = input_iterator_tag; }; - template - requires __weakly_equality_comparable_with<_Start, _Bound> && copyable<_Start> - class iota_view : public view_interface> { + template + requires __weakly_equality_comparable_with<_Start, _BoundSentinel> && copyable<_Start> + class iota_view : public view_interface> { struct __iterator : public __iota_iterator_category<_Start> { friend class iota_view; @@ -271,35 +271,35 @@ friend class iota_view; private: - _Bound __bound_ = _Bound(); + _BoundSentinel __bound_sentinel_ = _BoundSentinel(); public: _LIBCPP_HIDE_FROM_ABI __sentinel() = default; - constexpr explicit __sentinel(_Bound __bound) : __bound_(std::move(__bound)) {} + constexpr explicit __sentinel(_BoundSentinel __bound_sentinel) : __bound_sentinel_(std::move(__bound_sentinel)) {} _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const __iterator& __x, const __sentinel& __y) { - return __x.__value_ == __y.__bound_; + return __x.__value_ == __y.__bound_sentinel_; } _LIBCPP_HIDE_FROM_ABI friend constexpr iter_difference_t<_Start> operator-(const __iterator& __x, const __sentinel& __y) - requires sized_sentinel_for<_Bound, _Start> + requires sized_sentinel_for<_BoundSentinel, _Start> { - return __x.__value_ - __y.__bound_; + return __x.__value_ - __y.__bound_sentinel_; } _LIBCPP_HIDE_FROM_ABI friend constexpr iter_difference_t<_Start> operator-(const __sentinel& __x, const __iterator& __y) - requires sized_sentinel_for<_Bound, _Start> + requires sized_sentinel_for<_BoundSentinel, _Start> { return -(__y - __x); } }; _Start __value_ = _Start(); - _Bound __bound_ = _Bound(); + _BoundSentinel __bound_sentinel_ = _BoundSentinel(); public: _LIBCPP_HIDE_FROM_ABI @@ -309,75 +309,76 @@ constexpr explicit iota_view(_Start __value) : __value_(std::move(__value)) { } _LIBCPP_HIDE_FROM_ABI - constexpr iota_view(type_identity_t<_Start> __value, type_identity_t<_Bound> __bound) - : __value_(std::move(__value)), __bound_(std::move(__bound)) { + constexpr iota_view(type_identity_t<_Start> __value, type_identity_t<_BoundSentinel> __bound_sentinel) + : __value_(std::move(__value)), __bound_sentinel_(std::move(__bound_sentinel)) { // Validate the precondition if possible. - if constexpr (totally_ordered_with<_Start, _Bound>) { - _LIBCPP_ASSERT(ranges::less_equal()(__value_, __bound_), + if constexpr (totally_ordered_with<_Start, _BoundSentinel>) { + _LIBCPP_ASSERT(ranges::less_equal()(__value_, __bound_sentinel_), "Precondition violated: value is greater than bound."); } } _LIBCPP_HIDE_FROM_ABI constexpr iota_view(__iterator __first, __iterator __last) - requires same_as<_Start, _Bound> - : iota_view(std::move(__first.__value_), std::move(__last.__value_)) {} + requires same_as<_Start, _BoundSentinel> + : iota_view(std::move(__first.__value_), std::move(__last.__value_)) {} _LIBCPP_HIDE_FROM_ABI - constexpr iota_view(__iterator __first, _Bound __last) - requires same_as<_Bound, unreachable_sentinel_t> - : iota_view(std::move(__first.__value_), std::move(__last)) {} + constexpr iota_view(__iterator __first, _BoundSentinel __last) + requires same_as<_BoundSentinel, unreachable_sentinel_t> + : iota_view(std::move(__first.__value_), std::move(__last)) {} _LIBCPP_HIDE_FROM_ABI constexpr iota_view(__iterator __first, __sentinel __last) - requires (!same_as<_Start, _Bound> && !same_as<_Start, unreachable_sentinel_t>) - : iota_view(std::move(__first.__value_), std::move(__last.__bound_)) {} + requires(!same_as<_Start, _BoundSentinel> && !same_as<_Start, unreachable_sentinel_t>) + : iota_view(std::move(__first.__value_), std::move(__last.__bound_sentinel_)) {} _LIBCPP_HIDE_FROM_ABI constexpr __iterator begin() const { return __iterator{__value_}; } _LIBCPP_HIDE_FROM_ABI constexpr auto end() const { - if constexpr (same_as<_Bound, unreachable_sentinel_t>) + if constexpr (same_as<_BoundSentinel, unreachable_sentinel_t>) return unreachable_sentinel; else - return __sentinel{__bound_}; + return __sentinel{__bound_sentinel_}; } _LIBCPP_HIDE_FROM_ABI - constexpr __iterator end() const requires same_as<_Start, _Bound> { - return __iterator{__bound_}; + constexpr __iterator end() const + requires same_as<_Start, _BoundSentinel> + { + return __iterator{__bound_sentinel_}; } _LIBCPP_HIDE_FROM_ABI constexpr auto size() const - requires (same_as<_Start, _Bound> && __advanceable<_Start>) || - (integral<_Start> && integral<_Bound>) || - sized_sentinel_for<_Bound, _Start> + requires(same_as<_Start, _BoundSentinel> && __advanceable<_Start>) || + (integral<_Start> && integral<_BoundSentinel>) || sized_sentinel_for<_BoundSentinel, _Start> { - if constexpr (__integer_like<_Start> && __integer_like<_Bound>) { + if constexpr (__integer_like<_Start> && __integer_like<_BoundSentinel>) { if (__value_ < 0) { - if (__bound_ < 0) { - return std::__to_unsigned_like(-__value_) - std::__to_unsigned_like(-__bound_); + if (__bound_sentinel_ < 0) { + return std::__to_unsigned_like(-__value_) - std::__to_unsigned_like(-__bound_sentinel_); } - return std::__to_unsigned_like(__bound_) + std::__to_unsigned_like(-__value_); + return std::__to_unsigned_like(__bound_sentinel_) + std::__to_unsigned_like(-__value_); } - return std::__to_unsigned_like(__bound_) - std::__to_unsigned_like(__value_); + return std::__to_unsigned_like(__bound_sentinel_) - std::__to_unsigned_like(__value_); } - return std::__to_unsigned_like(__bound_ - __value_); + return std::__to_unsigned_like(__bound_sentinel_ - __value_); } }; - template - requires (!__integer_like<_Start> || !__integer_like<_Bound> || - (__signed_integer_like<_Start> == __signed_integer_like<_Bound>)) - iota_view(_Start, _Bound) -> iota_view<_Start, _Bound>; + template + requires(!__integer_like<_Start> || !__integer_like<_BoundSentinel> || + (__signed_integer_like<_Start> == __signed_integer_like<_BoundSentinel>)) + iota_view(_Start, _BoundSentinel) -> iota_view<_Start, _BoundSentinel>; - template - inline constexpr bool enable_borrowed_range> = true; + template + inline constexpr bool enable_borrowed_range> = true; -namespace views { -namespace __iota { + namespace views { + namespace __iota { struct __fn { template _LIBCPP_HIDE_FROM_ABI @@ -386,12 +387,12 @@ -> decltype( ranges::iota_view(std::forward<_Start>(__start))) { return ranges::iota_view(std::forward<_Start>(__start)); } - template - _LIBCPP_HIDE_FROM_ABI - constexpr auto operator()(_Start&& __start, _Bound&& __bound) const - noexcept(noexcept(ranges::iota_view(std::forward<_Start>(__start), std::forward<_Bound>(__bound)))) - -> decltype( ranges::iota_view(std::forward<_Start>(__start), std::forward<_Bound>(__bound))) - { return ranges::iota_view(std::forward<_Start>(__start), std::forward<_Bound>(__bound)); } + template + _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Start&& __start, _BoundSentinel&& __bound_sentinel) const noexcept( + noexcept(ranges::iota_view(std::forward<_Start>(__start), std::forward<_BoundSentinel>(__bound_sentinel)))) + -> decltype(ranges::iota_view(std::forward<_Start>(__start), std::forward<_BoundSentinel>(__bound_sentinel))) { + return ranges::iota_view(std::forward<_Start>(__start), std::forward<_BoundSentinel>(__bound_sentinel)); + } }; } // namespace __iota diff --git a/libcxx/test/libcxx/nasty_macros.compile.pass.cpp b/libcxx/test/libcxx/nasty_macros.compile.pass.cpp --- a/libcxx/test/libcxx/nasty_macros.compile.pass.cpp +++ b/libcxx/test/libcxx/nasty_macros.compile.pass.cpp @@ -78,6 +78,7 @@ // Obviously we can only define these on non-Windows platforms. #ifndef _WIN32 # define __allocator NASTY_MACRO +# define __bound NASTY_MACRO # define __deallocate NASTY_MACRO # define __deref NASTY_MACRO # define __full NASTY_MACRO