Menu

[94f52a]: / safe_iterator.hpp  Maximize  Restore  History

Download this file

38 lines (27 with data), 717 Bytes

 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
#ifndef CHILON_SAFE_ITERATOR_HPP
#define CHILON_SAFE_ITERATOR_HPP
#include <chilon/meta/return.hpp>
#include <chilon/print.hpp>
#include <unordered_map>
#include <vector>
namespace chilon {
template <class T>
struct safe_iterator {
T& container_;
size_t idx_;
public:
bool at_end() const { return idx_ >= container_.size(); }
safe_iterator& operator++() {
++idx_;
return *this;
}
auto operator*() CHILON_RETURN(container_[idx_]);
auto operator->() CHILON_RETURN(&container_[idx_]);
safe_iterator(T& container) : container_(container), idx_(0) {};
};
template <class T>
safe_iterator<T> make_safe_iterator(T& t) {
return safe_iterator<T>(t);
}
}
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.