1
#ifndef CHILON_SAFE_ITERATOR_HPP
2
#define CHILON_SAFE_ITERATOR_HPP
3
4
#include <chilon/meta/return.hpp>
5
#include <chilon/print.hpp>
6
7
#include <unordered_map>
8
#include <vector>
9
10
namespace chilon {
11
12
template <class T>
13
struct safe_iterator {
14
    T&  container_;
15
    size_t idx_;
16
  public:
17
    bool at_end() const { return idx_ >= container_.size(); }
18
19
    safe_iterator& operator++() {
20
        ++idx_;
21
        return *this;
22
    }
23
24
    auto operator*() CHILON_RETURN(container_[idx_]);
25
    auto operator->() CHILON_RETURN(&container_[idx_]);
26
27
    safe_iterator(T& container) : container_(container), idx_(0) {};
28
};
29
30
template <class T>
31
safe_iterator<T> make_safe_iterator(T& t) {
32
    return safe_iterator<T>(t);
33
}
34
35
}
36
37
#endif