Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <vector>
- namespace my {
- template <typename Iterator, typename U>
- int count(Iterator begin, Iterator end, const U& u) {
- int counter = 0;
- for(; begin != end; begin++) {
- if (u == *begin) {
- ++counter;
- }
- }
- return counter;
- }
- }
- int main() {
- std::vector<int> ints = {1, 2, 2, 3};
- std::vector<std::string> strings = {"ala", "ma", "kota", "ala"};
- std::cout << my::count(ints.begin(), ints.end(), 2) << '\n'
- << my::count(strings.begin(), strings.end(), "ala") << '\n';
- /*auto iterator = ints.begin();
- iterator += 2;
- --iterator;
- std::cout << *iterator;*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement