|
| 1 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | + |
| 3 | +#ifndef BEMAN_ANY_VIEW_DETAIL_UNREACHABLE_ITERATOR_HPP |
| 4 | +#define BEMAN_ANY_VIEW_DETAIL_UNREACHABLE_ITERATOR_HPP |
| 5 | + |
| 6 | +#include <beman/any_view/detail/utility.hpp> |
| 7 | + |
| 8 | +#include <compare> |
| 9 | +#include <iterator> |
| 10 | + |
| 11 | +namespace beman::any_view::detail { |
| 12 | + |
| 13 | +template <class ElementT, class RefT, class RValueRefT, class DiffT> |
| 14 | +struct iterator_concept { |
| 15 | + using type = std::random_access_iterator_tag; |
| 16 | +}; |
| 17 | + |
| 18 | +template <class ElementT> |
| 19 | +struct iterator_concept<ElementT, ElementT&, ElementT&&, std::ptrdiff_t> { |
| 20 | + using type = std::contiguous_iterator_tag; |
| 21 | +}; |
| 22 | + |
| 23 | +template <class ElementT, class RefT, class RValueRefT, class DiffT> |
| 24 | +class unreachable_iterator { |
| 25 | + public: |
| 26 | + using iterator_concept = iterator_concept<ElementT, RefT, RValueRefT, DiffT>::type; |
| 27 | + using element_type = ElementT; |
| 28 | + using difference_type = DiffT; |
| 29 | + |
| 30 | + constexpr auto operator*() const noexcept -> RefT { unreachable(); } |
| 31 | + |
| 32 | + constexpr friend auto iter_move(unreachable_iterator) noexcept -> RValueRefT { unreachable(); } |
| 33 | + |
| 34 | + constexpr auto operator++() noexcept -> unreachable_iterator& { return *this; } |
| 35 | + |
| 36 | + constexpr auto operator++(int) noexcept -> unreachable_iterator { return *this; } |
| 37 | + |
| 38 | + constexpr auto operator<=>(const unreachable_iterator&) const noexcept -> std::strong_ordering = default; |
| 39 | + |
| 40 | + constexpr auto operator--() noexcept -> unreachable_iterator& { return *this; } |
| 41 | + |
| 42 | + constexpr auto operator--(int) noexcept -> unreachable_iterator { return *this; } |
| 43 | + |
| 44 | + constexpr auto operator-(unreachable_iterator) const noexcept -> difference_type { return 0; } |
| 45 | + |
| 46 | + constexpr auto operator+=(difference_type) noexcept -> unreachable_iterator& { return *this; } |
| 47 | + |
| 48 | + constexpr auto operator+(difference_type) const noexcept -> unreachable_iterator { return *this; } |
| 49 | + |
| 50 | + constexpr friend auto operator+(difference_type, unreachable_iterator) noexcept -> unreachable_iterator { |
| 51 | + return {}; |
| 52 | + } |
| 53 | + |
| 54 | + constexpr auto operator-=(difference_type) noexcept -> unreachable_iterator& { return *this; } |
| 55 | + |
| 56 | + constexpr auto operator-(difference_type) const noexcept -> unreachable_iterator { return *this; } |
| 57 | + |
| 58 | + constexpr auto operator[](difference_type) const noexcept -> RefT { unreachable(); } |
| 59 | + |
| 60 | + constexpr auto operator->() const noexcept -> element_type* |
| 61 | + requires std::derived_from<iterator_concept, std::contiguous_iterator_tag> |
| 62 | + { |
| 63 | + return nullptr; |
| 64 | + } |
| 65 | +}; |
| 66 | + |
| 67 | +} // namespace beman::any_view::detail |
| 68 | + |
| 69 | +#endif // BEMAN_ANY_VIEW_DETAIL_UNREACHABLE_ITERATOR_HPP |
0 commit comments