LLVM  14.0.0git
iterator_range.h
Go to the documentation of this file.
1 //===- iterator_range.h - A range adaptor for iterators ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// This provides a very simple, boring adaptor for a begin and end iterator
10 /// into a range type. This should be used to build range views that work well
11 /// with range based for loops and range based constructors.
12 ///
13 /// Note that code here follows more standards-based coding conventions as it
14 /// is mirroring proposed interfaces for standardization.
15 ///
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_ADT_ITERATOR_RANGE_H
19 #define LLVM_ADT_ITERATOR_RANGE_H
20 
21 #include <utility>
22 
23 namespace llvm {
24 
25 /// A range adaptor for a pair of iterators.
26 ///
27 /// This just wraps two iterators into a range-compatible interface. Nothing
28 /// fancy at all.
29 template <typename IteratorT>
31  IteratorT begin_iterator, end_iterator;
32 
33 public:
34  //TODO: Add SFINAE to test that the Container's iterators match the range's
35  // iterators.
36  template <typename Container>
37  iterator_range(Container &&c)
38  //TODO: Consider ADL/non-member begin/end calls.
39  : begin_iterator(c.begin()), end_iterator(c.end()) {}
40  iterator_range(IteratorT begin_iterator, IteratorT end_iterator)
41  : begin_iterator(std::move(begin_iterator)),
42  end_iterator(std::move(end_iterator)) {}
43 
44  IteratorT begin() const { return begin_iterator; }
45  IteratorT end() const { return end_iterator; }
46  bool empty() const { return begin_iterator == end_iterator; }
47 };
48 
49 /// Convenience function for iterating over sub-ranges.
50 ///
51 /// This provides a bit of syntactic sugar to make using sub-ranges
52 /// in for loops a bit easier. Analogous to std::make_pair().
53 template <class T> iterator_range<T> make_range(T x, T y) {
55 }
56 
57 template <typename T> iterator_range<T> make_range(std::pair<T, T> p) {
58  return iterator_range<T>(std::move(p.first), std::move(p.second));
59 }
60 
61 }
62 
63 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
p
the resulting code requires compare and branches when and if * p
Definition: README.txt:396
llvm::iterator_range::empty
bool empty() const
Definition: iterator_range.h:46
c
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int c
Definition: README.txt:418
llvm::iterator_range::iterator_range
iterator_range(Container &&c)
Definition: iterator_range.h:37
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1658
llvm::iterator_range::iterator_range
iterator_range(IteratorT begin_iterator, IteratorT end_iterator)
Definition: iterator_range.h:40
llvm::iterator_range::end
IteratorT end() const
Definition: iterator_range.h:45
std
Definition: BitVector.h:838
x
TODO unsigned x
Definition: README.txt:10
y
into llvm powi allowing the code generator to produce balanced multiplication trees the intrinsic needs to be extended to support and second the code generator needs to be enhanced to lower these to multiplication trees Interesting testcase for add shift mul int y
Definition: README.txt:61
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::iterator_range::begin
IteratorT begin() const
Definition: iterator_range.h:44