Index: include/llvm/ADT/STLExtras.h =================================================================== --- include/llvm/ADT/STLExtras.h +++ include/llvm/ADT/STLExtras.h @@ -347,8 +347,8 @@ } // forward declarations required by zip_shortest/zip_first -template -bool all_of(R &&range, UnaryPredicate &&P); +template +bool all_of(R &&range, UnaryPredicate P); template struct index_sequence; @@ -570,8 +570,8 @@ /// container. template void DeleteContainerPointers(Container &C) { - for (typename Container::iterator I = C.begin(), E = C.end(); I != E; ++I) - delete *I; + for (auto I : C) + delete I; C.clear(); } @@ -579,82 +579,79 @@ /// deletes the second elements and then clears the container. template void DeleteContainerSeconds(Container &C) { - for (typename Container::iterator I = C.begin(), E = C.end(); I != E; ++I) - delete I->second; + for (auto &I : C) + delete I.second; C.clear(); } /// Provide wrappers to std::all_of which take ranges instead of having to pass /// begin/end explicitly. -template -bool all_of(R &&Range, UnaryPredicate &&P) { - return std::all_of(Range.begin(), Range.end(), - std::forward(P)); +template +bool all_of(R &&Range, UnaryPredicate P) { + return std::all_of(std::begin(Range), std::end(Range), P); } /// Provide wrappers to std::any_of which take ranges instead of having to pass /// begin/end explicitly. -template -bool any_of(R &&Range, UnaryPredicate &&P) { - return std::any_of(Range.begin(), Range.end(), - std::forward(P)); +template +bool any_of(R &&Range, UnaryPredicate P) { + return std::any_of(std::begin(Range), std::end(Range), P); } /// Provide wrappers to std::none_of which take ranges instead of having to pass /// begin/end explicitly. -template -bool none_of(R &&Range, UnaryPredicate &&P) { - return std::none_of(Range.begin(), Range.end(), - std::forward(P)); +template +bool none_of(R &&Range, UnaryPredicate P) { + return std::none_of(std::begin(Range), std::end(Range), P); } /// Provide wrappers to std::find which take ranges instead of having to pass /// begin/end explicitly. -template -auto find(R &&Range, const T &val) -> decltype(Range.begin()) { - return std::find(Range.begin(), Range.end(), val); +template +auto find(R &&Range, const T &Val) -> decltype(std::begin(Range)) { + return std::find(std::begin(Range), std::end(Range), Val); } /// Provide wrappers to std::find_if which take ranges instead of having to pass /// begin/end explicitly. -template -auto find_if(R &&Range, const T &Pred) -> decltype(Range.begin()) { - return std::find_if(Range.begin(), Range.end(), Pred); +template +auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range)) { + return std::find_if(std::begin(Range), std::end(Range), P); } -template -auto find_if_not(R &&Range, PredicateT Pred) -> decltype(Range.begin()) { - return std::find_if_not(Range.begin(), Range.end(), Pred); +template +auto find_if_not(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range)) { + return std::find_if_not(std::begin(Range), std::end(Range), P); } /// Provide wrappers to std::remove_if which take ranges instead of having to /// pass begin/end explicitly. -template -auto remove_if(R &&Range, UnaryPredicate &&P) -> decltype(Range.begin()) { - return std::remove_if(Range.begin(), Range.end(), P); +template +auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range)) { + return std::remove_if(std::begin(Range), std::end(Range), P); } /// Wrapper function around std::find to detect if an element exists /// in a container. template bool is_contained(R &&Range, const E &Element) { - return std::find(Range.begin(), Range.end(), Element) != Range.end(); + return std::find(std::begin(Range), std::end(Range), Element) != + std::end(Range); } /// Wrapper function around std::count_if to count the number of times an /// element satisfying a given predicate occurs in a range. template -auto count_if(R &&Range, UnaryPredicate &&P) - -> typename std::iterator_traits::difference_type { - return std::count_if(Range.begin(), Range.end(), P); +auto count_if(R &&Range, UnaryPredicate P) -> typename std::iterator_traits< + decltype(std::begin(Range))>::difference_type { + return std::count_if(std::begin(Range), std::end(Range), P); } /// Wrapper function around std::transform to apply a function to a range and /// store the result elsewhere. -template -OutputIt transform(R &&Range, OutputIt d_first, UnaryPredicate &&P) { - return std::transform(Range.begin(), Range.end(), d_first, - std::forward(P)); +template +OutputIt transform(R &&Range, OutputIt d_first, UnaryPredicate P) { + return std::transform(std::begin(Range), std::end(Range), d_first, P); } //===----------------------------------------------------------------------===//