Change GetValues() to take in const positions. (#6987)
* Change GetValues() to take in const positions. To support this, span needed some template deductions to correctly convert from non-const containers to const ones. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Removed the most problematic template deduction rules. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Remove duplicate validate_iterator methods. iterator type is a pointer, not a value, so "const iterator" and "const const_iterator" produce the same function signature. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com> * Fixed the span types. Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
This commit is contained in:
@@ -33,23 +33,24 @@ namespace AZStd
|
||||
*
|
||||
* Since the span does not copy and store any data, it is only valid as long as the data used to create it is valid.
|
||||
*/
|
||||
template <class Element>
|
||||
template <class T>
|
||||
class span final
|
||||
{
|
||||
public:
|
||||
using value_type = Element;
|
||||
using element_type = T;
|
||||
using value_type = AZStd::remove_cv_t<T>;
|
||||
|
||||
using pointer = value_type*;
|
||||
using const_pointer = const value_type*;
|
||||
using pointer = T*;
|
||||
using const_pointer = const T*;
|
||||
|
||||
using reference = value_type&;
|
||||
using const_reference = const value_type&;
|
||||
using reference = T&;
|
||||
using const_reference = const T&;
|
||||
|
||||
using size_type = AZStd::size_t;
|
||||
using difference_type = AZStd::ptrdiff_t;
|
||||
|
||||
using iterator = value_type*;
|
||||
using const_iterator = const value_type*;
|
||||
using iterator = T*;
|
||||
using const_iterator = const T*;
|
||||
using reverse_iterator = AZStd::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = AZStd::reverse_iterator<const_iterator>;
|
||||
|
||||
@@ -65,21 +66,11 @@ namespace AZStd
|
||||
// create a span to just the first element instead of an entire array.
|
||||
constexpr span(const_pointer s) = delete;
|
||||
|
||||
template<AZStd::size_t N>
|
||||
constexpr span(AZStd::array<value_type, N>& data);
|
||||
template<typename Container>
|
||||
constexpr span(Container& data);
|
||||
|
||||
constexpr span(AZStd::vector<value_type>& data);
|
||||
|
||||
template<AZStd::size_t N>
|
||||
constexpr span(AZStd::fixed_vector<value_type, N>& data);
|
||||
|
||||
template<AZStd::size_t N>
|
||||
constexpr span(const AZStd::array<value_type, N>& data);
|
||||
|
||||
constexpr span(const AZStd::vector<value_type>& data);
|
||||
|
||||
template<AZStd::size_t N>
|
||||
constexpr span(const AZStd::fixed_vector<value_type, N>& data);
|
||||
template<typename Container>
|
||||
constexpr span(const Container& data);
|
||||
|
||||
constexpr span(const span&) = default;
|
||||
|
||||
@@ -132,6 +123,7 @@ namespace AZStd
|
||||
pointer m_begin;
|
||||
pointer m_end;
|
||||
};
|
||||
|
||||
} // namespace AZStd
|
||||
|
||||
#include <AzCore/std/containers/span.inl>
|
||||
|
||||
@@ -29,42 +29,16 @@ namespace AZStd
|
||||
, m_end(last)
|
||||
{ }
|
||||
|
||||
template <class Element>
|
||||
template<AZStd::size_t N>
|
||||
inline constexpr span<Element>::span(AZStd::array<Element, N>& data)
|
||||
template<class Element>
|
||||
template<typename Container>
|
||||
inline constexpr span<Element>::span(Container& data)
|
||||
: m_begin(data.data())
|
||||
, m_end(m_begin + data.size())
|
||||
{ }
|
||||
|
||||
template <class Element>
|
||||
inline constexpr span<Element>::span(AZStd::vector<Element>& data)
|
||||
: m_begin(data.data())
|
||||
, m_end(m_begin + data.size())
|
||||
{ }
|
||||
|
||||
template <class Element>
|
||||
template<AZStd::size_t N>
|
||||
inline constexpr span<Element>::span(AZStd::fixed_vector<Element, N>& data)
|
||||
: m_begin(data.data())
|
||||
, m_end(m_begin + data.size())
|
||||
{ }
|
||||
|
||||
template <class Element>
|
||||
template<AZStd::size_t N>
|
||||
inline constexpr span<Element>::span(const AZStd::array<Element, N>& data)
|
||||
: m_begin(data.data())
|
||||
, m_end(m_begin + data.size())
|
||||
{ }
|
||||
|
||||
template <class Element>
|
||||
inline constexpr span<Element>::span(const AZStd::vector<Element>& data)
|
||||
: m_begin(data.data())
|
||||
, m_end(m_begin + data.size())
|
||||
{ }
|
||||
|
||||
template <class Element>
|
||||
template<AZStd::size_t N>
|
||||
inline constexpr span<Element>::span(const AZStd::fixed_vector<Element, N>& data)
|
||||
template<class Element>
|
||||
template<typename Container>
|
||||
inline constexpr span<Element>::span(const Container& data)
|
||||
: m_begin(data.data())
|
||||
, m_end(m_begin + data.size())
|
||||
{ }
|
||||
|
||||
@@ -954,25 +954,6 @@ namespace AZStd
|
||||
return true;
|
||||
}
|
||||
/// Validates an iter iterator. Returns a combination of \ref iterator_status_flag.
|
||||
AZ_FORCE_INLINE int validate_iterator(const iterator& iter) const
|
||||
{
|
||||
#ifdef AZSTD_HAS_CHECKED_ITERATORS
|
||||
AZ_Assert(iter.m_container == this, "Iterator doesn't belong to this container");
|
||||
pointer iterPtr = iter.m_iter;
|
||||
#else
|
||||
pointer iterPtr = iter;
|
||||
#endif
|
||||
if (iterPtr < m_start || iterPtr > m_last)
|
||||
{
|
||||
return isf_none;
|
||||
}
|
||||
else if (iterPtr == m_last)
|
||||
{
|
||||
return isf_valid;
|
||||
}
|
||||
|
||||
return isf_valid | isf_can_dereference;
|
||||
}
|
||||
AZ_FORCE_INLINE int validate_iterator(const const_iterator& iter) const
|
||||
{
|
||||
#ifdef AZSTD_HAS_CHECKED_ITERATORS
|
||||
@@ -992,7 +973,6 @@ namespace AZStd
|
||||
|
||||
return isf_valid | isf_can_dereference;
|
||||
}
|
||||
AZ_FORCE_INLINE int validate_iterator(const reverse_iterator& iter) const { return validate_iterator(iter.base()); }
|
||||
AZ_FORCE_INLINE int validate_iterator(const const_reverse_iterator& iter) const { return validate_iterator(iter.base()); }
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user