]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/iterator-utils.h
Move iterator_range to a new iterator-utils.h file
[thirdparty/gcc.git] / gcc / iterator-utils.h
CommitLineData
1751a78e
RS
1// Iterator-related utilities.
2// Copyright (C) 2002-2020 Free Software Foundation, Inc.
3//
4// This file is part of GCC.
5//
6// GCC is free software; you can redistribute it and/or modify it under
7// the terms of the GNU General Public License as published by the Free
8// Software Foundation; either version 3, or (at your option) any later
9// version.
10//
11// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12// WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with GCC; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20#ifndef GCC_ITERATOR_UTILS_H
21#define GCC_ITERATOR_UTILS_H 1
22
23// A half-open [begin, end) range of iterators.
24template<typename T>
25struct iterator_range
26{
27public:
28 using const_iterator = T;
29
30 iterator_range () = default;
31 iterator_range (const T &begin, const T &end)
32 : m_begin (begin), m_end (end) {}
33
34 T begin () const { return m_begin; }
35 T end () const { return m_end; }
36
37 explicit operator bool () const { return m_begin != m_end; }
38
39private:
40 T m_begin;
41 T m_end;
42};
43
44#endif