26#ifndef MYSQL_HARNESS_UTILITY_CONTAINER_GENERIC_H_
27#define MYSQL_HARNESS_UTILITY_CONTAINER_GENERIC_H_
39template <
typename Container,
typename Value =
typename Container::value_type>
40typename Container::const_iterator
find(
const Container &c, Value &&
value) {
44template <
typename Container,
typename Value =
typename Container::value_type>
46 auto it =
find(c, std::forward<Value>(
value));
48 if (it == c.end())
return false;
54template <
typename Container,
typename Find_if>
55typename Container::const_iterator
find_if(
const Container &c,
60template <
typename Container,
typename Find_if>
62 auto it = find_if<Container, Find_if>(c, std::forward<Find_if>(
value));
64 if (it == c.end())
return false;
70template <
typename Container,
typename Find_if>
74 if (c.end() == it)
return false;
79template <
typename Container,
typename Find_if>
83 if (c.end() == it)
return false;
84 if (out) *out = (*it);
88template <
typename Container,
typename Value =
typename Container::value_type>
89bool has(
const Container &c, Value &&val) {
92 auto it =
std::find(b, e, std::forward<Value>(val));
93 if (e == it)
return false;
97template <
typename Container,
typename Find_if>
100 if (c.end() == it)
return false;
104template <
typename Container,
typename Value =
typename Container::value_type>
106 auto it =
std::find(c.begin(), c.end(), std::forward<Value>(val));
107 if (c.end() == it)
return -1;
111template <
typename Container,
typename Find_if>
113 for (
auto &e : input) {
114 if (
find_if(e)) output.push_back(e);
118template <
typename Container,
typename Value =
typename Container::value_type>
120 return std::vector<Value>(v.begin(), v.end());
123template <
typename Value = u
int8_t,
typename Container>
125 return as_vector<Container, Value>(v);
128template <
typename Container,
typename Value =
typename Container::value_type>
129std::set<Value>
as_set(
const Container &v) {
130 return std::set<Value>(v.begin(), v.end());
133template <
typename Value = u
int8_t,
typename Container>
135 return as_set<Container, Value>(v);
uint16_t value_type
Definition: vt100.h:184
Definition: atomics_array.h:39
bool distance(const dd::Spatial_reference_system *srs, const Geometry *g1, const Geometry *g2, double *distance, bool *is_null) noexcept
Computes the distance between two geometries.
Definition: distance.cc:40
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
bool remove_if(Container &c, Find_if &&value)
Definition: generic.h:61
std::vector< Value > as_vector_t(const Container &v)
Definition: generic.h:124
Container::const_iterator find(const Container &c, Value &&value)
Definition: generic.h:40
std::vector< Value > as_vector(const Container &v)
Definition: generic.h:119
std::set< Value > as_set(const Container &v)
Definition: generic.h:129
bool has(const Container &c, Value &&val)
Definition: generic.h:89
bool remove(Container &c, Value &&value)
Definition: generic.h:45
Container::const_iterator find_if(const Container &c, Find_if &&find_if)
Definition: generic.h:55
std::set< Value > as_set_t(const Container &v)
Definition: generic.h:134
bool get_if(Container &c, Find_if &&find_if, typename Container::value_type *out)
Definition: generic.h:80
bool get_ptr_if(const Container &c, Find_if &&find_if, const typename Container::value_type **out)
Definition: generic.h:71
int index_of(Container &c, Value &&val)
Definition: generic.h:105
bool has_if(const Container &c, Find_if &&find_if)
Definition: generic.h:98
void copy_if(const Container &input, Find_if &&find_if, Container &output)
Definition: generic.h:112
const char * begin(const char *const c)
Definition: base64.h:44