[PATCH] D132279: [ADT] Simplify llvm::reverse with constexpr if (NFC)
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 20 07:28:25 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0e0e6382493f: [ADT] Simplify llvm::reverse with constexpr if (NFC) (authored by kazu).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132279/new/
https://reviews.llvm.org/D132279
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
@@ -376,21 +376,12 @@
};
// Returns an iterator_range over the given container which iterates in reverse.
-// Note that the container must have rbegin()/rend() methods for this to work.
-template <typename ContainerTy>
-auto reverse(ContainerTy &&C,
- std::enable_if_t<has_rbegin<ContainerTy>::value> * = nullptr) {
- return make_range(C.rbegin(), C.rend());
-}
-
-// Returns an iterator_range over the given container which iterates in reverse.
-// Note that the container must have begin()/end() methods which return
-// bidirectional iterators for this to work.
-template <typename ContainerTy>
-auto reverse(ContainerTy &&C,
- std::enable_if_t<!has_rbegin<ContainerTy>::value> * = nullptr) {
- return make_range(std::make_reverse_iterator(std::end(C)),
- std::make_reverse_iterator(std::begin(C)));
+template <typename ContainerTy> auto reverse(ContainerTy &&C) {
+ if constexpr (has_rbegin<ContainerTy>::value)
+ return make_range(C.rbegin(), C.rend());
+ else
+ return make_range(std::make_reverse_iterator(std::end(C)),
+ std::make_reverse_iterator(std::begin(C)));
}
/// An iterator adaptor that filters the elements of given inner iterators.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132279.454210.patch
Type: text/x-patch
Size: 1418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220820/6c355bce/attachment.bin>
More information about the llvm-commits
mailing list