Work in progress

This commit is contained in:
John Wellbelove 2022-07-10 14:09:46 +01:00
parent c3e90086a2
commit adf9bd5c20
7 changed files with 1318 additions and 1062 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,42 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2022 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#ifndef ETL_DYNAMIC_EXTENT_INCLUDED
#define ETL_DYNAMIC_EXTENT_INCLUDED
#include "../platform.h"
#include "../integral_limits.h"
namespace etl
{
static ETL_CONSTANT size_t dynamic_extent = etl::integral_limits<size_t>::max;
}
#endif

View File

@ -40,6 +40,8 @@ SOFTWARE.
#include "memory.h"
#include "array.h"
#include "private/dynamic_extent.h"
#if ETL_USING_CPP11 && ETL_USING_STL
#include <array>
#endif
@ -49,36 +51,34 @@ SOFTWARE.
namespace etl
{
static ETL_CONSTANT size_t dynamic_extent = etl::integral_limits<size_t>::max;
//***************************************************************************
/// Span
//***************************************************************************
template <typename T, size_t EXTENT = etl::dynamic_extent>
template <typename T, size_t Extent = etl::dynamic_extent>
class span
{
public:
typedef T element_type;
typedef typename etl::remove_cv<T>::type value_type;
typedef size_t size_type;
typedef T& reference;
typedef const T& const_reference;
typedef T* pointer;
typedef const T* const_pointer;
typedef T* iterator;
typedef const T* const_iterator;
typedef T element_type;
typedef typename etl::remove_cv<T>::type value_type;
typedef size_t size_type;
typedef T& reference;
typedef const T& const_reference;
typedef T* pointer;
typedef const T* const_pointer;
typedef T* iterator;
typedef const T* const_iterator;
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
static ETL_CONSTANT size_t extent = EXTENT;
static ETL_CONSTANT size_t extent = Extent;
//*************************************************************************
/// Default constructor.
//*************************************************************************
ETL_CONSTEXPR span() ETL_NOEXCEPT
: mbegin(ETL_NULLPTR)
, mend(ETL_NULLPTR)
: pbegin(ETL_NULLPTR)
{
}
@ -87,8 +87,7 @@ namespace etl
//*************************************************************************
template <typename TIterator, typename TSize>
ETL_CONSTEXPR span(const TIterator begin_, const TSize size_) ETL_NOEXCEPT
: mbegin(etl::addressof(*begin_))
, mend(etl::addressof(*begin_) + size_)
: pbegin(etl::addressof(*begin_))
{
}
@ -97,8 +96,7 @@ namespace etl
//*************************************************************************
template <typename TIterator>
ETL_CONSTEXPR span(const TIterator begin_, const TIterator end_)
: mbegin(etl::addressof(*begin_))
, mend(etl::addressof(*begin_) + etl::distance(begin_, end_))
: pbegin(etl::addressof(*begin_))
{
}
@ -107,8 +105,7 @@ namespace etl
//*************************************************************************
template<size_t ARRAY_SIZE>
ETL_CONSTEXPR span(element_type(&begin_)[ARRAY_SIZE]) ETL_NOEXCEPT
: mbegin(begin_)
, mend(begin_ + ARRAY_SIZE)
: pbegin(begin_)
{
}
@ -116,20 +113,18 @@ namespace etl
//*************************************************************************
/// Construct from etl::array.
//*************************************************************************
template <typename U, size_t N, typename = typename etl::enable_if<(N == EXTENT) && etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
template <typename U, size_t N, typename = typename etl::enable_if<(N == Extent) && etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR span(etl::array<U, N>& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
{
}
//*************************************************************************
/// Construct from etl::array.
//*************************************************************************
template <typename U, size_t N, typename = typename etl::enable_if<(N == EXTENT) && etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
template <typename U, size_t N, typename = typename etl::enable_if<(N == Extent) && etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR span(const etl::array<U, N>& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
{
}
#else
@ -137,9 +132,8 @@ namespace etl
/// Construct from etl::array.
//*************************************************************************
template <typename U, size_t N>
ETL_CONSTEXPR span(etl::array<U, N>& a, typename etl::enable_if<(N == EXTENT) && etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
ETL_CONSTEXPR span(etl::array<U, N>& a, typename etl::enable_if<(N == Extent) && etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type) ETL_NOEXCEPT
: pbegin(a.data())
{
}
@ -147,9 +141,8 @@ namespace etl
/// Construct from etl::array.
//*************************************************************************
template <typename U, size_t N>
ETL_CONSTEXPR span(const etl::array<U, N>& a, typename etl::enable_if<(N == EXTENT) && etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
ETL_CONSTEXPR span(const etl::array<U, N>& a, typename etl::enable_if<(N == Extent) && etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type) ETL_NOEXCEPT
: pbegin(a.data())
{
}
#endif
@ -158,20 +151,18 @@ namespace etl
//*************************************************************************
/// Construct from std::array.
//*************************************************************************
template <typename U, size_t N, typename = typename etl::enable_if<(N == EXTENT) && etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
template <typename U, size_t N, typename = typename etl::enable_if<(N == Extent) && etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR span(std::array<U, N>& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
{
}
//*************************************************************************
/// Construct from std::array.
//*************************************************************************
template <typename U, size_t N, typename = typename etl::enable_if<(N == EXTENT) && etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
template <typename U, size_t N, typename = typename etl::enable_if<(N == Extent) && etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR span(const std::array<U, N>& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
{
}
#endif
@ -180,8 +171,7 @@ namespace etl
/// Copy constructor
//*************************************************************************
ETL_CONSTEXPR span(const span& other) ETL_NOEXCEPT
: mbegin(other.mbegin)
, mend(other.mend)
: pbegin(other.pbegin)
{
}
@ -190,7 +180,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
{
return *mbegin;
return *pbegin;
}
//*************************************************************************
@ -198,7 +188,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
{
return *(mend - 1);
return *((pbegin + Extent) - 1);
}
//*************************************************************************
@ -206,7 +196,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
{
return mbegin;
return pbegin;
}
//*************************************************************************
@ -214,7 +204,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
{
return mbegin;
return pbegin;
}
//*************************************************************************
@ -222,7 +212,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
{
return mend;
return (pbegin + Extent);
}
//*************************************************************************
@ -230,7 +220,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR reverse_iterator rbegin() const ETL_NOEXCEPT
{
return reverse_iterator(mend);
return reverse_iterator((pbegin + Extent));
}
//*************************************************************************
@ -238,7 +228,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
{
return reverse_iterator(mbegin);
return reverse_iterator(pbegin);
}
//*************************************************************************
@ -246,7 +236,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
{
return (mbegin == mend);
return false;
}
//*************************************************************************
@ -254,7 +244,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
{
return (mend - mbegin);
return Extent;
}
//*************************************************************************
@ -262,7 +252,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
{
return sizeof(element_type) * (mend - mbegin);
return sizeof(element_type) * Extent;
}
//*************************************************************************
@ -278,8 +268,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR14 span& operator =(const span& other) ETL_NOEXCEPT
{
mbegin = other.mbegin;
mend = other.mend;
pbegin = other.pbegin;
return *this;
}
@ -288,7 +277,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR reference operator[](const size_t i) const
{
return mbegin[i];
return pbegin[i];
}
//*************************************************************************
@ -297,7 +286,7 @@ namespace etl
template <size_t COUNT>
ETL_CONSTEXPR etl::span<element_type, COUNT> first() const
{
return etl::span<element_type, COUNT>(mbegin, mbegin + COUNT);
return etl::span<element_type, COUNT>(pbegin, pbegin + COUNT);
}
//*************************************************************************
@ -305,7 +294,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR etl::span<element_type, etl::dynamic_extent> first(size_t count) const
{
return etl::span<element_type, etl::dynamic_extent>(mbegin, mbegin + count);
return etl::span<element_type, etl::dynamic_extent>(pbegin, pbegin + count);
}
//*************************************************************************
@ -314,7 +303,7 @@ namespace etl
template <size_t COUNT>
ETL_CONSTEXPR etl::span<element_type, COUNT> last() const
{
return etl::span<element_type, COUNT>(mend - COUNT, mend);
return etl::span<element_type, COUNT>((pbegin + Extent) - COUNT, (pbegin + Extent));
}
//*************************************************************************
@ -322,7 +311,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR etl::span<element_type, etl::dynamic_extent> last(size_t count) const
{
return etl::span<element_type, etl::dynamic_extent>(mend - count, mend);
return etl::span<element_type, etl::dynamic_extent>((pbegin + Extent) - count, (pbegin + Extent));
}
#if ETL_USING_CPP11
@ -331,15 +320,15 @@ namespace etl
//*************************************************************************
template <const size_t OFFSET, size_t COUNT = etl::dynamic_extent>
ETL_CONSTEXPR
etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (EXTENT != etl::dynamic_extent ? EXTENT - OFFSET : etl::dynamic_extent))> subspan() const
etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (Extent != etl::dynamic_extent ? Extent - OFFSET : etl::dynamic_extent))> subspan() const
{
if (COUNT == etl::dynamic_extent)
{
return etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (EXTENT != etl::dynamic_extent ? EXTENT - OFFSET : etl::dynamic_extent))>(mbegin + OFFSET, mend);
return etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (Extent != etl::dynamic_extent ? Extent - OFFSET : etl::dynamic_extent))>(pbegin + OFFSET, (pbegin + Extent));
}
else
{
return etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (EXTENT != etl::dynamic_extent ? EXTENT - OFFSET : etl::dynamic_extent))>(mbegin + OFFSET, mbegin + OFFSET + COUNT);
return etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (Extent != etl::dynamic_extent ? Extent - OFFSET : etl::dynamic_extent))>(pbegin + OFFSET, pbegin + OFFSET + COUNT);
}
}
#else
@ -348,15 +337,15 @@ namespace etl
//*************************************************************************
template <const size_t OFFSET, size_t COUNT>
ETL_CONSTEXPR
etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (EXTENT != etl::dynamic_extent ? EXTENT - OFFSET : etl::dynamic_extent))> subspan() const
etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (Extent != etl::dynamic_extent ? Extent - OFFSET : etl::dynamic_extent))> subspan() const
{
if (COUNT == etl::dynamic_extent)
{
return etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (EXTENT != etl::dynamic_extent ? EXTENT - OFFSET : etl::dynamic_extent))>(mbegin + OFFSET, mend);
return etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (Extent != etl::dynamic_extent ? Extent - OFFSET : etl::dynamic_extent))>(pbegin + OFFSET, (pbegin + Extent));
}
else
{
return etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (EXTENT != etl::dynamic_extent ? EXTENT - OFFSET : etl::dynamic_extent))>(mbegin + OFFSET, mbegin + OFFSET + COUNT);
return etl::span<element_type, (COUNT != etl::dynamic_extent ? COUNT : (Extent != etl::dynamic_extent ? Extent - OFFSET : etl::dynamic_extent))>(pbegin + OFFSET, pbegin + OFFSET + COUNT);
}
}
#endif
@ -368,18 +357,17 @@ namespace etl
{
if (count == etl::dynamic_extent)
{
return etl::span<element_type, etl::dynamic_extent>(mbegin + offset, mend);
return etl::span<element_type, etl::dynamic_extent>(pbegin + offset, (pbegin + Extent));
}
else
{
return etl::span<element_type, etl::dynamic_extent>(mbegin + offset, mbegin + offset + count);
return etl::span<element_type, etl::dynamic_extent>(pbegin + offset, pbegin + offset + count);
}
}
private:
element_type* mbegin;
element_type* mend;
pointer pbegin;
};
//***************************************************************************
@ -408,8 +396,8 @@ namespace etl
/// Default constructor.
//*************************************************************************
ETL_CONSTEXPR span() ETL_NOEXCEPT
: mbegin(ETL_NULLPTR)
, mend(ETL_NULLPTR)
: pbegin(ETL_NULLPTR)
, pend(ETL_NULLPTR)
{
}
@ -418,8 +406,8 @@ namespace etl
//*************************************************************************
template <typename TIterator, typename TSize>
ETL_CONSTEXPR span(const TIterator begin_, const TSize size_) ETL_NOEXCEPT
: mbegin(etl::addressof(*begin_))
, mend(etl::addressof(*begin_) + size_)
: pbegin(etl::addressof(*begin_))
, pend(etl::addressof(*begin_) + size_)
{
}
@ -428,8 +416,8 @@ namespace etl
//*************************************************************************
template <typename TIterator>
ETL_CONSTEXPR span(const TIterator begin_, const TIterator end_)
: mbegin(etl::addressof(*begin_))
, mend(etl::addressof(*begin_) + etl::distance(begin_, end_))
: pbegin(etl::addressof(*begin_))
, pend(etl::addressof(*begin_) + etl::distance(begin_, end_))
{
}
@ -438,8 +426,8 @@ namespace etl
//*************************************************************************
template<size_t ARRAY_SIZE>
ETL_CONSTEXPR span(element_type(&begin_)[ARRAY_SIZE]) ETL_NOEXCEPT
: mbegin(begin_)
, mend(begin_ + ARRAY_SIZE)
: pbegin(begin_)
, pend(begin_ + ARRAY_SIZE)
{
}
@ -449,8 +437,8 @@ namespace etl
//*************************************************************************
template <typename U, size_t N, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR span(etl::array<U, N>& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
, pend(a.data() + a.size())
{
}
@ -459,8 +447,8 @@ namespace etl
//*************************************************************************
template <typename U, size_t N, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR span(const etl::array<U, N>& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
, pend(a.data() + a.size())
{
}
#else
@ -469,8 +457,8 @@ namespace etl
//*************************************************************************
template <typename U, size_t N>
ETL_CONSTEXPR span(etl::array<U, N>& a, typename etl::enable_if<etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
, pend(a.data() + a.size())
{
}
@ -479,8 +467,8 @@ namespace etl
//*************************************************************************
template <typename U, size_t N>
ETL_CONSTEXPR span(const etl::array<U, N>& a, typename etl::enable_if<etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
, pend(a.data() + a.size())
{
}
#endif
@ -491,8 +479,8 @@ namespace etl
//*************************************************************************
template <typename U, size_t N, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR span(std::array<U, N>& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
, pend(a.data() + a.size())
{
}
@ -501,8 +489,8 @@ namespace etl
//*************************************************************************
template <typename U, size_t N, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR span(const std::array<U, N>& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
, pend(a.data() + a.size())
{
}
#endif
@ -516,8 +504,8 @@ namespace etl
!etl::is_array<etl::remove_reference_t<TContainer>>::value &&
etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<typename etl::remove_reference_t<TContainer>::value_type>>::value, void>::type>
ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
, pend(a.data() + a.size())
{
}
#else
@ -529,8 +517,8 @@ namespace etl
ETL_CONSTEXPR span(TContainer& a, typename etl::enable_if<!etl::is_pointer<typename etl::remove_reference<TContainer>::type>::value &&
!etl::is_array<TContainer>::value &&
etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
, pend(a.data() + a.size())
{
}
@ -542,8 +530,8 @@ namespace etl
ETL_CONSTEXPR span(const TContainer& a, typename etl::enable_if<!etl::is_pointer<typename etl::remove_reference<TContainer>::type>::value &&
!etl::is_array<TContainer>::value &&
etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type) ETL_NOEXCEPT
: mbegin(a.data())
, mend(a.data() + a.size())
: pbegin(a.data())
, pend(a.data() + a.size())
{
}
#endif
@ -552,8 +540,8 @@ namespace etl
/// Copy constructor
//*************************************************************************
ETL_CONSTEXPR span(const span& other) ETL_NOEXCEPT
: mbegin(other.mbegin)
, mend(other.mend)
: pbegin(other.pbegin)
, pend(other.pend)
{
}
@ -562,7 +550,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
{
return *mbegin;
return *pbegin;
}
//*************************************************************************
@ -570,7 +558,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
{
return *(mend - 1);
return *(pend - 1);
}
//*************************************************************************
@ -578,7 +566,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
{
return mbegin;
return pbegin;
}
//*************************************************************************
@ -586,7 +574,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
{
return mbegin;
return pbegin;
}
//*************************************************************************
@ -594,7 +582,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
{
return mend;
return pend;
}
//*************************************************************************
@ -602,7 +590,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR reverse_iterator rbegin() const ETL_NOEXCEPT
{
return reverse_iterator(mend);
return reverse_iterator(pend);
}
//*************************************************************************
@ -610,7 +598,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
{
return reverse_iterator(mbegin);
return reverse_iterator(pbegin);
}
//*************************************************************************
@ -618,7 +606,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
{
return (mbegin == mend);
return (pbegin == pend);
}
//*************************************************************************
@ -626,7 +614,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
{
return (mend - mbegin);
return (pend - pbegin);
}
//*************************************************************************
@ -634,7 +622,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
{
return sizeof(element_type) * (mend - mbegin);
return sizeof(element_type) * (pend - pbegin);
}
//*************************************************************************
@ -650,8 +638,8 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR14 span& operator =(const span& other) ETL_NOEXCEPT
{
mbegin = other.mbegin;
mend = other.mend;
pbegin = other.pbegin;
pend = other.pend;
return *this;
}
@ -660,7 +648,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR reference operator[](const size_t i) const
{
return mbegin[i];
return pbegin[i];
}
//*************************************************************************
@ -669,7 +657,7 @@ namespace etl
template <size_t COUNT>
ETL_CONSTEXPR etl::span<element_type, COUNT> first() const
{
return etl::span<element_type, COUNT>(mbegin, mbegin + COUNT);
return etl::span<element_type, COUNT>(pbegin, pbegin + COUNT);
}
//*************************************************************************
@ -677,7 +665,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR etl::span<element_type, etl::dynamic_extent> first(size_t count) const
{
return etl::span<element_type, etl::dynamic_extent>(mbegin, mbegin + count);
return etl::span<element_type, etl::dynamic_extent>(pbegin, pbegin + count);
}
//*************************************************************************
@ -686,7 +674,7 @@ namespace etl
template <size_t COUNT>
ETL_CONSTEXPR etl::span<element_type, COUNT> last() const
{
return etl::span<element_type, COUNT>(mend - COUNT, mend);
return etl::span<element_type, COUNT>(pend - COUNT, pend);
}
//*************************************************************************
@ -694,7 +682,7 @@ namespace etl
//*************************************************************************
ETL_CONSTEXPR etl::span<element_type, etl::dynamic_extent> last(size_t count) const
{
return etl::span<element_type, etl::dynamic_extent>(mend - count, mend);
return etl::span<element_type, etl::dynamic_extent>(pend - count, pend);
}
#if ETL_USING_CPP11
@ -707,11 +695,11 @@ namespace etl
{
if (COUNT == etl::dynamic_extent)
{
return etl::span<element_type, COUNT>(mbegin + OFFSET, mend);
return etl::span<element_type, COUNT>(pbegin + OFFSET, pend);
}
else
{
return etl::span<element_type, COUNT>(mbegin + OFFSET, mbegin + OFFSET + COUNT);
return etl::span<element_type, COUNT>(pbegin + OFFSET, pbegin + OFFSET + COUNT);
}
}
#else
@ -724,11 +712,11 @@ namespace etl
{
if (COUNT == etl::dynamic_extent)
{
return etl::span<element_type, COUNT>(mbegin + OFFSET, mend);
return etl::span<element_type, COUNT>(pbegin + OFFSET, pend);
}
else
{
return etl::span<element_type, COUNT>(mbegin + OFFSET, mbegin + OFFSET + COUNT);
return etl::span<element_type, COUNT>(pbegin + OFFSET, pbegin + OFFSET + COUNT);
}
}
#endif
@ -740,15 +728,15 @@ namespace etl
{
if (count == etl::dynamic_extent)
{
return etl::span<element_type, etl::dynamic_extent>(mbegin + offset, mend);
return etl::span<element_type, etl::dynamic_extent>(pbegin + offset, pend);
}
return etl::span<element_type, etl::dynamic_extent>(mbegin + offset, mbegin + offset + count);
return etl::span<element_type, etl::dynamic_extent>(pbegin + offset, pbegin + offset + count);
}
private:
element_type* mbegin;
element_type* mend;
pointer pbegin;
pointer pend;
};
//*************************************************************************

View File

@ -1,365 +0,0 @@
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2020 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include "unit_test_framework.h"
#include "etl/poly_span.h"
#include <array>
#include <vector>
#include <algorithm>
#include <iterator>
#include <vector>
namespace
{
//***************************************************************************
struct Base
{
virtual int value() const = 0;
virtual bool operator==(const Base& o) const { return value() == o.value(); }
};
//***************************************************************************
struct Derived : Base
{
Derived(int v) : m_value(v) {}
int value() const override { return m_value; }
int m_value;
};
//***************************************************************************
struct AnotherBase
{
virtual double another_value() const { return v; };
double v = 0;
};
//***************************************************************************
struct MultiDerived : AnotherBase, Base
{
MultiDerived(int v) : m_value(v) {}
int value() const override { return m_value; }
int m_value;
};
//***************************************************************************
template <typename TSpan, typename TSource>
bool equal(const TSpan& span, TSource& source)
{
auto sb = std::begin(source);
return (span.size() == (std::end(source) - sb)) && std::equal(span.begin(), span.end(), sb);
}
SUITE(test_poly_span)
{
//*************************************************************************
TEST(test_poly_span_defaultConstruct)
{
etl::poly_span<Base> s{};
CHECK(s.empty());
CHECK_EQUAL(0, s.size());
CHECK(s.begin() == s.end());
}
//*************************************************************************
TEST(test_poly_span_constructFromVec)
{
std::vector<int> v = { 1, 2, 3 };
etl::poly_span<int> s = v;
CHECK_EQUAL(s[0], v[0]);
CHECK_EQUAL(s[1], v[1]);
CHECK_EQUAL(s[2], v[2]);
CHECK_EQUAL(v.size(), s.size());
CHECK_EQUAL(sizeof(v[0]), s.element_size());
CHECK(!s.empty());
}
//*************************************************************************
TEST(test_poly_span_constructFromVecRespectConst)
{
std::vector<Derived> v;
const auto& cv = v;
etl::poly_span<const Base> s1 = v;
etl::poly_span<const Base>{v};
etl::poly_span<const Base> s2 = cv;
etl::poly_span<const Base>{cv};
etl::poly_span<Derived> s3 = v;
etl::poly_span<Base>{v};
// The line below shouldn't work if uncommented
// etl::poly_span<int>{cv};
}
//*************************************************************************
TEST(test_poly_span_constructFromCArray)
{
int a[] = { 1, 2, 3 };
etl::poly_span<const int> s = a;
CHECK_EQUAL(s[0], a[0]);
CHECK_EQUAL(s[1], a[1]);
CHECK_EQUAL(s[2], a[2]);
CHECK_EQUAL(3, s.size());
CHECK_EQUAL(sizeof(a[0]), s.element_size());
}
//*************************************************************************
TEST(test_poly_span_constructFromCArrayRespectConst)
{
Derived ar[2] = { 1, 2 };
const auto& car = ar;
etl::poly_span<const Base> s1 = ar;
etl::poly_span<const Base>{ar};
etl::poly_span<const Derived> s2 = car;
etl::poly_span<const Derived>{car};
etl::poly_span<Base> s3 = ar;
etl::poly_span<Base>{ar};
// The line below shouldn't work if uncommented
// etl::poly_span<int>{car};
}
//*************************************************************************
TEST(test_poly_span_constructFromArray)
{
std::array<int, 3> a = { 1, 2, 3 };
etl::poly_span<int> s = a;
CHECK_EQUAL(s[0], a[0]);
CHECK_EQUAL(s[1], a[1]);
CHECK_EQUAL(s[2], a[2]);
}
//*************************************************************************
TEST(test_poly_span_constructFromPolySpan)
{
std::array<Derived, 3> a = { 1, 2, 3 };
etl::poly_span<Derived> s1 = a;
etl::poly_span<Base> s2 = s1;
etl::poly_span<const Base>{s2};
CHECK(equal(s1, s2));
}
//*************************************************************************
TEST(test_poly_span_constructFromIterator)
{
std::vector<int> v = { 1, 2, 3, 4 };
etl::poly_span<int> s1{ v.begin() + 1, v.end() };
CHECK_EQUAL(v.size() - 1, s1.size());
CHECK_EQUAL(s1[0], v[1]);
CHECK_EQUAL(s1[1], v[2]);
CHECK_EQUAL(s1[2], v[3]);
etl::poly_span<const int> s2{ v.data() + 1, v.data() + v.size() };
CHECK(equal(s1, s2));
etl::poly_span<const int> s3{ v.cbegin(), v.size() };
CHECK(equal(s3, v));
}
//*************************************************************************
TEST(test_poly_span_constructFromInitializerList)
{
const int data[] = { 1, 2, 3, 4, 5 };
etl::poly_span<const int> s(data);
CHECK_EQUAL(5, s.size());
for (int i = 0; i < 5; ++i)
{
//int x = s[i];
//CHECK_EQUAL(i + 1, s[i]);
}
}
//*************************************************************************
TEST(test_poly_span_DerivedToBase)
{
std::vector<Derived> v1 = { 0, 1, 2 };
Derived a1[] = { 0, 1, 2 };
CHECK(sizeof(Derived) > sizeof(Base));
etl::poly_span<const Base> s1 = v1;
CHECK_EQUAL(sizeof(Derived), s1.element_size());
etl::poly_span<Base> s2 = a1;
auto it1 = s1.begin();
auto it2 = s2.begin();
for (int i = 0; i < 3; ++i, ++it1, ++it2)
{
CHECK_EQUAL(i, s1[i].value());
CHECK_EQUAL(i, s2[i].value());
CHECK_EQUAL(i, it1->value());
CHECK_EQUAL(i, it2->value());
}
}
//*************************************************************************
TEST(test_poly_span_MultiDerivedToBase)
{
std::vector<MultiDerived> v1 = { 0, 1, 2 };
etl::poly_span<Base> s1 = v1;
CHECK(static_cast<void*>(v1.data()) != static_cast<void*>(&s1.front()));
CHECK(equal(s1, v1));
}
//*************************************************************************
TEST(test_poly_span_typeProperties)
{
CHECK(std::is_trivial<etl::poly_span<int>::iterator>::value);
CHECK(std::is_trivial<etl::poly_span<const Base>::iterator>::value);
CHECK(std::is_trivial<etl::poly_span<int>::const_iterator>::value);
CHECK(bool(std::is_base_of<ETL_OR_STD::random_access_iterator_tag, etl::poly_span<int>::iterator::iterator_category>::value));
CHECK(std::is_trivially_copy_constructible<etl::poly_span<int>>::value);
CHECK(std::is_trivially_copy_assignable<etl::poly_span<int>>::value);
}
//*************************************************************************
//TEST(test_poly_span_iterators)
//{
// std::vector<int> v = { 1, 2, 3 };
// etl::poly_span<int> s = v;
// using iterator = etl::poly_span<int>::iterator;
//
// CHECK_EQUAL(s.end() - s.begin(), s.size());
// CHECK_EQUAL(s.rend() - s.rbegin(), s.size());
//
// iterator b = s.begin();
// CHECK(b + s.size() == s.end());
// CHECK_EQUAL(b[0], 1);
// CHECK(b < s.end());
// CHECK(b != s.end());
// CHECK(b + 2 > s.end() - 1);
// etl::poly_span<int>::const_iterator bc = b;
// CHECK(bc <= s.end());
// CHECK_EQUAL(s.back(), *s.crbegin());
// CHECK_EQUAL(s.front(), s.crend()[-1]);
//
// bc += 1;
// bc -= 1;
// CHECK(bc == s.cbegin());
// CHECK(std::is_sorted(s.cbegin(), s.cend()));
//}
//*************************************************************************
TEST(test_poly_span_randomAccessIteratorUse)
{
int data[] = { 25, 4, 3, -2, 1 };
etl::poly_span<int> s = data;
std::sort(s.begin(), s.end());
CHECK(std::is_sorted(std::begin(data), std::end(data)));
}
//*************************************************************************
TEST(test_poly_span_subspan)
{
const int data[] = { 1, 2, 3, 4, 5 };
etl::poly_span<const int> s(data);
auto s1 = s.subspan(1, 2);
CHECK_EQUAL(2, s1.size());
CHECK_EQUAL(s[1], s1[0]);
CHECK_EQUAL(s[2], s1[1]);
auto s2 = s.subspan(2);
CHECK_EQUAL(3, s2.size());
CHECK_EQUAL(s[2], s2[0]);
CHECK_EQUAL(s[4], s2[2]);
auto s3 = s.subspan(0, 10);
CHECK_EQUAL(s.size(), s3.size());
CHECK_THROW(s.subspan(6, 1), etl::poly_span_out_of_range);
}
//*************************************************************************
TEST(test_poly_span_first)
{
const int data[] = { 1, 2, 3, 4, 5 };
etl::poly_span<const int> s(data);
CHECK_THROW(s.first(6), etl::poly_span_out_of_range);
CHECK_EQUAL(s.first(5).size(), 5);
CHECK(s.first(0).empty());
auto s1 = s.first(3);
CHECK_EQUAL(3, s1.size());
CHECK_EQUAL(1, s1[0]);
CHECK_EQUAL(3, s1[2]);
}
//*************************************************************************
TEST(test_poly_span_last)
{
const int data[] = { 1, 2, 3, 4, 5 };
etl::poly_span<const int> s(data);
CHECK_THROW(s.last(6), etl::poly_span_out_of_range);
CHECK_EQUAL(s.last(5).size(), 5);
auto s2 = s.last(2);
CHECK_EQUAL(2, s2.size());
CHECK_EQUAL(4, s2[0]);
CHECK_EQUAL(5, s2[1]);
}
//*************************************************************************
TEST(test_poly_span_equal_view)
{
std::vector<double> v = { 1.0, 2.0, 3.0 };
etl::poly_span<double> s1 = v;
etl::poly_span<const double> cs2 = v;
CHECK(!etl::poly_span<const double>{}.equal_view(s1));
CHECK(s1.equal_view(cs2));
CHECK(s1.last(2).equal_view(cs2.subspan(1)));
}
//*************************************************************************
TEST(test_poly_span_at)
{
const int data[] = { 1, 2, 3 };
etl::poly_span<const int> s(data);
CHECK_EQUAL(s.at(0), 1);
CHECK_EQUAL(s.at(2), 3);
CHECK_THROW(s.at(3), etl::poly_span_out_of_range);
CHECK_THROW(s.at(-1), etl::poly_span_out_of_range);
}
}
}

View File

@ -0,0 +1,381 @@
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2020 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include "unit_test_framework.h"
#include "etl/poly_span.h"
#include <array>
#include <vector>
#include <algorithm>
#include <iterator>
#include <vector>
namespace
{
//***************************************************************************
struct Base
{
virtual int value() const = 0;
virtual bool operator ==(const Base& rhs) const
{
return value() == rhs.value();
}
};
//***************************************************************************
struct AnotherBase
{
virtual double another_value() const = 0;
virtual bool operator ==(const AnotherBase& rhs) const
{
return another_value() == rhs.another_value();
}
};
//***************************************************************************
struct Derived : Base
{
Derived(int v_)
: v1(v_)
{
}
int value() const override
{
return v1;
}
int v1;
};
//***************************************************************************
struct MultiDerived : AnotherBase, Base
{
MultiDerived(int v1_, double v2_)
: v1(v1_)
, v2(v2_)
{
}
int value() const override
{
return v1;
}
double another_value() const override
{
return v2;
}
int v1;
double v2;
};
//***************************************************************************
template <typename TSpan, typename TSource>
bool equal(const TSpan& span, TSource& source)
{
auto sb = std::begin(source);
return (span.size() == (std::end(source) - sb)) && std::equal(span.begin(), span.end(), sb);
}
SUITE(test_poly_span_dynamic_extent)
{
//*************************************************************************
TEST(test_poly_span_default_construct)
{
etl::poly_span<Base> s;
CHECK_EQUAL(0U, s.size_of_element());
CHECK(s.empty());
CHECK_EQUAL(0U, s.size());
CHECK_EQUAL(0U, s.size_bytes());
//CHECK(s.begin() == s.end());
}
//*************************************************************************
TEST(test_poly_span_construct_from_iterators)
{
std::vector<Derived> data = { 1, 2, 3, 4 };
etl::poly_span<Base> s(data.begin(), data.end());
CHECK_EQUAL(sizeof(Derived), s.size_of_element());
CHECK(!s.empty());
CHECK_EQUAL(data.size(), s.size());
CHECK_EQUAL(s.size() * sizeof(Derived), s.size_bytes());
CHECK_EQUAL(data[0].value(), s[0].value());
CHECK_EQUAL(data[1].value(), s[1].value());
CHECK_EQUAL(data[2].value(), s[2].value());
CHECK_EQUAL(data[3].value(), s[3].value());
}
//*************************************************************************
TEST(test_poly_span_construct_from_c_array)
{
Derived data[] = { 1, 2, 3, 4 };
etl::poly_span<Base> s(data);
CHECK_EQUAL(sizeof(Derived), s.size_of_element());
CHECK(!s.empty());
CHECK_EQUAL(std::size(data), s.size());
CHECK_EQUAL(s.size() * sizeof(Derived), s.size_bytes());
CHECK_EQUAL(data[0].value(), s[0].value());
CHECK_EQUAL(data[1].value(), s[1].value());
CHECK_EQUAL(data[2].value(), s[2].value());
CHECK_EQUAL(data[3].value(), s[3].value());
}
//*************************************************************************
TEST(test_poly_span_construct_from_const_c_array)
{
const Derived data[] = { 1, 2, 3, 4 };
etl::poly_span<const Base> s(data);
CHECK_EQUAL(sizeof(Derived), s.size_of_element());
CHECK(!s.empty());
CHECK_EQUAL(std::size(data), s.size());
CHECK_EQUAL(s.size() * sizeof(Derived), s.size_bytes());
CHECK_EQUAL(data[0].value(), s[0].value());
CHECK_EQUAL(data[1].value(), s[1].value());
CHECK_EQUAL(data[2].value(), s[2].value());
CHECK_EQUAL(data[3].value(), s[3].value());
}
//*************************************************************************
TEST(test_poly_span_construct_from_std_array)
{
std::array data{ Derived(1), Derived(2), Derived(3), Derived(4) };
etl::poly_span<Base> s(data);
CHECK(!s.empty());
CHECK_EQUAL(data.size(), s.size());
CHECK_EQUAL(s.size() * sizeof(Derived), s.size_bytes());
CHECK_EQUAL(data[0].value(), s[0].value());
CHECK_EQUAL(data[1].value(), s[1].value());
CHECK_EQUAL(data[2].value(), s[2].value());
CHECK_EQUAL(data[3].value(), s[3].value());
}
//*************************************************************************
TEST(test_poly_span_construct_from_const_std_array)
{
const std::array data{ Derived(1), Derived(2), Derived(3), Derived(4) };
etl::poly_span<const Base> s(data);
CHECK(!s.empty());
CHECK_EQUAL(data.size(), s.size());
CHECK_EQUAL(s.size() * sizeof(Derived), s.size_bytes());
CHECK_EQUAL(data[0].value(), s[0].value());
CHECK_EQUAL(data[1].value(), s[1].value());
CHECK_EQUAL(data[2].value(), s[2].value());
CHECK_EQUAL(data[3].value(), s[3].value());
}
//*************************************************************************
TEST(test_poly_span_construct_from_etl_array)
{
etl::array data{ Derived(1), Derived(2), Derived(3), Derived(4) };
etl::poly_span<Base> s(data);
CHECK(!s.empty());
CHECK_EQUAL(data.size(), s.size());
CHECK_EQUAL(s.size() * sizeof(Derived), s.size_bytes());
CHECK_EQUAL(data[0].value(), s[0].value());
CHECK_EQUAL(data[1].value(), s[1].value());
CHECK_EQUAL(data[2].value(), s[2].value());
CHECK_EQUAL(data[3].value(), s[3].value());
}
//*************************************************************************
TEST(test_poly_span_construct_from_const_etl_array)
{
const etl::array data{ Derived(1), Derived(2), Derived(3), Derived(4) };
etl::poly_span<const Base> s(data);
CHECK(!s.empty());
CHECK_EQUAL(data.size(), s.size());
CHECK_EQUAL(s.size() * sizeof(Derived), s.size_bytes());
CHECK_EQUAL(data[0].value(), s[0].value());
CHECK_EQUAL(data[1].value(), s[1].value());
CHECK_EQUAL(data[2].value(), s[2].value());
CHECK_EQUAL(data[3].value(), s[3].value());
}
//*************************************************************************
TEST(test_poly_span_copy_construct)
{
std::array<Derived, 4> a = { 1, 2, 3, 4 };
etl::poly_span<Base> s1 = a;
etl::poly_span<Base> s2 = s1;
const etl::poly_span<const Base> s3 = s1;
//CHECK(equal(s1, s2));
CHECK(!s2.empty());
CHECK(!s3.empty());
}
//*************************************************************************
TEST(test_poly_span_multi_derived)
{
std::vector<MultiDerived> data = { { 0, 1.2 }, { 1, 2.3 }, { 2, 3.4 }, { 3, 4.5 } };
etl::poly_span<Base> s1(data.begin(), data.end());
etl::poly_span<AnotherBase> s2(data.begin(), data.end());
CHECK_EQUAL(data[0].value(), s1[0].value());
CHECK_EQUAL(data[1].value(), s1[1].value());
CHECK_EQUAL(data[2].value(), s1[2].value());
CHECK_EQUAL(data[3].value(), s1[3].value());
CHECK_EQUAL(data[0].another_value(), s2[0].another_value());
CHECK_EQUAL(data[1].another_value(), s2[1].another_value());
CHECK_EQUAL(data[2].another_value(), s2[2].another_value());
CHECK_EQUAL(data[3].another_value(), s2[3].another_value());
}
////*************************************************************************
//TEST(test_poly_span_typeProperties)
//{
// CHECK(std::is_trivial<etl::poly_span<int>::iterator>::value);
// CHECK(std::is_trivial<etl::poly_span<const Base>::iterator>::value);
// CHECK(std::is_trivial<etl::poly_span<int>::const_iterator>::value);
// CHECK(bool(std::is_base_of<ETL_OR_STD::random_access_iterator_tag, etl::poly_span<int>::iterator::iterator_category>::value));
// CHECK(std::is_trivially_copy_constructible<etl::poly_span<int>>::value);
// CHECK(std::is_trivially_copy_assignable<etl::poly_span<int>>::value);
//}
////*************************************************************************
////TEST(test_poly_span_iterators)
////{
//// std::vector<int> v = { 1, 2, 3 };
//// etl::poly_span<int> s = v;
//// using iterator = etl::poly_span<int>::iterator;
////
//// CHECK_EQUAL(s.end() - s.begin(), s.size());
//// CHECK_EQUAL(s.rend() - s.rbegin(), s.size());
////
//// iterator b = s.begin();
//// CHECK(b + s.size() == s.end());
//// CHECK_EQUAL(b[0], 1);
//// CHECK(b < s.end());
//// CHECK(b != s.end());
//// CHECK(b + 2 > s.end() - 1);
//// etl::poly_span<int>::const_iterator bc = b;
//// CHECK(bc <= s.end());
//// CHECK_EQUAL(s.back(), *s.crbegin());
//// CHECK_EQUAL(s.front(), s.crend()[-1]);
////
//// bc += 1;
//// bc -= 1;
//// CHECK(bc == s.cbegin());
//// CHECK(std::is_sorted(s.cbegin(), s.cend()));
////}
//*************************************************************************
TEST(test_poly_span_randomAccessIteratorUse)
{
int data[] = { 25, 4, 3, -2, 1 };
etl::poly_span<int> s = data;
// std::sort(s.begin(), s.end());
// CHECK(std::is_sorted(std::begin(data), std::end(data)));
}
//*************************************************************************
TEST(test_poly_span_subspan)
{
const Derived data[] = { 1, 2, 3, 4, 5 };
// etl::poly_span<const int> s(data);
// auto s1 = s.subspan(1, 2);
// CHECK_EQUAL(2, s1.size());
// CHECK_EQUAL(s[1], s1[0]);
// CHECK_EQUAL(s[2], s1[1]);
// auto s2 = s.subspan(2);
// CHECK_EQUAL(3, s2.size());
// CHECK_EQUAL(s[2], s2[0]);
// CHECK_EQUAL(s[4], s2[2]);
// auto s3 = s.subspan(0, 10);
// CHECK_EQUAL(s.size(), s3.size());
// CHECK_THROW(s.subspan(6, 1), etl::poly_span_out_of_range);
}
////*************************************************************************
//TEST(test_poly_span_first)
//{
// const int data[] = { 1, 2, 3, 4, 5 };
// etl::poly_span<const int> s(data);
//
// CHECK_THROW(s.first(6), etl::poly_span_out_of_range);
// CHECK_EQUAL(s.first(5).size(), 5);
// CHECK(s.first(0).empty());
//
// auto s1 = s.first(3);
// CHECK_EQUAL(3, s1.size());
// CHECK_EQUAL(1, s1[0]);
// CHECK_EQUAL(3, s1[2]);
//}
////*************************************************************************
//TEST(test_poly_span_last)
//{
// const int data[] = { 1, 2, 3, 4, 5 };
// etl::poly_span<const int> s(data);
//
// CHECK_THROW(s.last(6), etl::poly_span_out_of_range);
// CHECK_EQUAL(s.last(5).size(), 5);
//
// auto s2 = s.last(2);
// CHECK_EQUAL(2, s2.size());
// CHECK_EQUAL(4, s2[0]);
// CHECK_EQUAL(5, s2[1]);
//}
////*************************************************************************
//TEST(test_poly_span_equal_view)
//{
// std::vector<double> v = { 1.0, 2.0, 3.0 };
// etl::poly_span<double> s1 = v;
// etl::poly_span<const double> cs2 = v;
// CHECK(!etl::poly_span<const double>{}.equal_view(s1));
// CHECK(s1.equal_view(cs2));
// CHECK(s1.last(2).equal_view(cs2.subspan(1)));
//}
////*************************************************************************
//TEST(test_poly_span_at)
//{
// const int data[] = { 1, 2, 3 };
// etl::poly_span<const int> s(data);
//
// CHECK_EQUAL(s.at(0), 1);
// CHECK_EQUAL(s.at(2), 3);
// CHECK_THROW(s.at(3), etl::poly_span_out_of_range);
// CHECK_THROW(s.at(-1), etl::poly_span_out_of_range);
//}
}
}

View File

@ -5313,7 +5313,34 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - Appveyor|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug64|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\sanity-check\poly_span.h.t.cpp" />
<ClCompile Include="..\sanity-check\poly_span.h.t.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Small Strings|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No Tests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - Appveyor|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - No STL - Appveyor|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Force Constexpr Algorithms|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM C++20|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - No Unit Tests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Built-ins|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Force Built-ins|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM - No STL - Built-ins|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug64|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - String Truncation Is Error|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - No STL - Force No Advanced|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Force cpp03|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Intel - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Intel|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No Checks|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Force C++03|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\sanity-check\pseudo_moving_average.h.t.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Built-ins|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Force Built-ins|Win32'">true</ExcludedFromBuild>
@ -10975,7 +11002,7 @@
<ClCompile Include="..\test_crc8_maxim.cpp" />
<ClCompile Include="..\test_crc8_rohc.cpp" />
<ClCompile Include="..\test_crc8_wcdma.cpp" />
<ClCompile Include="..\test_poly_span.cpp" />
<ClCompile Include="..\test_poly_span_dynamic_extent.cpp" />
<ClCompile Include="..\test_pseudo_moving_average.cpp" />
<ClCompile Include="..\test_delegate.cpp" />
<ClCompile Include="..\test_delegate_cpp03.cpp" />

View File

@ -3266,7 +3266,7 @@
<ClCompile Include="..\sanity-check\poly_span.h.t.cpp">
<Filter>Tests\Sanity Checks\Source</Filter>
</ClCompile>
<ClCompile Include="..\test_poly_span.cpp">
<ClCompile Include="..\test_poly_span_dynamic_extent.cpp">
<Filter>Tests\Containers</Filter>
</ClCompile>
</ItemGroup>