1//===- iterator_range.h - A range adaptor for iterators ---------*- C++ -*-===//
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
7//===----------------------------------------------------------------------===//
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.
13/// Note that code here follows more standards-based coding conventions as it
14/// is mirroring proposed interfaces for standardization.
16//===----------------------------------------------------------------------===//
18#ifndef LLVM_ADT_ITERATOR_RANGE_H
19#define LLVM_ADT_ITERATOR_RANGE_H
27/// A range adaptor for a pair of iterators.
29/// This just wraps two iterators into a range-compatible interface. Nothing
31template <
typename IteratorT>
33 IteratorT begin_iterator, end_iterator;
35 template <
typename From,
typename To>
36 using explicitly_converted_t =
decltype(
static_cast<To
>(
37 std::declval<std::add_rvalue_reference_t<From>>()));
40#if defined(__GNUC__) && \
41 (__GNUC__ == 7 || (__GNUC__ == 8 && __GNUC_MINOR__ < 4))
42 // Be careful no to break gcc-7 and gcc-8 < 8.4 on the mlir target.
43 // See https://github.com/llvm/llvm-project/issues/63843
44 template <
typename Container>
46 template <
typename Container,
47 std::void_t<explicitly_converted_t<
54 : begin_iterator(
std::
move(begin_iterator)),
55 end_iterator(
std::
move(end_iterator)) {}
57 IteratorT
begin()
const {
return begin_iterator; }
58 IteratorT
end()
const {
return end_iterator; }
59 bool empty()
const {
return begin_iterator == end_iterator; }
62template <
typename Container>
66/// Convenience function for iterating over sub-ranges.
68/// This provides a bit of syntactic sugar to make using sub-ranges
69/// in for loops a bit easier. Analogous to std::make_pair().
A range adaptor for a pair of iterators.
iterator_range(IteratorT begin_iterator, IteratorT end_iterator)
iterator_range(Container &&c)
decltype(adl_begin(std::declval< RangeT & >())) IterOfRange
This is an optimization pass for GlobalISel generic memory operations.
constexpr auto adl_begin(RangeT &&range) -> decltype(adl_detail::begin_impl(std::forward< RangeT >(range)))
Returns the begin iterator to range using std::begin and function found through Argument-Dependent Lo...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr auto adl_end(RangeT &&range) -> decltype(adl_detail::end_impl(std::forward< RangeT >(range)))
Returns the end iterator to range using std::end and functions found through Argument-Dependent Looku...
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.
Implement std::hash so that hash_code can be used in STL containers.