Skip to content

Commit

Permalink
Use type aliases from base class (iterator_interface)
Browse files Browse the repository at this point in the history
  • Loading branch information
neatudarius committed Jun 24, 2024
1 parent ab1f2c6 commit 34a75c4
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions include/Beman/Optional26/detail/iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,37 @@

namespace beman::optional::detail {

// Forward declaration.
template <class T, class Container>
struct contiguous_iterator;

// Base class for contiguous iterator types with Boost stl_interfaces library.
// Current implementation based on P2727R4: std::iterator_interface.
template <class T, class Container>
using base_contiguous_iterator = stl_interfaces::iterator_interface<
#if !BEMAN_OPTIONAL26_DETAIL_STL_INTERFACES_USE_DEDUCED_THIS
contiguous_iterator<T, Container>, // 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 <class T, class Container>
struct contiguous_iterator : stl_interfaces::iterator_interface<
#if !BEMAN_OPTIONAL26_DETAIL_STL_INTERFACES_USE_DEDUCED_THIS
contiguous_iterator<T, Container>,
#endif
std::contiguous_iterator_tag,
T> {
using iterator_type = T*;
using difference_type = std::iterator_traits<iterator_type>::difference_type;
using reference = std::iterator_traits<iterator_type>::reference;
using pointer = std::iterator_traits<iterator_type>::pointer;

static_assert(std::contiguous_iterator<iterator_type>);
struct contiguous_iterator : public base_contiguous_iterator<T, Container> {
// Alias for the base class.
using base_type = base_contiguous_iterator<T, Container>;
// Alias for types from the base class.
using typename base_type::difference_type;
using typename base_type::iterator_category;
using typename base_type::pointer;
using typename base_type::reference;

// Default constructor.
contiguous_iterator() noexcept : m_current() {}
Expand Down

0 comments on commit 34a75c4

Please sign in to comment.