From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/lib/misc/algorithm.hh | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tiger-compiler/lib/misc/algorithm.hh (limited to 'tiger-compiler/lib/misc/algorithm.hh') 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 +#include + +namespace misc +{ + /// Invoke delete on all the members of \a c, and clear it. + template + requires Iterable + void deep_clear(Container& c); + + /// Find \a v in the whole \a c. + template + requires ConstIterable + inline typename Container::const_iterator + find(const Container& c, const typename Container::value_type& v); + + /// Find \a v in the whole \a c. + template + requires Iterable + 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 + requires ConstIterable + inline Functor& for_each(Container& c, Functor& v); + + /// Is \a v member of \a c? + template + requires ConstIterable + 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 + typename Map::iterator put(Map& map, + const typename Map::key_type& key, + const typename Map::mapped_type& value); + +} // namespace misc + +#include -- cgit v1.2.3