LLVM: include/llvm/ADT/iterator.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_ADT_ITERATOR_H

10#define LLVM_ADT_ITERATOR_H

11

13#include

14#include

15#include <type_traits>

16#include

17

18namespace llvm {

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

77template <typename DerivedT, typename IteratorCategoryT, typename T,

78 typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *,

79 typename ReferenceT = T &>

81public:

87

88protected:

89 enum {

90 IsRandomAccess = std::is_base_of<std::random_access_iterator_tag,

91 IteratorCategoryT>::value,

92 IsBidirectional = std::is_base_of<std::bidirectional_iterator_tag,

93 IteratorCategoryT>::value,

94 };

95

96

97

98

99

100

101 class ReferenceProxy {

102 friend iterator_facade_base;

103

104 DerivedT I;

105

106 ReferenceProxy(DerivedT I) : I(std::move(I)) {}

107

108 public:

109 operator ReferenceT() const { return *I; }

110 };

111

112

113

114

115

116 class PointerProxy {

117 friend iterator_facade_base;

118

119 ReferenceT R;

120

121 template

122 PointerProxy(RefT &&R) : R(std::forward(R)) {}

123

124 public:

126 };

127

128public:

129 DerivedT operator+(DifferenceTypeT n) const {

130 static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,

131 "Must pass the derived type to this template!");

132 static_assert(

134 "The '+' operator is only defined for random access iterators.");

135 DerivedT tmp = *static_cast<const DerivedT *>(this);

136 tmp += n;

137 return tmp;

138 }

139 friend DerivedT operator+(DifferenceTypeT n, const DerivedT &i) {

140 static_assert(

142 "The '+' operator is only defined for random access iterators.");

143 return i + n;

144 }

145 DerivedT operator-(DifferenceTypeT n) const {

146 static_assert(

148 "The '-' operator is only defined for random access iterators.");

149 DerivedT tmp = *static_cast<const DerivedT *>(this);

150 tmp -= n;

151 return tmp;

152 }

153

155 static_assert(std::is_base_of<iterator_facade_base, DerivedT>::value,

156 "Must pass the derived type to this template!");

157 return static_cast<DerivedT *>(this)->operator+=(1);

158 }

160 DerivedT tmp = *static_cast<DerivedT *>(this);

161 ++*static_cast<DerivedT *>(this);

162 return tmp;

163 }

165 static_assert(

167 "The decrement operator is only defined for bidirectional iterators.");

168 return static_cast<DerivedT *>(this)->operator-=(1);

169 }

171 static_assert(

173 "The decrement operator is only defined for bidirectional iterators.");

174 DerivedT tmp = *static_cast<DerivedT *>(this);

175 --*static_cast<DerivedT *>(this);

176 return tmp;

177 }

178

179#ifndef __cpp_impl_three_way_comparison

181 return !(static_cast<const DerivedT &>(*this) == RHS);

182 }

183#endif

184

186 static_assert(

188 "Relational operators are only defined for random access iterators.");

189 return !(static_cast<const DerivedT &>(*this) < RHS) &&

190 !(static_cast<const DerivedT &>(*this) == RHS);

191 }

193 static_assert(

195 "Relational operators are only defined for random access iterators.");

196 return !(static_cast<const DerivedT &>(*this) > RHS);

197 }

199 static_assert(

201 "Relational operators are only defined for random access iterators.");

202 return !(static_cast<const DerivedT &>(*this) < RHS);

203 }

204

206 return static_cast<const DerivedT *>(this)->operator*();

207 }

208 ReferenceProxy operator[](DifferenceTypeT n) const {

210 "Subscripting is only defined for random access iterators.");

211 return static_cast<const DerivedT *>(this)->operator+(n);

212 }

213};

214

215

216

217

218

219

220template <

222 typename IteratorCategoryT =

223 typename std::iterator_traits::iterator_category,

224 typename T = typename std::iterator_traits::value_type,

225 typename DifferenceTypeT =

226 typename std::iterator_traits::difference_type,

227 typename PointerT = std::conditional_t<

228 std::is_same<T, typename std::iterator_traits<

230 typename std::iterator_traits::pointer, T *>,

231 typename ReferenceT = std::conditional_t<

232 std::is_same<T, typename std::iterator_traits<

234 typename std::iterator_traits::reference, T &>>

237 DifferenceTypeT, PointerT, ReferenceT> {

238 using BaseT = typename iterator_adaptor_base::iterator_facade_base;

239

240protected:

242

244

246 static_assert(std::is_base_of<iterator_adaptor_base, DerivedT>::value,

247 "Must pass the derived type to this template!");

248 }

249

251

252public:

254

256 static_assert(

257 BaseT::IsRandomAccess,

258 "The '+=' operator is only defined for random access iterators.");

259 I += n;

260 return *static_cast<DerivedT *>(this);

261 }

263 static_assert(

264 BaseT::IsRandomAccess,

265 "The '-=' operator is only defined for random access iterators.");

266 I -= n;

267 return *static_cast<DerivedT *>(this);

268 }

269 using BaseT::operator-;

271 static_assert(

272 BaseT::IsRandomAccess,

273 "The '-' operator is only defined for random access iterators.");

274 return I - RHS.I;

275 }

276

277

278

279 using BaseT::operator++;

281 ++I;

282 return *static_cast<DerivedT *>(this);

283 }

284 using BaseT::operator--;

286 static_assert(

287 BaseT::IsBidirectional,

288 "The decrement operator is only defined for bidirectional iterators.");

289 --I;

290 return *static_cast<DerivedT *>(this);

291 }

292

295 return LHS.I == RHS.I;

296 }

299 static_assert(

300 BaseT::IsRandomAccess,

301 "Relational operators are only defined for random access iterators.");

302 return LHS.I < RHS.I;

303 }

304

306};

307

308

309

310

311

312

313

314

315

316

318 typename T = std::remove_reference_t<decltype(

319 **std::declval())>>

324 T> {

326 template

329

331};

332

334 decltype(std::begin(std::declval()))>

338 return make_range(PointeeIteratorT(std::begin(std::forward(Range))),

339 PointeeIteratorT(std::end(std::forward(Range))));

340}

341

343 typename T = decltype(&*std::declval())>

348 T> {

349 mutable T Ptr;

350

351public:

353

356

358};

359

361 decltype(std::begin(std::declval()))>

365 return make_range(PointerIteratorT(std::begin(std::forward(Range))),

366 PointerIteratorT(std::end(std::forward(Range))));

367}

368

370 typename T1 = std::remove_reference_t<decltype(

371 **std::declval())>,

372 typename T2 = std::add_pointer_t>

375

376}

377

378#endif

ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))

iterator_adaptor_base(WrappedIteratorT u)

Definition iterator.h:245

const WrappedIteratorT & wrapped() const

Definition iterator.h:250

DerivedT & operator--()

Definition iterator.h:285

DerivedT & operator+=(difference_type n)

Definition iterator.h:255

DerivedT & operator++()

Definition iterator.h:280

IteratorBase I

Definition iterator.h:241

iterator_adaptor_base()=default

difference_type operator-(const DerivedT &RHS) const

Definition iterator.h:270

friend bool operator<(const iterator_adaptor_base &LHS, const iterator_adaptor_base &RHS)

Definition iterator.h:297

DerivedT & operator-=(difference_type n)

Definition iterator.h:262

friend bool operator==(const iterator_adaptor_base &LHS, const iterator_adaptor_base &RHS)

Definition iterator.h:293

ReferenceT operator*() const

Definition iterator.h:305

typename std::iterator_traits< IteratorBase >::difference_type difference_type

Definition iterator.h:253

PointerT operator->() const

Definition iterator.h:125

CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...

Definition iterator.h:80

PointerProxy operator->() const

Definition iterator.h:205

IteratorCategoryT iterator_category

Definition iterator.h:82

DerivedT & operator++()

Definition iterator.h:154

bool operator<=(const DerivedT &RHS) const

Definition iterator.h:192

DerivedT & operator--()

Definition iterator.h:164

bool operator>=(const DerivedT &RHS) const

Definition iterator.h:198

DerivedT operator--(int)

Definition iterator.h:170

T value_type

Definition iterator.h:83

DerivedT operator-(DifferenceTypeT n) const

Definition iterator.h:145

friend DerivedT operator+(DifferenceTypeT n, const DerivedT &i)

Definition iterator.h:139

DerivedT operator++(int)

Definition iterator.h:159

DifferenceTypeT difference_type

Definition iterator.h:84

bool operator!=(const DerivedT &RHS) const

Definition iterator.h:180

bool operator>(const DerivedT &RHS) const

Definition iterator.h:185

ReferenceT reference

Definition iterator.h:86

DerivedT operator+(DifferenceTypeT n) const

Definition iterator.h:129

@ IsBidirectional

Definition iterator.h:92

@ IsRandomAccess

Definition iterator.h:90

PointerT pointer

Definition iterator.h:85

ReferenceProxy operator[](DifferenceTypeT n) const

Definition iterator.h:208

Definition iterator.h:348

T & operator*() const

Definition iterator.h:357

pointer_iterator(WrappedIteratorT u)

Definition iterator.h:354

pointer_iterator()=default

This provides a very simple, boring adaptor for a begin and end iterator into a range type.

This is an optimization pass for GlobalISel generic memory operations.

pointer_iterator< pointee_iterator< WrappedIteratorT, T1 >, T2 > raw_pointer_iterator

Definition iterator.h:373

iterator_range< T > make_range(T x, T y)

Convenience function for iterating over sub-ranges.

iterator_range< pointee_iterator< WrappedIteratorT > > make_pointee_range(RangeT &&Range)

Definition iterator.h:336

iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)

Definition iterator.h:363

Implement std::hash so that hash_code can be used in STL containers.

An iterator type that allows iterating over the pointees via some other iterator.

Definition iterator.h:324

pointee_iterator(U &&u)

Definition iterator.h:327

T & operator*() const

Definition iterator.h:330

pointee_iterator()=default