[libcxx-commits] [PATCH] D102037: [libcxx][views] Add drop_view.
Tim Song via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jun 22 10:18:29 PDT 2021
tcanens added inline comments.
================
Comment at: libcxx/include/__ranges/drop_view.h:37
+
+ static constexpr bool _UseCache = forward_range<_View> && !random_access_range<_View>;
+ using _Cache = optional<iterator_t<_View>>;
----------------
zoecarver wrote:
> tcanens wrote:
> > The cache needs to be used for random access ranges too unless the range is also sized.
> Why does the range being sized matter? Doesn't a random access range provide amortized constant-time complexity for element lookup (which is the requirement for `drop_view`)?
You need the size of the underlying view to figure out how much to drop in constant time.
If you don't know that, then you have to advance the iterator one step at a time until you either reach the end of the range or N steps, and that's linear.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102037/new/
https://reviews.llvm.org/D102037
More information about the libcxx-commits
mailing list