libdl  0.0.1
Simple yet powerful deep learning
Loading...
Searching...
No Matches
line_iter.hpp
1#pragma once
2
3#include <istream>
4#include <iterator>
5#include <string>
6
7namespace dl::utils {
8 struct LineIterator final {
10 using value_type = std::string;
12 using reference = const value_type&;
13 using pointer = const value_type*;
14
15 LineIterator() : input_(nullptr) {}
16 LineIterator(std::istream& input) : input_(&input) { ++*this; }
17
18 reference operator*() const { return s_; }
19 pointer operator->() const { return &**this; }
20
21 LineIterator& operator++() {
22 if (!std::getline(*input_, s_))
23 input_ = nullptr;
24 return *this;
25 }
26
27 LineIterator operator++(int) {
28 auto copy(*this);
29 ++*this;
30 return copy;
31 }
32
33 friend bool operator==(const LineIterator& x, const LineIterator& y) { return x.input_ == y.input_; }
34
35 friend bool operator!=(const LineIterator& x, const LineIterator& y) { return !(x == y); }
36
37 private:
38 std::istream* input_;
39 std::string s_;
40 };
41} // namespace dl::utils
T getline(T... args)