[libcxx-commits] [PATCH] D121130: [libc++] Make common_iterator's proxy types into aggregates
Arthur O'Dwyer via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 7 08:48:45 PST 2022
Quuxplusone created this revision.
Quuxplusone added reviewers: ldionne, libc++.
Quuxplusone added a project: libc++.
Herald added a project: All.
Quuxplusone requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.
This is an alternative to one part of D120998 <https://reviews.llvm.org/D120998>; @ldionne, do you like this diff better than the corresponding diff in D120998 <https://reviews.llvm.org/D120998>?
This saves one move in each case, which is basically nothing perf-wise; this is more about simplifying the code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D121130
Files:
libcxx/include/__iterator/common_iterator.h
Index: libcxx/include/__iterator/common_iterator.h
===================================================================
--- libcxx/include/__iterator/common_iterator.h
+++ libcxx/include/__iterator/common_iterator.h
@@ -37,31 +37,18 @@
template<input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent>
requires (!same_as<_Iter, _Sent> && copyable<_Iter>)
class common_iterator {
- class __proxy {
- friend common_iterator;
-
- iter_value_t<_Iter> __value;
- // We can move __x because the only caller verifies that __x is not a reference.
- constexpr explicit __proxy(iter_reference_t<_Iter>&& __x)
- : __value(_VSTD::move(__x)) {}
-
- public:
+ struct __proxy {
constexpr const iter_value_t<_Iter>* operator->() const noexcept {
- return _VSTD::addressof(__value);
+ return _VSTD::addressof(__value_);
}
+ iter_value_t<_Iter> __value_;
};
- class __postfix_proxy {
- friend common_iterator;
-
- iter_value_t<_Iter> __value;
- constexpr explicit __postfix_proxy(iter_reference_t<_Iter>&& __x)
- : __value(_VSTD::forward<iter_reference_t<_Iter>>(__x)) {}
-
- public:
+ struct __postfix_proxy {
constexpr const iter_value_t<_Iter>& operator*() const noexcept {
- return __value;
+ return __value_;
}
+ iter_value_t<_Iter> __value_;
};
public:
@@ -133,7 +120,7 @@
auto&& __tmp = *_VSTD::__unchecked_get<_Iter>(__hold_);
return _VSTD::addressof(__tmp);
} else {
- return __proxy(*_VSTD::__unchecked_get<_Iter>(__hold_));
+ return __proxy{*_VSTD::__unchecked_get<_Iter>(__hold_)};
}
}
@@ -152,7 +139,7 @@
!__can_use_postfix_proxy<_Iter>) {
return _VSTD::__unchecked_get<_Iter>(__hold_)++;
} else {
- __postfix_proxy __p(**this);
+ auto __p = __postfix_proxy{**this};
++*this;
return __p;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121130.413504.patch
Type: text/x-patch
Size: 1891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220307/ea5c2c57/attachment.bin>
More information about the libcxx-commits
mailing list