Changeset View
Changeset View
Standalone View
Standalone View
libcxx/include/__ranges/transform_view.h
// -*- C++ -*- | // -*- C++ -*- | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#ifndef _LIBCPP___RANGES_TRANSFORM_VIEW_H | #ifndef _LIBCPP___RANGES_TRANSFORM_VIEW_H | ||||
#define _LIBCPP___RANGES_TRANSFORM_VIEW_H | #define _LIBCPP___RANGES_TRANSFORM_VIEW_H | ||||
#include <__config> | #include <__config> | ||||
#include <__compare/three_way_comparable.h> | |||||
#include <__functional/bind_back.h> | #include <__functional/bind_back.h> | ||||
#include <__functional/invoke.h> | #include <__functional/invoke.h> | ||||
#include <__iterator/concepts.h> | #include <__iterator/concepts.h> | ||||
#include <__iterator/iter_swap.h> | #include <__iterator/iter_swap.h> | ||||
#include <__iterator/iterator_traits.h> | #include <__iterator/iterator_traits.h> | ||||
#include <__memory/addressof.h> | #include <__memory/addressof.h> | ||||
#include <__ranges/access.h> | #include <__ranges/access.h> | ||||
#include <__ranges/all.h> | #include <__ranges/all.h> | ||||
▲ Show 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | public: | ||||
_LIBCPP_HIDE_FROM_ABI | _LIBCPP_HIDE_FROM_ABI | ||||
constexpr decltype(auto) operator[](difference_type __n) const | constexpr decltype(auto) operator[](difference_type __n) const | ||||
noexcept(noexcept(_VSTD::invoke(*__parent_->__func_, __current_[__n]))) | noexcept(noexcept(_VSTD::invoke(*__parent_->__func_, __current_[__n]))) | ||||
requires random_access_range<_Base> | requires random_access_range<_Base> | ||||
{ | { | ||||
return _VSTD::invoke(*__parent_->__func_, __current_[__n]); | return _VSTD::invoke(*__parent_->__func_, __current_[__n]); | ||||
} | } | ||||
_LIBCPP_HIDE_FROM_ABI | _LIBCPP_HIDE_FROM_ABI | ||||
friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) | friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) | ||||
requires equality_comparable<iterator_t<_Base>> | requires equality_comparable<iterator_t<_Base>> | ||||
{ | { | ||||
return __x.__current_ == __y.__current_; | return __x.__current_ == __y.__current_; | ||||
} | } | ||||
Quuxplusone: I wonder if we should just replace this function body with `= default` instead. The only user… | |||||
_LIBCPP_HIDE_FROM_ABI | _LIBCPP_HIDE_FROM_ABI | ||||
friend constexpr bool operator<(const __iterator& __x, const __iterator& __y) | friend constexpr bool operator<(const __iterator& __x, const __iterator& __y) | ||||
requires random_access_range<_Base> | requires random_access_range<_Base> | ||||
{ | { | ||||
return __x.__current_ < __y.__current_; | return __x.__current_ < __y.__current_; | ||||
} | } | ||||
QuuxplusoneAuthorUnsubmitted Unfortunately, I am not convinced that it would be conforming to eliminate these redundant relational operators in the case that operator<=> exists. The user might have some clever way of observing whether it was actual-operator< or rewritten-candidate-operator<=> getting called. At least I'm not convinced that no such cleverness exists. Quuxplusone: Unfortunately, I am //not// convinced that it would be conforming to eliminate these redundant… | |||||
_LIBCPP_HIDE_FROM_ABI | _LIBCPP_HIDE_FROM_ABI | ||||
friend constexpr bool operator>(const __iterator& __x, const __iterator& __y) | friend constexpr bool operator>(const __iterator& __x, const __iterator& __y) | ||||
requires random_access_range<_Base> | requires random_access_range<_Base> | ||||
{ | { | ||||
return __x.__current_ > __y.__current_; | return __x.__current_ > __y.__current_; | ||||
} | } | ||||
_LIBCPP_HIDE_FROM_ABI | _LIBCPP_HIDE_FROM_ABI | ||||
friend constexpr bool operator<=(const __iterator& __x, const __iterator& __y) | friend constexpr bool operator<=(const __iterator& __x, const __iterator& __y) | ||||
requires random_access_range<_Base> | requires random_access_range<_Base> | ||||
{ | { | ||||
return __x.__current_ <= __y.__current_; | return __x.__current_ <= __y.__current_; | ||||
} | } | ||||
_LIBCPP_HIDE_FROM_ABI | _LIBCPP_HIDE_FROM_ABI | ||||
friend constexpr bool operator>=(const __iterator& __x, const __iterator& __y) | friend constexpr bool operator>=(const __iterator& __x, const __iterator& __y) | ||||
requires random_access_range<_Base> | requires random_access_range<_Base> | ||||
{ | { | ||||
return __x.__current_ >= __y.__current_; | return __x.__current_ >= __y.__current_; | ||||
} | } | ||||
// TODO: Fix this as soon as soon as three_way_comparable is implemented. | #if !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR) | ||||
// _LIBCPP_HIDE_FROM_ABI | _LIBCPP_HIDE_FROM_ABI | ||||
// friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y) | friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y) | ||||
// requires random_access_range<_Base> && three_way_comparable<iterator_t<_Base>> | requires random_access_range<_Base> && three_way_comparable<iterator_t<_Base>> | ||||
// { | { | ||||
// return __x.__current_ <=> __y.__current_; | return __x.__current_ <=> __y.__current_; | ||||
// } | } | ||||
#endif // !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR) | |||||
_LIBCPP_HIDE_FROM_ABI | _LIBCPP_HIDE_FROM_ABI | ||||
friend constexpr __iterator operator+(__iterator __i, difference_type __n) | friend constexpr __iterator operator+(__iterator __i, difference_type __n) | ||||
requires random_access_range<_Base> | requires random_access_range<_Base> | ||||
{ | { | ||||
return __iterator{*__i.__parent_, __i.__current_ + __n}; | return __iterator{*__i.__parent_, __i.__current_ + __n}; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |
I wonder if we should just replace this function body with = default instead. The only user-visible difference would be that it would become implicitly noexcept(auto) instead of noexcept(false).