15 template <
typename Iterator,
typename T,
typename BinaryCompare>
16 Iterator
find(Iterator begin, Iterator end,
const T &value, BinaryCompare q) {
17 return std::find_if(begin, end, [&value, q](
const T &other) ->
bool {
18 return q(value, other);
23 template <
typename Iterator,
typename T>
25 return std::distance(begin,
std::find(begin, end, value));
29 template <
typename Iterator,
typename T,
typename BinaryCompare>
32 return std::distance(begin,
find(begin, end, value, q));
37 template <
typename Container,
typename T,
typename BinaryCompare>
39 return std::distance(container.begin(),
40 find(container.begin(), container.end(), value, q));
45 template <
typename Container,
typename T>
47 return std::distance(container.begin(),
48 std::find(container.begin(), container.end(), value));
52 template <
typename Iterator,
typename UnaryPredicate>
54 return std::distance(begin, std::find_if(begin, end, p));
59 template <
typename Container,
typename UnaryPredicate>
61 return std::distance(container.begin(),
62 std::find_if(container.begin(), container.end(), p));
66 template <
typename Iterator,
typename UnaryPredicate>
69 return std::distance(begin, std::find_if_not(begin, end, q));
74 template <
typename Container,
typename UnaryPredicate>
76 return std::distance(container.begin(),
77 std::find_if_not(container.begin(), container.end(), q));
82 template <
typename Container,
typename T>
83 bool contains(
const Container &container,
const T &value) {
84 return container.end() !=
85 std::find(container.begin(), container.end(), value);
90 template <
typename Container,
typename T,
typename BinaryCompare>
91 bool contains(
const Container &container,
const T &value, BinaryCompare q) {
92 return container.end() !=
find(container.begin(), container.end(), value, q);
97 template <
typename Container,
typename UnaryPredicate>
98 bool contains_if(
const Container &container, UnaryPredicate p) {
99 return container.end() != std::find_if(container.begin(), container.end(), p);
104 template <
typename Container,
typename UnaryPredicate>
106 return container.end() !=
107 std::find_if_not(container.begin(), container.end(), q);
111 template <
typename Container1,
typename Container2>
112 bool contains_all(
const Container1 &container,
const Container2 &values) {
113 for (
auto const &v : values)
114 if (!
contains(container, v))
return false;
121 template <
typename Container1,
typename Container2,
typename BinaryCompare>
122 bool contains_all(
const Container1 &container,
const Container2 &values,
124 for (
auto const &v : values)
125 if (!
contains(container, v, q))
return false;
130 template <
typename Container>
131 typename Container::value_type
sum(
132 const Container &container,
typename Container::value_type init_val = 0) {
133 for (
const auto &val : container) {
141 template <
typename T>
143 return container.data() + container.size();
148 template <
typename T>
149 T
const *
end_ptr(std::vector<T>
const &container) {
150 return container.data() + container.size();
Index find_index(Iterator begin, Iterator end, const T &value)
Equivalent to std::distance(begin, std::find(begin, end, value))
Container::value_type sum(const Container &container, typename Container::value_type init_val=0)
Index find_index_if(Iterator begin, Iterator end, UnaryPredicate p)
Equivalent to std::distance(begin, std::find_if(begin, end, p))
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.
bool contains_if_not(const Container &container, UnaryPredicate q)
Equivalent to container.end() != std::find_if_not(container.begin(), container.end(),...
bool contains(const Container &container, const T &value)
Equivalent to container.end() != std::find(container.begin(), container.end(), value)
T * end_ptr(std::vector< T > &container)
Return pointer one past end of vector. Equivalent to convainer.data()+container.size()
bool contains_if(const Container &container, UnaryPredicate p)
Equivalent to container.end() != std::find_if(container.begin(), container.end(), p)
INDEX_TYPE Index
For long integer indexing:
bool contains_all(const Container1 &container, const Container2 &values)
Returns true if each elements of 'values' is contained in 'container'.
Index find_index_if_not(Iterator begin, Iterator end, UnaryPredicate q)
Equivalent to std::distance(begin, std::find_if_not(begin, end, q))