ranges.hpp 705 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_RANGES_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_RANGES_HPP
Paul's avatar
Paul committed
3

Paul's avatar
Paul committed
4
5
#include <algorithm>

Paul's avatar
Paul committed
6
namespace migraph {
Paul's avatar
Paul committed
7
8
9
10
11
12
13
14
15
16
17
18
19

template <class C, class T>
bool contains(C&& c, T&& x)
{
    return c.find(x) != c.end();
}

template <class Range, class Iterator>
void copy(Range&& r, Iterator it)
{
    std::copy(r.begin(), r.end(), it);
}

Paul's avatar
Paul committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
template<class Iterator>
struct iterator_range
{
    Iterator start;
    Iterator last;

    Iterator begin() const
    {
        return start;
    }

    Iterator end() const
    {
        return last;
    }
};

template<class Iterator>
iterator_range<Iterator> range(Iterator start, Iterator last)
{
    return {start, last};
}

Paul's avatar
Paul committed
43
} // namespace migraph
Paul's avatar
Paul committed
44
45

#endif