halcheck 1.0
Loading...
Searching...
No Matches
subrange.hpp
1#ifndef HALCHECK_LIB_ITERATOR_SUBRANGE_HPP
2#define HALCHECK_LIB_ITERATOR_SUBRANGE_HPP
3
4// IWYU pragma: private, include <halcheck/lib/iterator.hpp>
5
6#include <halcheck/lib/iterator/interface.hpp>
7#include <halcheck/lib/iterator/range.hpp>
8#include <halcheck/lib/iterator/type_traits.hpp>
9#include <halcheck/lib/type_traits.hpp>
10
11#include <type_traits>
12
13namespace halcheck { namespace lib {
14
20template<typename I>
21class subrange : public lib::view_interface<subrange<I>> {
22public:
23 static_assert(lib::is_iterator<I>(), "I must be an iterator");
24
29 constexpr subrange() = default;
30
36 constexpr subrange(I first, I last) : _begin(std::move(first)), _end(std::move(last)) {}
37
42 constexpr I begin() const { return _begin; }
43
48 constexpr I end() const { return _end; }
49
50private:
51 I _begin;
52 I _end;
53};
54
63template<typename I, HALCHECK_REQUIRE(lib::is_iterator<I>())>
65 return lib::subrange<I>(std::move(first), std::move(last));
66}
67
68template<typename I>
69struct enable_borrowed_range<lib::subrange<I>> : std::true_type {};
70
71}} // namespace halcheck::lib
72
73#endif
constexpr subrange(I first, I last)
Constructs a subrange from a pair of iterators.
Definition subrange.hpp:36
constexpr I begin() const
Gets an iterator pointing at the first element in the subrange.
Definition subrange.hpp:42
constexpr subrange()=default
Constructs an empty subrange.
constexpr I end() const
Gets an iterator pointing past the last element in the subrange.
Definition subrange.hpp:48
Describes a range formed from a pair of iterators.
Definition subrange.hpp:21
An implementation of std::ranges::view_interface.
Definition interface.hpp:238
lib::subrange< I > make_subrange(I first, I last)
Constructs a subrange from a pair of iterators.
Definition subrange.hpp:64
STL namespace.
Determines whether a type satisfies the LegacyIterator concept.
Definition type_traits.hpp:34