mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: replace list of dives in trip by std::vector<>
The dive_table will be converted into a table of owning pointers. Since the trip has only non-owning pointers to dives, turn its dive_table into an std::vector<dive *>. Add a helper functions to add/remove items in a sorted list. These could be used elsewhere. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
71518fa77e
commit
5c7cfb1057
12 changed files with 107 additions and 86 deletions
19
core/range.h
19
core/range.h
|
|
@ -176,7 +176,24 @@ int index_of_if(const Range &range, Func f)
|
|||
template<typename Range, typename Element>
|
||||
bool range_contains(const Range &v, const Element &item)
|
||||
{
|
||||
return std::find(v.begin(), v.end(), item) != v.end();
|
||||
return std::find(std::begin(v), std::end(v), item) != v.end();
|
||||
}
|
||||
|
||||
// Insert into an already sorted range
|
||||
template<typename Range, typename Element, typename Comp>
|
||||
void range_insert_sorted(Range &v, Element &item, Comp &comp)
|
||||
{
|
||||
auto it = std::lower_bound(std::begin(v), std::end(v), item,
|
||||
[&comp](auto &a, auto &b) { return comp(a, b) < 0; });
|
||||
v.insert(it, std::move(item));
|
||||
}
|
||||
|
||||
template<typename Range, typename Element>
|
||||
void range_remove(Range &v, const Element &item)
|
||||
{
|
||||
auto it = std::find(std::begin(v), std::end(v), item);
|
||||
if (it != std::end(v))
|
||||
v.erase(it);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue