forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamples.hpp
More file actions
98 lines (80 loc) · 2.51 KB
/
Copy pathsamples.hpp
File metadata and controls
98 lines (80 loc) · 2.51 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef ITERTOOLS_SAMPLE_CLASSES_HPP
#define ITERTOOLS_SAMPLE_CLASSES_HPP
#include <iostream>
#include <utility>
#include <cstddef>
namespace itertest {
class MoveOnly {
private:
int i; // not an aggregate
public:
MoveOnly(int v)
: i{v}
{ }
MoveOnly(const MoveOnly&) = delete;
MoveOnly& operator=(const MoveOnly&) = delete;
MoveOnly(MoveOnly&& other) noexcept
: i{other.i}
{ }
MoveOnly& operator=(MoveOnly&& other) noexcept {
this->i = other.i;
return *this;
}
// for std::next_permutation compatibility
friend bool operator<(const MoveOnly& lhs, const MoveOnly& rhs) {
return lhs.i < rhs.i;
}
friend std::ostream& operator<<(
std::ostream& out, const MoveOnly& self) {
return out << self.i;
}
};
class DerefByValue {
private:
static constexpr std::size_t N = 3;
int array[N] = {0, 1, 2};
public:
DerefByValue() = default;
class Iterator {
private:
int *current;
public:
Iterator() = default;
Iterator(int *p)
: current{p}
{ }
bool operator!=(const Iterator& other) const {
return this->current != other.current;
}
// for testing, iterator derefences to an int instead of
// an int&
int operator*() const {
return *this->current;
}
Iterator& operator++() {
++this->current;
return *this;
}
};
Iterator begin() {
return {this->array};
}
Iterator end() {
return {this->array + N};
}
};
class DerefByValueFancy {
private:
static constexpr std::size_t N = 3;
int array[N] = {0, 1, 2};
public:
DerefByValueFancy() = default;
int *begin() {
return this->array;
}
int *end() {
return this->array + N;
}
};
}
#endif // #ifndef ITERTOOLS_SAMPLE_CLASSES_HPP