diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/lib/misc/algorithm.hh | |
Diffstat (limited to 'tiger-compiler/lib/misc/algorithm.hh')
| -rw-r--r-- | tiger-compiler/lib/misc/algorithm.hh | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tiger-compiler/lib/misc/algorithm.hh b/tiger-compiler/lib/misc/algorithm.hh new file mode 100644 index 0000000..14250bc --- /dev/null +++ b/tiger-compiler/lib/misc/algorithm.hh @@ -0,0 +1,48 @@ +/** + ** \file misc/algorithm.hh + ** \brief Some syntactic sugar to look for things in STL containers. + */ + +#pragma once + +#include <iosfwd> +#include <misc/concepts.hh> + +namespace misc +{ + /// Invoke delete on all the members of \a c, and clear it. + template <typename Container> + requires Iterable<Container> + void deep_clear(Container& c); + + /// Find \a v in the whole \a c. + template <typename Container> + requires ConstIterable<Container> + inline typename Container::const_iterator + find(const Container& c, const typename Container::value_type& v); + + /// Find \a v in the whole \a c. + template <typename Container> + requires Iterable<Container> + inline typename Container::iterator + find(Container& c, const typename Container::value_type& v); + + /// Apply \a f to all the members of \a c, and return it. + template <typename Container, typename Functor> + requires ConstIterable<Container> + inline Functor& for_each(Container& c, Functor& v); + + /// Is \a v member of \a c? + template <typename Container> + requires ConstIterable<Container> + inline bool has(const Container& c, const typename Container::value_type& v); + + /// Insert or update \a key -> \a value in \a map, return iterator to it. + template <Map Map> + typename Map::iterator put(Map& map, + const typename Map::key_type& key, + const typename Map::mapped_type& value); + +} // namespace misc + +#include <misc/algorithm.hxx> |
