Struct iterable_adaptor

Synopsis

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

template<typename It>
struct iterable_adaptor final

Description

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

Template Parameters

It - Type of iterators.

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 61-112 in src/entt/core/iterator.hpp.

template<typename It>
struct iterable_adaptor final {
    /*! @brief Type of the objects returned during iteration. */
    using value_type = typename std::iterator_traits<It>::value_type;
    /*! @brief Iterator type. */
    using iterator = It;
    /*! @brief Const iterator type. */
    using const_iterator = iterator;

    /*! @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(It from, It to)
        : first{from},
          last{to} {}

    /**
     * @brief Returns an iterator to the beginning.
     * @return An iterator to the first element of the range.
     */
    [[nodiscard]] const_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]] const_iterator end() const ENTT_NOEXCEPT {
        return last;
    }

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

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

private:
    It first;
    It last;
};





Add Discussion

Log in to comment