-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount.cpp
More file actions
64 lines (57 loc) · 1.44 KB
/
Copy pathcount.cpp
File metadata and controls
64 lines (57 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "count.h"
template <typename T2>
T2 pyfunc::count(std::string source, std::string search) {
size_t end_index;
size_t search_len = search.length();
T2 count = 0;
while ((end_index = source.find(search)) != -1) {
count++;
source = source.substr(end_index + search_len);
}
return count;
}
template <typename T2>
T2 pyfunc::count(std::string source, char search_) {
std::string search = (std::string)"" + search_;
return pyfunc::count<T2>(source, search);
}
template <typename T, typename T2>
T2 pyfunc::count(std::vector<T> source, T search) {
T2 count = 0;
for (T src : source) {
if (src == search) {
count++;
}
}
return count;
}
template <typename T, typename T2>
T2 pyfunc::count(T* source, size_t size, T search) {
T2 count = 0;
for (size_t index = 0; index < size; index++) {
if (*source++ == search) {
count++;
}
}
return count;
}
template <typename T, typename T2>
T2 pyfunc::count(const T* source, size_t size, T search) {
T2 count = 0;
for (size_t index = 0; index < size; index++) {
if (*source++ == search) {
count++;
}
}
return count;
}
template <typename T, size_t size, typename T2>
T2 pyfunc::count(std::array<T, size> source, T search) {
T2 count = 0;
for (T src : source) {
if (src == search) {
count++;
}
}
return count;
}