[PATCH] D65788: [ADT] Remove O(1) requirement to range passed to llvm::size
Alex Brachet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 21:39:31 PDT 2019
abrachet created this revision.
abrachet added reviewers: jhenderson, rupprecht, MaskRay, shchenz, rriddle.
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.
None of the other wrappers around the algorithms have this requirement that the iterators should be bidirectional, llvm::size shouldn't either.
https://reviews.llvm.org/D65788
Files:
llvm/include/llvm/ADT/STLExtras.h
Index: llvm/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -1167,15 +1167,10 @@
C.clear();
}
-/// Get the size of a range. This is a wrapper function around std::distance
-/// which is only enabled when the operation is O(1).
+/// Provide wrappers to std::distance which take ranges instead of having to
+/// pass begin/end explicitly.
template <typename R>
-auto size(R &&Range, typename std::enable_if<
- std::is_same<typename std::iterator_traits<decltype(
- Range.begin())>::iterator_category,
- std::random_access_iterator_tag>::value,
- void>::type * = nullptr)
- -> decltype(std::distance(Range.begin(), Range.end())) {
+auto size(R &&Range) -> decltype(std::distance(Range.begin(), Range.end())) {
return std::distance(Range.begin(), Range.end());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65788.213518.patch
Type: text/x-patch
Size: 1029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190806/caeda177/attachment.bin>
More information about the llvm-commits
mailing list