map_utils.hpp

A set of simple functions to manipulate maps.

Note

Status: BETA

Functions

template<typename MAP_T>
std::string MapToString(const MAP_T &in_map)
template<class MAP_T, class KEY_T>
inline bool Has(const MAP_T &in_map, const KEY_T &key)

Take any map type, and run find to determine if a key is present.

template<typename KEY_T, typename ELEMENT_T, typename FUN_T>
bool AnyOf(const std::map<KEY_T, ELEMENT_T> &c, FUN_T fun)
template<typename KEY_T, typename ELEMENT_T, typename FUN_T>
bool AllOf(const std::map<KEY_T, ELEMENT_T> &c, FUN_T fun)
template<typename KEY_T, typename ELEMENT_T, typename FUN_T>
bool NoneOf(const std::map<KEY_T, ELEMENT_T> &c, FUN_T fun)
template<class MAP_T>
inline auto Keys(const MAP_T &in_map)
template<class MAP_T, class KEY_T>
inline auto Find(const MAP_T &in_map, const KEY_T &key, const typename MAP_T::mapped_type &dval)

Take any map, run find() member function, and return the result found (or default value if no results found).

template<class MAP_T, class KEY_T>
inline const auto &FindRef(const MAP_T &in_map, const KEY_T &key, const typename MAP_T::mapped_type &dval)

Take any map and element, run find() member function, and return a reference to the result found (or default value if no results found).

template<class MAP_T, class KEY_T>
inline const auto &GetConstRef(const MAP_T &in_map, const KEY_T &key)

Take any map and element, run find() member function, and return a reference to the result found; trip assert if the result is not present.

template<typename A, typename B>
constexpr std::pair<B, A> flip_pair(const std::pair<A, B> &p)

Take an std::pair<A,B> and return the flipped pair std::pair<B,A>

template<typename A, typename B>
std::multimap<B, A> flip_map(const std::map<A, B> &src)

Take an std::map<A,B> and return the flipped map (now multimap to be safe): std::multimap<B,A>

template<typename A, typename B>
multimap<B, A> flip_map(const map<A, B> &src)

Take an map<A,B> and return the flipped map (now multimap to be safe): multimap<B,A>