Struct iterable_adaptor

Synopsis

#include <src/entt/core/iterator.hpp>

template<typename It, typename Sentinel = It>
struct iterable_adaptor final

Description

Utility class to create an iterable object from a pair of iterators.

Template Parameters

It - Type of iterator.

Sentinel - Type of sentinel.

Methods

iterable_adaptor overloadDefault constructor.
iterable_adaptor overloadCreates an iterable object from a pair of iterators.
beginReturns an iterator to the beginning.
cbeginReturns an iterator to the beginning.
cendReturns an iterator to the end.
endReturns an iterator to the end.

Source

Lines 62-113 in src/entt/core/iterator.hpp.

template<typename It, typename Sentinel = It>
struct iterable_adaptor final {
    /*! @brief Value type. */
    using value_type = typename std::iterator_traits<It>::value_type;
    /*! @brief Iterator type. */
    using iterator = It;
    /*! @brief Sentinel type. */
    using sentinel = Sentinel;

    /*! @brief Default constructor. */
    iterable_adaptor() = default;

    /**
     * @brief Creates an iterable object from a pair of iterators.
     * @param from Begin iterator.
     * @param to End iterator.
     */
    iterable_adaptor(iterator from, sentinel to)
        : first{from},
          last{to} {}

    /**
     * @brief Returns an iterator to the beginning.
     * @return An iterator to the first element of the range.
     */
    [[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
        return first;
    }

    /**
     * @brief Returns an iterator to the end.
     * @return An iterator to the element following the last element of the
     * range.
     */
    [[nodiscard]] sentinel end() const ENTT_NOEXCEPT {
        return last;
    }

    /*! @copydoc begin */
    [[nodiscard]] iterator cbegin() const ENTT_NOEXCEPT {
        return begin();
    }

    /*! @copydoc end */
    [[nodiscard]] sentinel cend() const ENTT_NOEXCEPT {
        return end();
    }

private:
    It first;
    Sentinel last;
};





Add Discussion

Log in to comment