blob: 14250bce80635a957668eecb85c3b9b59b8bf915 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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>
|