Test std::count and std::count_if

This commit is contained in:
Daniel Marjamäki 2016-11-02 09:57:35 +01:00
parent 12319d705e
commit fd67bbf2d3
1 changed files with 17 additions and 9 deletions

View File

@ -3168,43 +3168,51 @@ void nullPointer_wmemcmp(wchar_t *p)
#define pred [](int i){return i==0;} #define pred [](int i){return i==0;}
// <!-- InputIterator std::find(InputIterator first, InputIterator last, T val) --> void stdalgorithm(const std::list<int> &ints1, const std::list<int> &ints2)
// <!-- InputIterator std::find_if(InputIterator first, InputIterator last, UnaryPredicate val) -->
// <!-- InputIterator std::find_if_not(InputIterator first, InputIterator last, UnaryPredicate val) -->
void stdfind(const std::list<int> &ints1, const std::list<int> &ints2)
{ {
// <!-- InputIterator std::find(InputIterator first, InputIterator last, T val) -->
// cppcheck-suppress mismatchingContainers // cppcheck-suppress mismatchingContainers
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
std::find(ints1.begin(), ints2.end(), 123); std::find(ints1.begin(), ints2.end(), 123);
// cppcheck-suppress mismatchingContainers // cppcheck-suppress mismatchingContainers
if (std::find(ints1.begin(), ints1.end(), 123) == ints2.end()) {} if (std::find(ints1.begin(), ints1.end(), 123) == ints2.end()) {}
// <!-- InputIterator std::find_if(InputIterator first, InputIterator last, UnaryPredicate val) -->
// cppcheck-suppress mismatchingContainers // cppcheck-suppress mismatchingContainers
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
std::find_if(ints1.begin(), ints2.end(), pred); std::find_if(ints1.begin(), ints2.end(), pred);
// cppcheck-suppress mismatchingContainers // cppcheck-suppress mismatchingContainers
if (std::find_if(ints1.begin(), ints1.end(), pred) == ints2.end()) {} if (std::find_if(ints1.begin(), ints1.end(), pred) == ints2.end()) {}
// <!-- InputIterator std::find_if_not(InputIterator first, InputIterator last, UnaryPredicate val) -->
// cppcheck-suppress mismatchingContainers // cppcheck-suppress mismatchingContainers
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
std::find_if_not(ints1.begin(), ints2.end(), pred); std::find_if_not(ints1.begin(), ints2.end(), pred);
// cppcheck-suppress mismatchingContainers // cppcheck-suppress mismatchingContainers
if (std::find_if_not(ints1.begin(), ints1.end(), pred) == ints2.end()) {} if (std::find_if_not(ints1.begin(), ints1.end(), pred) == ints2.end()) {}
}
// <!-- bool std::all_of(InputIterator first, InputIterator last, UnaryPredicate pred) --> // <!-- bool std::all_of(InputIterator first, InputIterator last, UnaryPredicate pred) -->
// <!-- bool std::any_of(InputIterator first, InputIterator last, UnaryPredicate pred) -->
// <!-- bool std::none_of(InputIterator first, InputIterator last, UnaryPredicate pred) -->
void stdallof(const std::list<int> &ints1, const std::list<int> &ints2) {
// cppcheck-suppress mismatchingContainers // cppcheck-suppress mismatchingContainers
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
std::all_of(ints1.begin(), ints2.end(), pred); std::all_of(ints1.begin(), ints2.end(), pred);
// <!-- bool std::any_of(InputIterator first, InputIterator last, UnaryPredicate pred) -->
// cppcheck-suppress mismatchingContainers // cppcheck-suppress mismatchingContainers
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
std::any_of(ints1.begin(), ints2.end(), pred); std::any_of(ints1.begin(), ints2.end(), pred);
// <!-- bool std::none_of(InputIterator first, InputIterator last, UnaryPredicate pred) -->
// cppcheck-suppress mismatchingContainers // cppcheck-suppress mismatchingContainers
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
std::none_of(ints1.begin(), ints2.end(), pred); std::none_of(ints1.begin(), ints2.end(), pred);
// <!-- difference_type std::count(InputIterator first, InputIterator last, T val) -->
// cppcheck-suppress mismatchingContainers
// cppcheck-suppress ignoredReturnValue
std::count(ints1.begin(), ints2.end(), 123);
// <!-- difference_type std::count_if(InputIterator first, InputIterator last, UnaryPredicate val) -->
// cppcheck-suppress mismatchingContainers
// cppcheck-suppress ignoredReturnValue
std::count_if(ints1.begin(), ints2.end(), pred);
} }