1 /* A range adapter that wraps begin / end iterators.
2 Copyright (C) 2021-2023 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #ifndef GDBSUPPORT_ITERATOR_RANGE_H
20 #define GDBSUPPORT_ITERATOR_RANGE_H
22 /* A wrapper that allows using ranged for-loops on a range described by two
25 template <typename IteratorType
>
28 using iterator
= IteratorType
;
30 /* Create an iterator_range using BEGIN as the begin iterator.
32 Assume that the end iterator can be default-constructed. */
33 template <typename
... Args
>
34 iterator_range (Args
&&...args
)
35 : m_begin (std::forward
<Args
> (args
)...)
38 /* Create an iterator range using explicit BEGIN and END iterators. */
39 template <typename
... Args
>
40 iterator_range (IteratorType begin
, IteratorType end
)
41 : m_begin (std::move (begin
)), m_end (std::move (end
))
44 /* Need these as the variadic constructor would be a better match
46 iterator_range (iterator_range
&) = default;
47 iterator_range (const iterator_range
&) = default;
48 iterator_range (iterator_range
&&) = default;
50 IteratorType
begin () const
53 IteratorType
end () const
56 /* The number of items in this iterator_range. */
57 std::size_t size () const
58 { return std::distance (m_begin
, m_end
); }
61 IteratorType m_begin
, m_end
;
64 #endif /* GDBSUPPORT_ITERATOR_RANGE_H */