Skip to content

[gardening] Remove unneeded implementations of none_of/count_if/count. #6059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions include/swift/Basic/Range.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <utility>
#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"

namespace swift {
using llvm::make_range;
Expand Down Expand Up @@ -268,33 +269,6 @@ template <class T> EnumeratorRange<T> enumerate(T Begin, T End) {
return EnumeratorRange<T>(Begin, End);
}

/// An adaptor of std::none_of for ranges.
template <class Range, class Predicate>
inline bool none_of(const Range &R, Predicate &&P) {
return std::none_of(R.begin(), R.end(), std::forward<Predicate>(P));
}

/// An adaptor of std::count for ranges.
///
/// We use std::result_of on Range::begin since llvm::iterator_range does not
/// have a public typedef set to what is the underlying iterator.
//typename std::iterator_traits<decltype(&Range::begin())>::difference_type
template <class Range, class Value>
inline auto count(const Range &R, Value V)
-> typename std::iterator_traits<decltype(R.begin())>::difference_type {
return std::count(R.begin(), R.end(), V);
}

/// An adaptor of std::count_if for ranges.
///
/// We use std::result_of on Range::begin since llvm::iterator_range does not
/// have a public typedef set to what is the underlying iterator.
template <class Range, class Predicate>
inline auto count_if(const Range &R, Predicate &&P)
-> typename std::iterator_traits<decltype(R.begin())>::difference_type {
return std::count_if(R.begin(), R.end(), std::forward<Predicate>(P));
}

} // end namespace swift

#endif // SWIFT_BASIC_RANGE_H
3 changes: 2 additions & 1 deletion unittests/Basic/BlotMapVectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
#include <map>
Expand Down Expand Up @@ -254,7 +255,7 @@ bool CtorTesterSet::hasLiveTesters() const {
}

bool CtorTesterSet::numLiveTesters() const {
return count_if(Constructed, [](CtorTester *T) -> bool {
return llvm::count_if(Constructed, [](CtorTester *T) -> bool {
assert(T);
return !T->isIgnorableTester();
});
Expand Down