10#ifndef CONTAINER_FUNC_HPP
11#define CONTAINER_FUNC_HPP
23template <
typename Container>
24inline bool include(Container &container,
typename Container::const_reference &item)
26 const bool is_member = std::ranges::find(container, item) != container.end();
27 if (!is_member) container.emplace_back(item);
40template <
typename Container>
41int find_index(Container
const &container,
typename Container::const_reference item)
43 auto const it = std::ranges::find(container, item);
44 if (it != container.end())
return std::distance(container.begin(), it);
56template <
typename TIter>
57auto Slide(TIter first, TIter last, TIter position) -> std::pair<TIter, TIter>
59 if (last < position)
return { std::rotate(first, last, position), position };
60 if (position < first)
return { position, std::rotate(position, first, last) };
61 return { first, last };
bool include(Container &container, typename Container::const_reference &item)
Helper function to append an item to a container if it is not already contained.
int find_index(Container const &container, typename Container::const_reference item)
Helper function to get the index of an item Consider using std::set, std::unordered_set or std::flat_...
auto Slide(TIter first, TIter last, TIter position) -> std::pair< TIter, TIter >
Move elements between first and last to a new position, rotating elements in between as necessary.