26#ifndef ROUTER_SRC_ROUTER_INCLUDE_HELPER_CONTAINER_GENERIC_H_
27#define ROUTER_SRC_ROUTER_INCLUDE_HELPER_CONTAINER_GENERIC_H_
38template <
typename Container,
typename Value =
typename Container::value_type>
39typename Container::const_iterator
find(
const Container &c, Value &&value) {
40 return std::find(c.begin(), c.end(), std::forward<Value>(value));
43template <
typename Container,
typename Value =
typename Container::value_type>
44bool remove(Container &c, Value &&value) {
45 auto it =
find(c, std::forward<Value>(value));
47 if (it == c.end())
return false;
53template <
typename Container,
typename Find_if>
54typename Container::const_iterator
find_if(
const Container &c,
59template <
typename Container,
typename Find_if>
61 auto it = find_if<Container, Find_if>(c, std::forward<Find_if>(value));
63 if (it == c.end())
return false;
69template <
typename Container,
typename Find_if>
73 if (c.end() == it)
return false;
78template <
typename Container,
typename Find_if>
82 if (c.end() == it)
return false;
87template <
typename Container,
typename Find_if>
91 if (c.end() == it)
return false;
96template <
typename Container,
typename Value =
typename Container::value_type>
97bool has(
const Container &c, Value &&val) {
100 auto it =
std::find(b, e, std::forward<Value>(val));
101 if (e == it)
return false;
105template <
typename Container,
typename Value =
typename Container::value_type>
107 auto it =
std::find(c.begin(), c.end(), std::forward<Value>(val));
108 if (c.end() == it)
return -1;
112template <
typename Container,
typename Find_if>
114 for (
auto &e : input) {
115 if (
find_if(e)) output.push_back(e);
119template <
typename Container,
typename Value =
typename Container::value_type>
121 return std::vector<Value>(v.begin(), v.end());
124template <
typename Value = u
int8_t,
typename Container>
126 return as_vector<Container, Value>(v);
129template <
typename Container,
typename Value =
typename Container::value_type>
130std::set<Value>
as_set(
const Container &v) {
131 return std::set<Value>(v.begin(), v.end());
134template <
typename Value = u
int8_t,
typename Container>
136 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
std::vector< Value > as_vector(const Container &v)
Definition: generic.h:120
bool get_if(const Container &c, Find_if &&find_if, const typename Container::value_type *out)
Definition: generic.h:79
std::set< Value > as_set(const Container &v)
Definition: generic.h:130
int index_of(Container &c, Value &&val)
Definition: generic.h:106
std::vector< Value > as_vector_t(const Container &v)
Definition: generic.h:125
Container::const_iterator find_if(const Container &c, Find_if &&find_if)
Definition: generic.h:54
bool remove_if(Container &c, Find_if &&value)
Definition: generic.h:60
void copy_if(const Container &input, Find_if &&find_if, Container &output)
Definition: generic.h:113
Container::const_iterator find(const Container &c, Value &&value)
Definition: generic.h:39
bool get_ptr_if(const Container &c, Find_if &&find_if, const typename Container::value_type **out)
Definition: generic.h:70
std::set< Value > as_set_t(const Container &v)
Definition: generic.h:135
bool has(const Container &c, Value &&val)
Definition: generic.h:97
bool remove(Container &c, Value &&value)
Definition: generic.h:44
const char * begin(const char *const c)
Definition: base64.h:44