LLVM  13.0.0git
Sequence.h
Go to the documentation of this file.
1 //===- Sequence.h - Utility for producing sequences of values ---*- 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 routine provides some synthesis utilities to produce sequences of
10 /// values. The names are intentionally kept very short as they tend to occur
11 /// in common and widely used contexts.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_ADT_SEQUENCE_H
16 #define LLVM_ADT_SEQUENCE_H
17 
18 #include "llvm/ADT/iterator.h"
20 #include <algorithm>
21 #include <iterator>
22 #include <utility>
23 
24 namespace llvm {
25 
26 namespace detail {
27 
28 template <typename ValueT>
30  : public iterator_facade_base<value_sequence_iterator<ValueT>,
31  std::random_access_iterator_tag,
32  const ValueT> {
33  using BaseT = typename value_sequence_iterator::iterator_facade_base;
34 
35  ValueT Value;
36 
37 public:
38  using difference_type = typename BaseT::difference_type;
39  using reference = typename BaseT::reference;
40 
41  value_sequence_iterator() = default;
44  : Value(std::move(Arg.Value)) {}
46  Value = Arg.Value;
47  return *this;
48  }
49 
50  template <typename U, typename Enabler = decltype(ValueT(std::declval<U>()))>
51  value_sequence_iterator(U &&Value) : Value(std::forward<U>(Value)) {}
52 
54  Value += N;
55  return *this;
56  }
58  Value -= N;
59  return *this;
60  }
61  using BaseT::operator-;
63  return Value - RHS.Value;
64  }
65 
66  bool operator==(const value_sequence_iterator &RHS) const {
67  return Value == RHS.Value;
68  }
69  bool operator<(const value_sequence_iterator &RHS) const {
70  return Value < RHS.Value;
71  }
72 
73  reference operator*() const { return Value; }
74 };
75 
76 } // end namespace detail
77 
78 template <typename ValueT>
80  ValueT End) {
83 }
84 
85 } // end namespace llvm
86 
87 #endif // LLVM_ADT_SEQUENCE_H
llvm
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
llvm::detail::value_sequence_iterator::operator=
value_sequence_iterator & operator=(const value_sequence_iterator &Arg)
Definition: Sequence.h:45
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::detail::value_sequence_iterator::operator*
reference operator*() const
Definition: Sequence.h:73
llvm::detail::value_sequence_iterator::value_sequence_iterator
value_sequence_iterator()=default
iterator.h
llvm::iterator_facade_base
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:66
llvm::detail::value_sequence_iterator::operator<
bool operator<(const value_sequence_iterator &RHS) const
Definition: Sequence.h:69
llvm::detail::value_sequence_iterator::operator==
bool operator==(const value_sequence_iterator &RHS) const
Definition: Sequence.h:66
llvm::detail::value_sequence_iterator::operator-=
value_sequence_iterator & operator-=(difference_type N)
Definition: Sequence.h:57
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:1540
iterator_range.h
llvm::detail::value_sequence_iterator
Definition: Sequence.h:29
ValueT
llvm::detail::value_sequence_iterator::operator-
difference_type operator-(const value_sequence_iterator &RHS) const
Definition: Sequence.h:62
std
Definition: BitVector.h:838
llvm::detail::value_sequence_iterator::operator+=
value_sequence_iterator & operator+=(difference_type N)
Definition: Sequence.h:53
llvm::detail::value_sequence_iterator::value_sequence_iterator
value_sequence_iterator(value_sequence_iterator &&Arg)
Definition: Sequence.h:43
llvm::detail::value_sequence_iterator::value_sequence_iterator
value_sequence_iterator(U &&Value)
Definition: Sequence.h:51
N
#define N
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::detail::value_sequence_iterator::difference_type
typename BaseT::difference_type difference_type
Definition: Sequence.h:38
llvm::seq
iterator_range< detail::value_sequence_iterator< ValueT > > seq(ValueT Begin, ValueT End)
Definition: Sequence.h:79
llvm::detail::value_sequence_iterator::reference
typename BaseT::reference reference
Definition: Sequence.h:39
llvm::Value
LLVM Value Representation.
Definition: Value.h:75