--- title: "poly_span" --- {{< callout >}} Header: `priority_queue.h` Since: `20.31.0` {{< /callout >}} This class implements a view in to a contiguous range through a base type. ```cpp etl::poly_span ``` ## Template deduction guides C++17 ```cpp template poly_span(const TIterator begin, const TIterator end) ->poly_span, etl::dynamic_extent>; ``` ```cpp template poly_span(const TIterator begin, const TSize size) ->poly_span, etl::dynamic_extent>; ``` ```cpp template poly_span(T(&)[N]) -> poly_span; ``` ```cpp template poly_span(etl::array&) -> poly_span; ``` ```cpp template poly_span(const etl::array&) -> poly_span; ``` ```cpp template poly_span(std::array&) ->poly_span; ``` ```cpp template poly_span(const std::array&) ->poly_span; ``` ## Member types ```cpp element_type T value_type remove_cv::type size_type size_t difference_type ptrdiff_t reference value_type& const_reference const value_type& pointer value_type* const_pointer const value_type* iterator Random access iterator reverse_iterator ETL_OR_STD::reverse_iterator ``` ## Constructors ```cpp ETL_CONSTEXPR poly_span() ETL_NOEXCEPT ``` --- ```cpp template ETL_CONSTEXPR poly_span(const TIterator begin, const TSize size) ETL_NOEXCEPT ``` Static asserts if `etl::iterator_traits::iterator_category` is not `random_access_iterator_tag` or `etl::iterator_traits::value_type` is not the same as, or not derived from `TBase`. --- ```cpp template ETL_CONSTEXPR poly_span(const TIterator begin, const TIterator end) ``` Static asserts if `etl::iterator_traits::iterator_category` is not `random_access_iterator_tag` or `etl::iterator_traits::value_type` is not the same as, or not derived from `TBase`. --- ```cpp template ETL_CONSTEXPR poly_span(U(&begin_)[N]) ETL_NOEXCEPT ``` Static asserts if `N` is greater than `Extent` or `etl::iterator_traits::value_type` is not the same as, or not derived from `TBase`. --- ```cpp template ETL_CONSTEXPR poly_span(etl::array& a) ETL_NOEXCEPT ``` Static asserts if `N` is greater than `Extent` or `etl::iterator_traits::value_type` is not the same as, or not derived from `TBase`. --- ```cpp template ETL_CONSTEXPR poly_span(const etl::array& a) ETL_NOEXCEPT ``` Static asserts if `N` is greater than `Extent` or `etl::iterator_traits::value_type` is not the same as, or not derived from `TBase`. --- ```cpp template ETL_CONSTEXPR poly_span(std::array& a) ETL_NOEXCEPT ``` Enabled if `ETL_USING_CPP11` and `ETL_USING_STL` are `true`. Static asserts if `N` is greater than `Extent` or `etl::iterator_traits::value_type` is not the same as, or not derived from `TBase`. --- ```cpp template ETL_CONSTEXPR poly_span(const std::array& a) ETL_NOEXCEPT ``` Enabled if `ETL_USING_CPP11` and `ETL_USING_STL` are `true`. Static asserts if `N` is greater than `Extent` or `etl::iterator_traits::value_type` is not the same as, or not derived from `TBase`. --- ```cpp ETL_CONSTEXPR poly_span(const poly_span& other) ``` Copy constructor. ## Access ```cpp ETL_CONSTEXPR reference operator[](size_t i) const ``` Returns a reference to the indexed element. Index out of range results in undefined behaviour. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT ``` Returns a reference to the first element. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT ``` Returns a reference to the last element. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT ``` Returns a pointer to the first element. --- ```cpp ETL_CONSTEXPR14 poly_span& operator =(const poly_span& other) ETL_NOEXCEPT ``` Assign from a other span --- ```cpp template ETL_CONSTEXPR14 poly_span& operator =(const poly_span& other) ETL_NOEXCEPT ``` Assign from a other span. --- ```cpp template ETL_NODISCARD ETL_CONSTEXPR etl::poly_span first() const ``` Returns a span consisting of the first `COUNT` elements of the current span. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR etl::poly_span last(size_t count) const ``` Returns a span consisting of the last count elements of the current span. --- ```cpp template ETL_NODISCARD ETL_CONSTEXPR etl::poly_span last() const ```cpp Returns a span consisting of the last `COUNT` elements of the current span --- ```cpp ETL_NODISCARD ETL_CONSTEXPR etl::poly_span first(size_t count) const ``` Returns a span consisting of the first count elements of the current span. --- ```cpp template ETL_NODISCARD ETL_CONSTEXPR etl::poly_span subspan() const ``` Returns a subspan consisting of the range starting at `OFFSET` for `COUNT` elements of the current span. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR etl::poly_span subspan(size_t offset, size_t count = etl::dynamic_extent) const ``` Returns a subspan consisting of the range starting at `offset` for `count` elements of the current span. ## Iterators ```cpp ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT ``` Returns an iterator to the beginning of the span. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT ``` Returns an iterator to the end of the span. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR iterator rbegin() const ETL_NOEXCEPT ``` Returns a reverse iterator to the beginning of the span. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR iterator rend() const ETL_NOEXCEPT ``` Returns a reverse iterator to the end of the span. ## Capacity ```cpp ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT ``` Returns true if the size of the span is zero, otherwise false. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT ``` Returns the size of the span. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT ``` Returns the size of the span in bytes. --- ```cpp ETL_NODISCARD ETL_CONSTEXPR size_t size_of_element() const ETL_NOEXCEPT ``` Returns the size of the elements pointed to by the span, in bytes. ## Non-member functions ### Hash There is a specialisation of `etl::hash` for `etl::poly_span`. --- ### Example ```cpp struct Base { virtual ~Base() {} virtual void Print() const = 0; }; struct Derived : Base { Derived(int i_) : i(i_) { } void Print() const override { std::cout << "Derived " << i << "\n"; } int i; }; etl::array data{ Derived(1), Derived(2), Derived(3), Derived(4) }; etl::poly_span ps{ data }; for (const Base& b : ps) { b.Print(); } ```