diff --git a/include/Beman/Optional26/detail/iterator.hpp b/include/Beman/Optional26/detail/iterator.hpp index aab37161..9f29765e 100644 --- a/include/Beman/Optional26/detail/iterator.hpp +++ b/include/Beman/Optional26/detail/iterator.hpp @@ -11,27 +11,36 @@ namespace beman::optional::detail { +// Forward declaration. +template +struct contiguous_iterator; + +// Base class for contiguous iterator types with Boost stl_interfaces library. +// Current implementation based on P2727R4: std::iterator_interface. +template +using base_contiguous_iterator = stl_interfaces::iterator_interface< +#if !BEMAN_OPTIONAL26_DETAIL_STL_INTERFACES_USE_DEDUCED_THIS + contiguous_iterator, // Required for P2727R4 to work with C++20/C++23. TODO: Do more experiments. +#endif + std::contiguous_iterator_tag, + T>; + // This is a minimal contiguous iterator. It uses stl_interfaces library from Boost // (current implementation based on https://wg21.link/P2727R4). // -// TODO: Change this to use the stl_interfaces library from Beman when available. +// TODO: Change this to use the stl_interfaces library from Beman if/when available. // // @tparam T - The type of the elements the iterator points to. // @tparam Container - The type of the container the iterator points to. This parameter exists solely so that different // containers using this template can instantiate different types, even if the T parameter is the same. template -struct contiguous_iterator : stl_interfaces::iterator_interface< -#if !BEMAN_OPTIONAL26_DETAIL_STL_INTERFACES_USE_DEDUCED_THIS - contiguous_iterator, -#endif - std::contiguous_iterator_tag, - T> { - using iterator_type = T*; - using difference_type = std::iterator_traits::difference_type; - using reference = std::iterator_traits::reference; - using pointer = std::iterator_traits::pointer; - - static_assert(std::contiguous_iterator); +struct contiguous_iterator : public base_contiguous_iterator { + // Alias for the base class. + using base_type = base_contiguous_iterator; + // Alias for types from the base class. + using typename base_type::difference_type; + using typename base_type::pointer; + using typename base_type::reference; // Default constructor. contiguous_iterator() noexcept : m_current() {}