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
7
namespace
dl::utils {
8
struct
LineIterator
final {
9
using
iterator_category
=
std::input_iterator_tag
;
10
using
value_type
=
std::string
;
11
using
difference_type
=
std::ptrdiff_t
;
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
std::istream
std::string
std::getline
T getline(T... args)
std::input_iterator_tag
std::ptrdiff_t
dl::utils::LineIterator
Definition
line_iter.hpp:8
dl
utils
line_iter.hpp
Generated by
1.9.8