ranges.hpp 675 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
template <class Iterator>
Paul's avatar
Paul committed
21
22
23
24
25
struct iterator_range
{
    Iterator start;
    Iterator last;

Paul's avatar
Paul committed
26
    Iterator begin() const { return start; }
Paul's avatar
Paul committed
27

Paul's avatar
Paul committed
28
    Iterator end() const { return last; }
Paul's avatar
Paul committed
29
30
};

Paul's avatar
Paul committed
31
template <class Iterator>
Paul's avatar
Paul committed
32
33
34
35
36
iterator_range<Iterator> range(Iterator start, Iterator last)
{
    return {start, last};
}

Paul's avatar
Paul committed
37
} // namespace migraph
Paul's avatar
Paul committed
38
39

#endif