Adding partial implementation of C++20 concepts and range functions for AZStd::span (#7102)
* Adding partial implementation of C++20 concepts and range functions for AZStd::span The new concepts to discovered existing issues with the PathIterator and deque::iterator classes PathIterator wasn't properly an input_iterator and therefore the Path classes weren't a range due to an incorrect const_iterator alias The deque::iterator classes was missing the operator+ friend function that accepted a (ptrdiff_t, deque::iterator) to fulfill the random_access_iterator concepts The AZStd implementations of (uninitialized_)copy(_n), (uninitialized_)move(_n) and (uninitialized_)file(_n) have been optimized to use memcpy and memset based on fulfilling the contiguous_iterator concept Fixed invalid AZStd::vector inserts in FrameGraphExecuter.cpp and SliceditorEntityOwnershipService.cpp The code was trying to copy the underlying addresses for vector<unique_ptr> to a vector<raw pointer> using insert, which it was doing by using memcpy. relates to #6749 Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed the `fixed_vector` emplace function to not move initialized elements using uninitialized_move. This was causing initialized elements of the fixed_vector to be overwritten with the element at the emplace position. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed clang warnings about variables that are set, but never read Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the `az_has_builtin_is_constant_evaluated` define to not have "()" as is not a macro. This helps prevent users from using `az_has_builtin_is_constant_evaluated` define in a situation where they want to know if the function is being evaluated in a compile time context. In that case they need to use the `az_builtin_is_constant_evaluated()` macro (which of course looks quite similiar) but does not have the word "has" in it.. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Updated the AZStd span class to be C++20 compliant. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Changed phrase "DoesNotCompiles" to be more grammatically correct. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Added more unit test for AZStd span Fixed an the the return type of the subspan template overload to account for the source span having a dynamic extent. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed unused variable from span unit test. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
a3fbcae81f
commit
f3e9e41f4f
@@ -15,9 +15,9 @@ namespace AZ::IO
|
||||
// Class template instantations
|
||||
template class BasicPath<AZStd::string>;
|
||||
template class BasicPath<FixedMaxPathString>;
|
||||
template class PathIterator<PathView>;
|
||||
template class PathIterator<Path>;
|
||||
template class PathIterator<FixedMaxPath>;
|
||||
template class PathIterator<const PathView>;
|
||||
template class PathIterator<const Path>;
|
||||
template class PathIterator<const FixedMaxPath>;
|
||||
|
||||
// Swap function instantiations
|
||||
template void swap<AZStd::string>(Path& lhs, Path& rhs) noexcept;
|
||||
@@ -38,16 +38,16 @@ namespace AZ::IO
|
||||
const typename BasicPath<FixedMaxPathString>::value_type* rhs);
|
||||
|
||||
// Iterator compare instantiations
|
||||
template bool operator==<PathView>(const PathIterator<PathView>& lhs,
|
||||
const PathIterator<PathView>& rhs);
|
||||
template bool operator==<Path>(const PathIterator<Path>& lhs,
|
||||
const PathIterator<Path>& rhs);
|
||||
template bool operator==<FixedMaxPath>(const PathIterator<FixedMaxPath>& lhs,
|
||||
const PathIterator<FixedMaxPath>& rhs);
|
||||
template bool operator!=<PathView>(const PathIterator<PathView>& lhs,
|
||||
const PathIterator<PathView>& rhs);
|
||||
template bool operator!=<Path>(const PathIterator<Path>& lhs,
|
||||
const PathIterator<Path>& rhs);
|
||||
template bool operator!=<FixedMaxPath>(const PathIterator<FixedMaxPath>& lhs,
|
||||
const PathIterator<FixedMaxPath>& rhs);
|
||||
template bool operator==<const PathView>(const PathIterator<const PathView>& lhs,
|
||||
const PathIterator<const PathView>& rhs);
|
||||
template bool operator==<const Path>(const PathIterator<const Path>& lhs,
|
||||
const PathIterator<const Path>& rhs);
|
||||
template bool operator==<const FixedMaxPath>(const PathIterator<const FixedMaxPath>& lhs,
|
||||
const PathIterator<const FixedMaxPath>& rhs);
|
||||
template bool operator!=<const PathView>(const PathIterator<const PathView>& lhs,
|
||||
const PathIterator<const PathView>& rhs);
|
||||
template bool operator!=<const Path>(const PathIterator<const Path>& lhs,
|
||||
const PathIterator<const Path>& rhs);
|
||||
template bool operator!=<const FixedMaxPath>(const PathIterator<const FixedMaxPath>& lhs,
|
||||
const PathIterator<const FixedMaxPath>& rhs);
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ namespace AZ::IO
|
||||
public:
|
||||
using string_view_type = AZStd::string_view;
|
||||
using value_type = char;
|
||||
using const_iterator = const PathIterator<PathView>;
|
||||
using const_iterator = PathIterator<const PathView>;
|
||||
using iterator = const_iterator;
|
||||
friend PathIterator<PathView>;
|
||||
friend const_iterator;
|
||||
|
||||
// constructors and destructor
|
||||
constexpr PathView() = default;
|
||||
@@ -319,9 +319,9 @@ namespace AZ::IO
|
||||
using value_type = typename StringType::value_type;
|
||||
using traits_type = typename StringType::traits_type;
|
||||
using string_view_type = AZStd::string_view;
|
||||
using const_iterator = const PathIterator<BasicPath>;
|
||||
using const_iterator = PathIterator<const BasicPath>;
|
||||
using iterator = const_iterator;
|
||||
friend PathIterator<BasicPath>;
|
||||
friend const_iterator;
|
||||
|
||||
// constructors and destructor
|
||||
constexpr BasicPath() = default;
|
||||
@@ -692,7 +692,7 @@ namespace AZ::IO
|
||||
friend PathType;
|
||||
|
||||
using iterator_category = AZStd::bidirectional_iterator_tag;
|
||||
using value_type = PathType;
|
||||
using value_type = AZStd::remove_cv_t<PathType>;
|
||||
using difference_type = ptrdiff_t;
|
||||
using pointer = const value_type*;
|
||||
using reference = const value_type&;
|
||||
@@ -703,8 +703,9 @@ namespace AZ::IO
|
||||
|
||||
constexpr PathIterator() = default;
|
||||
constexpr PathIterator(const PathIterator&) = default;
|
||||
|
||||
constexpr PathIterator(PathIterator&&) noexcept = default;
|
||||
constexpr PathIterator& operator=(const PathIterator&) = default;
|
||||
constexpr PathIterator& operator=(PathIterator&&) noexcept = default;
|
||||
|
||||
constexpr reference operator*() const;
|
||||
|
||||
@@ -733,10 +734,10 @@ namespace AZ::IO
|
||||
ParserState m_state{ Singular };
|
||||
};
|
||||
|
||||
template <typename PathType1>
|
||||
constexpr bool operator==(const PathIterator<PathType1>& lhs, const PathIterator<PathType1>& rhs);
|
||||
template <typename PathType1>
|
||||
constexpr bool operator!=(const PathIterator<PathType1>& lhs, const PathIterator<PathType1>& rhs);
|
||||
template <typename PathType>
|
||||
constexpr bool operator==(const PathIterator<PathType>& lhs, const PathIterator<PathType>& rhs);
|
||||
template <typename PathType>
|
||||
constexpr bool operator!=(const PathIterator<PathType>& lhs, const PathIterator<PathType>& rhs);
|
||||
}
|
||||
|
||||
#include <AzCore/IO/Path/Path.inl>
|
||||
|
||||
@@ -399,7 +399,7 @@ namespace AZ::IO
|
||||
constexpr auto PathView::begin() const -> const_iterator
|
||||
{
|
||||
auto pathParser = parser::PathParser::CreateBegin(m_path, m_preferred_separator);
|
||||
PathIterator<PathView> it;
|
||||
const_iterator it;
|
||||
it.m_path_ref = this;
|
||||
it.m_state = static_cast<typename const_iterator::ParserState>(pathParser.m_parser_state);
|
||||
it.m_path_entry_view = pathParser.m_path_raw_entry;
|
||||
@@ -409,7 +409,7 @@ namespace AZ::IO
|
||||
|
||||
constexpr auto PathView::end() const -> const_iterator
|
||||
{
|
||||
PathIterator<PathView> it;
|
||||
const_iterator it;
|
||||
it.m_state = const_iterator::AtEnd;
|
||||
it.m_path_ref = this;
|
||||
return it;
|
||||
@@ -1262,7 +1262,7 @@ namespace AZ::IO
|
||||
constexpr auto BasicPath<StringType>::begin() const -> const_iterator
|
||||
{
|
||||
auto pathParser = parser::PathParser::CreateBegin(m_path, m_preferred_separator);
|
||||
PathIterator<BasicPath> it;
|
||||
const_iterator it;
|
||||
it.m_path_ref = this;
|
||||
it.m_state = static_cast<typename const_iterator::ParserState>(pathParser.m_parser_state);
|
||||
it.m_path_entry_view = pathParser.m_path_raw_entry;
|
||||
@@ -1273,7 +1273,7 @@ namespace AZ::IO
|
||||
template <typename StringType>
|
||||
constexpr auto BasicPath<StringType>::end() const -> const_iterator
|
||||
{
|
||||
PathIterator<BasicPath> it;
|
||||
const_iterator it;
|
||||
it.m_state = const_iterator::AtEnd;
|
||||
it.m_path_ref = this;
|
||||
return it;
|
||||
@@ -1529,16 +1529,16 @@ namespace AZ::IO
|
||||
const typename BasicPath<FixedMaxPathString>::value_type* rhs);
|
||||
|
||||
// Iterator compare explicit declarations
|
||||
extern template bool operator==<PathView>(const PathIterator<PathView>& lhs,
|
||||
const PathIterator<PathView>& rhs);
|
||||
extern template bool operator==<Path>(const PathIterator<Path>& lhs,
|
||||
const PathIterator<Path>& rhs);
|
||||
extern template bool operator==<FixedMaxPath>(const PathIterator<FixedMaxPath>& lhs,
|
||||
const PathIterator<FixedMaxPath>& rhs);
|
||||
extern template bool operator!=<PathView>(const PathIterator<PathView>& lhs,
|
||||
const PathIterator<PathView>& rhs);
|
||||
extern template bool operator!=<Path>(const PathIterator<Path>& lhs,
|
||||
const PathIterator<Path>& rhs);
|
||||
extern template bool operator!=<FixedMaxPath>(const PathIterator<FixedMaxPath>& lhs,
|
||||
const PathIterator<FixedMaxPath>& rhs);
|
||||
extern template bool operator==<const PathView>(const PathIterator<const PathView>& lhs,
|
||||
const PathIterator<const PathView>& rhs);
|
||||
extern template bool operator==<const Path>(const PathIterator<const Path>& lhs,
|
||||
const PathIterator<const Path>& rhs);
|
||||
extern template bool operator==<const FixedMaxPath>(const PathIterator<const FixedMaxPath>& lhs,
|
||||
const PathIterator<const FixedMaxPath>& rhs);
|
||||
extern template bool operator!=<const PathView>(const PathIterator<const PathView>& lhs,
|
||||
const PathIterator<const PathView>& rhs);
|
||||
extern template bool operator!=<const Path>(const PathIterator<const Path>& lhs,
|
||||
const PathIterator<const Path>& rhs);
|
||||
extern template bool operator!=<const FixedMaxPath>(const PathIterator<const FixedMaxPath>& lhs,
|
||||
const PathIterator<const FixedMaxPath>& rhs);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <AzCore/AzCore_Traits_Platform.h>
|
||||
#include <AzCore/Casting/numeric_cast.h>
|
||||
#include <AzCore/std/concepts/concepts.h>
|
||||
|
||||
namespace AZ::IO::Internal
|
||||
{
|
||||
@@ -17,7 +18,7 @@ namespace AZ::IO::Internal
|
||||
{
|
||||
return elem == '/' || elem == '\\';
|
||||
}
|
||||
template <typename InputIt, typename EndIt, typename = AZStd::enable_if_t<AZStd::Internal::is_input_iterator_v<InputIt>>>
|
||||
template <typename InputIt, typename EndIt, typename = AZStd::enable_if_t<AZStd::input_iterator<InputIt>>>
|
||||
static constexpr bool HasDrivePrefix(InputIt first, EndIt last)
|
||||
{
|
||||
size_t prefixSize = AZStd::distance(first, last);
|
||||
@@ -46,7 +47,7 @@ namespace AZ::IO::Internal
|
||||
//! Windows root names can have include drive letter within them
|
||||
template <typename InputIt>
|
||||
constexpr auto ConsumeRootName(InputIt entryBeginIter, InputIt entryEndIter, const char preferredSeparator)
|
||||
-> AZStd::enable_if_t<AZStd::Internal::is_forward_iterator_v<InputIt>, InputIt>
|
||||
-> AZStd::enable_if_t<AZStd::forward_iterator<InputIt>, InputIt>
|
||||
{
|
||||
if (preferredSeparator == PosixPathSeparator)
|
||||
{
|
||||
@@ -147,7 +148,7 @@ namespace AZ::IO::Internal
|
||||
//! If the preferred separator is '/' just checks if the path starts with a '/
|
||||
//! Otherwise a check for a Windows absolute path occurs
|
||||
//! Windows absolute paths can include a RootName
|
||||
template <typename InputIt, typename EndIt, typename = AZStd::enable_if_t<AZStd::Internal::is_input_iterator_v<InputIt>>>
|
||||
template <typename InputIt, typename EndIt, typename = AZStd::enable_if_t<AZStd::input_iterator<InputIt>>>
|
||||
static constexpr bool IsAbsolute(InputIt first, EndIt last, const char preferredSeparator)
|
||||
{
|
||||
size_t pathSize = AZStd::distance(first, last);
|
||||
@@ -208,11 +209,11 @@ namespace AZ::IO::parser
|
||||
enum ParserState : uint8_t
|
||||
{
|
||||
// Zero is a special sentinel value used by default constructed iterators.
|
||||
PS_BeforeBegin = PathIterator<PathView>::BeforeBegin,
|
||||
PS_InRootName = PathIterator<PathView>::InRootName,
|
||||
PS_InRootDir = PathIterator<PathView>::InRootDir,
|
||||
PS_InFilenames = PathIterator<PathView>::InFilenames,
|
||||
PS_AtEnd = PathIterator<PathView>::AtEnd
|
||||
PS_BeforeBegin = PathView::const_iterator::BeforeBegin,
|
||||
PS_InRootName = PathView::const_iterator::InRootName,
|
||||
PS_InRootDir = PathView::const_iterator::InRootDir,
|
||||
PS_InFilenames = PathView::const_iterator::InFilenames,
|
||||
PS_AtEnd = PathView::const_iterator::AtEnd
|
||||
};
|
||||
|
||||
struct PathParser
|
||||
|
||||
@@ -248,14 +248,14 @@
|
||||
#if defined(__has_builtin)
|
||||
#if __has_builtin(__builtin_is_constant_evaluated)
|
||||
#define az_builtin_is_constant_evaluated() __builtin_is_constant_evaluated()
|
||||
#define az_has_builtin_is_constant_evaluated() true
|
||||
#define az_has_builtin_is_constant_evaluated true
|
||||
#endif
|
||||
#elif AZ_COMPILER_MSVC >= 1928
|
||||
#define az_builtin_is_constant_evaluated() __builtin_is_constant_evaluated()
|
||||
#define az_has_builtin_is_constant_evaluated() true
|
||||
#define az_has_builtin_is_constant_evaluated true
|
||||
#elif AZ_COMPILER_GCC
|
||||
#define az_builtin_is_constant_evaluated() __builtin_is_constant_evaluated()
|
||||
#define az_has_builtin_is_constant_evaluated() true
|
||||
#define az_has_builtin_is_constant_evaluated true
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -271,7 +271,7 @@
|
||||
}
|
||||
}
|
||||
#define az_builtin_is_constant_evaluated() AZ::Internal::builtin_is_constant_evaluated()
|
||||
#define az_has_builtin_is_constant_evaluated() false
|
||||
#define az_has_builtin_is_constant_evaluated false
|
||||
#endif
|
||||
|
||||
// define builtin functions used by char_traits class for efficient compile time and runtime
|
||||
|
||||
@@ -19,6 +19,7 @@ set(FILES
|
||||
any.h
|
||||
base.h
|
||||
config.h
|
||||
concepts/concepts.h
|
||||
createdestroy.h
|
||||
docs.h
|
||||
exceptions.h
|
||||
@@ -27,11 +28,14 @@ set(FILES
|
||||
hash.cpp
|
||||
hash.h
|
||||
hash_table.h
|
||||
iterator/iterator_primitives.h
|
||||
iterator.h
|
||||
limits.h
|
||||
numeric.h
|
||||
math.h
|
||||
optional.h
|
||||
ranges/iter_move.h
|
||||
ranges/ranges.h
|
||||
ratio.h
|
||||
reference_wrapper.h
|
||||
sort.h
|
||||
@@ -151,6 +155,7 @@ set(FILES
|
||||
typetraits/alignment_of.h
|
||||
typetraits/config.h
|
||||
typetraits/common_type.h
|
||||
typetraits/common_reference.h
|
||||
typetraits/conjunction.h
|
||||
typetraits/disjunction.h
|
||||
typetraits/extent.h
|
||||
@@ -217,4 +222,6 @@ set(FILES
|
||||
typetraits/void_t.h
|
||||
typetraits/internal/type_sequence_traits.h
|
||||
typetraits/internal/is_template_copy_constructible.h
|
||||
utility/declval.h
|
||||
utility/move.h
|
||||
)
|
||||
|
||||
@@ -30,4 +30,6 @@ namespace AZStd
|
||||
using std::nullptr_t;
|
||||
|
||||
using sys_time_t = AZ::s64;
|
||||
|
||||
using std::byte;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,840 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/function/invoke.h>
|
||||
#include <AzCore/std/iterator/iterator_primitives.h>
|
||||
#include <AzCore/std/ranges/iter_move.h>
|
||||
|
||||
#include <AzCore/std/typetraits/add_pointer.h>
|
||||
#include <AzCore/std/typetraits/common_reference.h>
|
||||
#include <AzCore/std/typetraits/extent.h>
|
||||
#include <AzCore/std/typetraits/is_array.h>
|
||||
#include <AzCore/std/typetraits/is_assignable.h>
|
||||
#include <AzCore/std/typetraits/is_class.h>
|
||||
#include <AzCore/std/typetraits/is_constructible.h>
|
||||
#include <AzCore/std/typetraits/is_destructible.h>
|
||||
#include <AzCore/std/typetraits/is_enum.h>
|
||||
#include <AzCore/std/typetraits/is_floating_point.h>
|
||||
#include <AzCore/std/typetraits/is_function.h>
|
||||
#include <AzCore/std/typetraits/is_integral.h>
|
||||
#include <AzCore/std/typetraits/is_object.h>
|
||||
#include <AzCore/std/typetraits/is_same.h>
|
||||
#include <AzCore/std/typetraits/is_signed.h>
|
||||
#include <AzCore/std/typetraits/is_void.h>
|
||||
#include <AzCore/std/typetraits/remove_cvref.h>
|
||||
#include <AzCore/std/typetraits/void_t.h>
|
||||
#include <AzCore/std/utility/declval.h>
|
||||
#include <AzCore/std/utility/move.h>
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// alias std::pointer_traits into the AZStd::namespace
|
||||
using std::pointer_traits;
|
||||
|
||||
// Alias re-declarations from iterator.h
|
||||
/// Identifying tag for input iterators.
|
||||
using input_iterator_tag = std::input_iterator_tag;
|
||||
/// Identifying tag for output iterators.
|
||||
using output_iterator_tag = std::output_iterator_tag;
|
||||
/// Identifying tag for forward iterators.
|
||||
using forward_iterator_tag = std::forward_iterator_tag;
|
||||
/// Identifying tag for bidirectional iterators.
|
||||
using bidirectional_iterator_tag = std::bidirectional_iterator_tag;
|
||||
/// Identifying tag for random-access iterators.
|
||||
using random_access_iterator_tag = std::random_access_iterator_tag;
|
||||
/// Identifying tag for contagious iterators
|
||||
struct contiguous_iterator_tag;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template <typename T, typename = void>
|
||||
constexpr bool pointer_traits_has_to_address_v = false;
|
||||
|
||||
template <typename T>
|
||||
constexpr bool pointer_traits_has_to_address_v<T, enable_if_t<
|
||||
is_void_v<void_t<decltype(pointer_traits<T>::to_address(declval<const T&>()))>>> > = true;
|
||||
|
||||
|
||||
// pointer_traits isn't SFINAE friendly https://cplusplus.github.io/LWG/lwg-active.html#3545
|
||||
// So working around that by checking if type T has an element_type alias
|
||||
template <typename T, typename = void>
|
||||
constexpr bool pointer_traits_valid_and_has_to_address_v = false;
|
||||
template <typename T>
|
||||
constexpr bool pointer_traits_valid_and_has_to_address_v<T, enable_if_t<has_element_type_v<T>> >
|
||||
= pointer_traits_has_to_address_v<T>;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
//! Implements the C++20 to_address function
|
||||
//! This obtains the address represented by ptr without forming a reference
|
||||
//! to the pointee type
|
||||
template <typename T>
|
||||
constexpr T* to_address(T* ptr) noexcept
|
||||
{
|
||||
static_assert(!AZStd::is_function_v<T>, "Invoking to address on a function pointer is not allowed");
|
||||
return ptr;
|
||||
}
|
||||
//! Fancy pointer overload which delegates to using a specialization of pointer_traits<T>::to_address
|
||||
//! if that is a well-formed expression, otherwise it returns ptr->operator->()
|
||||
//! For example invoking `to_address(AZStd::reverse_iterator<const char*>(char_ptr))`
|
||||
//! Returns an element of type const char*
|
||||
template <typename T>
|
||||
constexpr auto to_address(const T& ptr) noexcept
|
||||
{
|
||||
if constexpr (AZStd::Internal::pointer_traits_valid_and_has_to_address_v<T>)
|
||||
{
|
||||
return pointer_traits<T>::to_address(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return to_address(ptr.operator->());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
// Variadic template which maps types to true For SFINAE
|
||||
template <class... Args>
|
||||
constexpr bool sfinae_trigger_v = true;
|
||||
|
||||
template <class It, class = void>
|
||||
constexpr bool is_class_or_enum = false;
|
||||
template <class It>
|
||||
constexpr bool is_class_or_enum<It, enable_if_t<
|
||||
(is_class_v<remove_cvref_t<It>> || is_enum_v<remove_cvref_t<It>>)>> = true;
|
||||
|
||||
template<class LHS, class RHS, class = void>
|
||||
constexpr bool assignable_from_impl = false;
|
||||
template<class LHS, class RHS>
|
||||
constexpr bool assignable_from_impl<LHS, RHS, enable_if_t<is_lvalue_reference_v<LHS>
|
||||
&& common_reference_with<const remove_reference_t<LHS>&, const remove_reference_t<RHS>&>
|
||||
&& same_as<decltype(declval<LHS>() = declval<RHS>()), LHS> >> = true;
|
||||
|
||||
|
||||
template<class T, class U, class = void>
|
||||
constexpr bool common_with_impl = false;
|
||||
template<class T, class U>
|
||||
constexpr bool common_with_impl<T, U, enable_if_t<
|
||||
same_as<common_type_t<T, U>, common_type_t<U, T>>
|
||||
&& sfinae_trigger_v<decltype(static_cast<common_type_t<T, U>>(declval<T>()))>
|
||||
&& sfinae_trigger_v<decltype(static_cast<common_type_t<T, U>>(declval<U>()))>
|
||||
&& common_reference_with<add_lvalue_reference_t<const T>, add_lvalue_reference_t<const U>>
|
||||
&& common_reference_with<add_lvalue_reference_t<common_type_t<T, U>>, common_reference_t<add_lvalue_reference_t<const T>, add_lvalue_reference_t<const U>>>
|
||||
>> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<class T, class U>
|
||||
/*concept*/ constexpr bool common_with = Internal::common_with_impl<T, U>;
|
||||
|
||||
template<class LHS, class RHS>
|
||||
/*concept*/ constexpr bool assignable_from = Internal::assignable_from_impl<LHS, RHS>;
|
||||
|
||||
template<class T, class... Args>
|
||||
/*concept*/ constexpr bool constructible_from = destructible<T> && is_constructible_v<T, Args...>;
|
||||
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool move_constructible = constructible_from<T, T> && convertible_to<T, T>;
|
||||
|
||||
template<class Derived, class Base>
|
||||
/*concept*/ constexpr bool derived_from = is_base_of_v<Base, Derived> && is_convertible_v<const volatile Derived*, const volatile Base*>;
|
||||
}
|
||||
|
||||
namespace AZStd::ranges::Internal
|
||||
{
|
||||
template <class T, class U, class = void>
|
||||
constexpr bool is_class_or_enum_with_swap_adl = false;
|
||||
template <class T, class U>
|
||||
constexpr bool is_class_or_enum_with_swap_adl<T, U, enable_if_t<
|
||||
(is_class_v<remove_cvref_t<T>> || is_enum_v<remove_cvref_t<T>>
|
||||
|| is_class_v<remove_cvref_t<U>> || is_enum_v<remove_cvref_t<T>>)
|
||||
&& is_void_v<void_t<decltype(swap(declval<T&>(), declval<U&>()))>>
|
||||
>> = true;
|
||||
|
||||
template <class T>
|
||||
void swap(T&, T&) = delete;
|
||||
|
||||
struct swap_fn
|
||||
{
|
||||
template <class T, class U>
|
||||
constexpr auto operator()(T&& t, U&& u) const noexcept(noexcept(swap(AZStd::forward<T>(t), AZStd::forward<U>(u))))
|
||||
->enable_if_t<is_class_or_enum_with_swap_adl<T, U>>
|
||||
{
|
||||
swap(AZStd::forward<T>(t), AZStd::forward<U>(u));
|
||||
}
|
||||
|
||||
// ranges::swap customization point https://eel.is/c++draft/concepts#concept.swappable-2.2
|
||||
// Implemented in ranges.h as to prevent circular dependency.
|
||||
// ranges::swap_ranges depends on the range concepts that can't be defined here
|
||||
template <class T, class U>
|
||||
constexpr auto operator()(T&& t, U&& u) const noexcept(noexcept((*this)(*t, *u)))
|
||||
->enable_if_t<!is_class_or_enum_with_swap_adl<T, U>
|
||||
&& is_array_v<T> && is_array_v<U> && (extent_v<T> == extent_v<U>)
|
||||
>;
|
||||
|
||||
template <class T>
|
||||
constexpr auto operator()(T& t1, T& t2) const noexcept(noexcept(is_nothrow_move_constructible_v<T>&& is_nothrow_move_assignable_v<T>))
|
||||
->enable_if_t<move_constructible<T>&& assignable_from<T&, T>>
|
||||
{
|
||||
auto temp(AZStd::move(t1));
|
||||
t1 = AZStd::move(t2);
|
||||
t2 = AZStd::move(temp);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace AZStd::ranges
|
||||
{
|
||||
inline namespace customization_point_object
|
||||
{
|
||||
inline constexpr auto swap = Internal::swap_fn{};
|
||||
}
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template <class T, class = void>
|
||||
constexpr bool swappable_impl = false;
|
||||
template <class T>
|
||||
constexpr bool swappable_impl<T, void_t<decltype(AZStd::ranges::swap(declval<T&>(), declval<T&>()))>> = true;
|
||||
|
||||
template <class T, class U, class = void>
|
||||
constexpr bool swappable_with_impl = false;
|
||||
template <class T, class U>
|
||||
constexpr bool swappable_with_impl<T, U, enable_if_t<common_reference_with<T, U>
|
||||
&& sfinae_trigger_v<
|
||||
decltype(AZStd::ranges::swap(declval<T&>(), declval<T&>())),
|
||||
decltype(AZStd::ranges::swap(declval<U&>(), declval<U&>())),
|
||||
decltype(AZStd::ranges::swap(declval<T&>(), declval<U&>())),
|
||||
decltype(AZStd::ranges::swap(declval<U&>(), declval<T&>()))>>> = true;
|
||||
}
|
||||
namespace AZStd
|
||||
{
|
||||
template <class T>
|
||||
/*concept*/ constexpr bool signed_integral = integral<T> && is_signed_v<T>;
|
||||
template <class T>
|
||||
/*concept*/ constexpr bool unsigned_integral = integral<T> && !signed_integral<T>;
|
||||
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool swappable = Internal::swappable_impl<T>;
|
||||
|
||||
template<class T, class U>
|
||||
/*concept*/ constexpr bool swappable_with = Internal::swappable_with_impl<T, U>;
|
||||
}
|
||||
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
// boolean-testable concept (exposition only in the C++standard)
|
||||
template<class T>
|
||||
constexpr bool boolean_testable_impl = convertible_to<T, bool>;
|
||||
|
||||
template<class T, class = void>
|
||||
constexpr bool boolean_testable = false;
|
||||
template<class T>
|
||||
constexpr bool boolean_testable<T, enable_if_t<boolean_testable_impl<T> && boolean_testable_impl<decltype(!declval<T>())>>> = true;
|
||||
|
||||
// weakly comparable ==, !=
|
||||
template<class T, class U, class = void>
|
||||
constexpr bool weakly_equality_comparable_with = false;
|
||||
template<class T, class U>
|
||||
constexpr bool weakly_equality_comparable_with<T, U, enable_if_t<
|
||||
boolean_testable<decltype(declval<AZStd::remove_reference_t<T>&>() == declval<AZStd::remove_reference_t<U>&>())>
|
||||
&& boolean_testable<decltype(declval<AZStd::remove_reference_t<T>&>() != declval<AZStd::remove_reference_t<U>&>())>
|
||||
&& boolean_testable<decltype(declval<AZStd::remove_reference_t<U>&>() == declval<AZStd::remove_reference_t<T>&>())>
|
||||
&& boolean_testable<decltype(declval<AZStd::remove_reference_t<U>&>() != declval<AZStd::remove_reference_t<T>&>())>
|
||||
>> = true;
|
||||
|
||||
// partially ordered <, >, <=, >=
|
||||
template<class, class U, class = void>
|
||||
constexpr bool partially_ordered_with_impl = false;
|
||||
template<class T, class U>
|
||||
constexpr bool partially_ordered_with_impl<T, U, enable_if_t<
|
||||
boolean_testable<decltype(declval<const remove_reference_t<T>&>() < declval<const remove_reference_t<U>&>())>
|
||||
&& boolean_testable<decltype(declval<const remove_reference_t<T>&>() > declval<const remove_reference_t<U>&>())>
|
||||
&& boolean_testable<decltype(declval<const remove_reference_t<T>&>() <= declval<const remove_reference_t<U>&>())>
|
||||
&& boolean_testable<decltype(declval<const remove_reference_t<T>&>() >= declval<const remove_reference_t<U>&>())>
|
||||
&& boolean_testable<decltype(declval<const remove_reference_t<U>&>() < declval<const remove_reference_t<T>&>())>
|
||||
&& boolean_testable<decltype(declval<const remove_reference_t<U>&>() > declval<const remove_reference_t<T>&>())>
|
||||
&& boolean_testable<decltype(declval<const remove_reference_t<U>&>() <= declval<const remove_reference_t<T>&>())>
|
||||
&& boolean_testable<decltype(declval<const remove_reference_t<U>&>() >= declval<const remove_reference_t<T>&>())>
|
||||
>> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool equality_comparable = Internal::weakly_equality_comparable_with<T, T>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
// equally_comparable + partially ordered
|
||||
template<class, class U, class = void>
|
||||
constexpr bool equally_comparable_with_impl = false;
|
||||
template<class T, class U>
|
||||
constexpr bool equally_comparable_with_impl<T, U, enable_if_t<equality_comparable<T>
|
||||
&& equality_comparable<U>
|
||||
&& common_reference_with<const remove_reference_t<T>&, const remove_reference_t<U>&>
|
||||
&& equality_comparable<common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>>
|
||||
&& Internal::weakly_equality_comparable_with<T, U>
|
||||
>> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<class T, class U>
|
||||
/*concept*/ constexpr bool equality_comparable_with = Internal::equally_comparable_with_impl<T, U>;
|
||||
|
||||
template<class T, class U>
|
||||
/*concept*/ constexpr bool partially_ordered_with = Internal::partially_ordered_with_impl<T, U>;
|
||||
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool totally_ordered = equality_comparable<T> && partially_ordered_with<T, T>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
// equally_comparable + partially ordered
|
||||
template<class, class U, class = void>
|
||||
constexpr bool totally_ordered_with_impl = false;
|
||||
template<class T, class U>
|
||||
constexpr bool totally_ordered_with_impl<T, U, enable_if_t<totally_ordered<T>&& totally_ordered<U>
|
||||
&& equality_comparable_with<T, U>
|
||||
&& totally_ordered<common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>>
|
||||
&& partially_ordered_with<T, U>
|
||||
>> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<class T, class U>
|
||||
/*concept*/ constexpr bool totally_ordered_with = Internal::totally_ordered_with_impl<T, U>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class T, class = void>
|
||||
inline constexpr bool is_default_initializable = false;
|
||||
template<class T>
|
||||
inline constexpr bool is_default_initializable<T, void_t<decltype(::new T)>> = true;
|
||||
|
||||
template<class T, class = void>
|
||||
constexpr bool default_initializable_impl = false;
|
||||
template<class T>
|
||||
constexpr bool default_initializable_impl < T, enable_if_t < constructible_from<T>
|
||||
&& sfinae_trigger_v<decltype(T{}) > && Internal::is_default_initializable<T> >> = true;
|
||||
|
||||
template <class T, class = void>
|
||||
constexpr bool movable_impl = false;
|
||||
template <class T>
|
||||
constexpr bool movable_impl<T, enable_if_t<is_object_v<T> && move_constructible<T> &&
|
||||
assignable_from<T&, T> && swappable<T>> > = true;
|
||||
|
||||
template <class T, class = void>
|
||||
constexpr bool copy_constructible_impl = false;
|
||||
template <class T>
|
||||
constexpr bool copy_constructible_impl<T, enable_if_t<move_constructible<T> &&
|
||||
constructible_from<T, T&> && convertible_to<T&, T> &&
|
||||
constructible_from<T, const T&> && convertible_to<const T&, T> &&
|
||||
constructible_from<T, const T> && convertible_to<const T, T>> > = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// movable
|
||||
template <class T>
|
||||
/*concept*/ constexpr bool movable = Internal::movable_impl<T>;
|
||||
|
||||
// default_initializable
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool default_initializable = Internal::default_initializable_impl<T>;
|
||||
|
||||
// copy constructible
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool copy_constructible = Internal::copy_constructible_impl<T>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template <class T, class = void>
|
||||
constexpr bool copyable_impl = false;
|
||||
template <class T>
|
||||
constexpr bool copyable_impl<T, enable_if_t<copy_constructible<T> && movable<T> && assignable_from<T&, T&> &&
|
||||
assignable_from<T&, const T&> && assignable_from<T&, const T>> > = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// copyable
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool copyable = Internal::copyable_impl<T>;
|
||||
|
||||
// semiregular
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool semiregular = copyable<T> && default_initializable<T>;
|
||||
|
||||
// regular
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool regular = semiregular<T> && equality_comparable<T>;
|
||||
}
|
||||
|
||||
// Iterator Concepts
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template <class T>
|
||||
constexpr bool is_integer_like = integral<T> && !same_as<T, bool>;
|
||||
|
||||
template <class T>
|
||||
constexpr bool is_signed_integer_like = signed_integral<T>;
|
||||
|
||||
template <class T, class = void>
|
||||
constexpr bool weakly_incrementable_impl = false;
|
||||
template <class T>
|
||||
constexpr bool weakly_incrementable_impl<T, enable_if_t<movable<T>
|
||||
&& is_signed_integer_like<iter_difference_t<T>>
|
||||
&& same_as<decltype(++declval<T&>()), T&>
|
||||
&& sfinae_trigger_v<decltype(declval<T&>()++)> >> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// models weakly_incrementable concept
|
||||
template <class T>
|
||||
/*concept*/ constexpr bool weakly_incrementable = Internal::weakly_incrementable_impl<T>;
|
||||
|
||||
// models input_or_output_iterator concept
|
||||
template <class T>
|
||||
/*concept*/ constexpr bool input_or_output_iterator = !is_void_v<T>
|
||||
&& weakly_incrementable<T>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template <class T, class = void>
|
||||
constexpr bool incrementable_impl = false;
|
||||
template <class T>
|
||||
constexpr bool incrementable_impl<T, enable_if_t<regular<T>
|
||||
&& weakly_incrementable<T>
|
||||
&& same_as<decltype(declval<T&>()++), T> >> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template <class T>
|
||||
/*concept*/ constexpr bool incrementable = Internal::incrementable_impl<T>;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<class S, class I>
|
||||
/*concept*/ constexpr bool sentinel_for = semiregular<S> &&
|
||||
input_or_output_iterator<I> &&
|
||||
Internal::weakly_equality_comparable_with<S, I>;
|
||||
template<class S, class I>
|
||||
inline constexpr bool disable_sized_sentinel_for = false;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class S, class I, class = void>
|
||||
/*concept*/ constexpr bool sized_sentinel_for_impl = false;
|
||||
template<class S, class I>
|
||||
/*concept*/ constexpr bool sized_sentinel_for_impl<S, I, enable_if_t<
|
||||
sentinel_for<S, I>
|
||||
&& !disable_sized_sentinel_for<remove_cv_t<S>, remove_cv_t<I>>
|
||||
&& same_as<decltype(declval<S>() - declval<I>()), iter_difference_t<I>>
|
||||
&& same_as<decltype(declval<I>() - declval<S>()), iter_difference_t<I>> >> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<class S, class I>
|
||||
/*concept*/ constexpr bool sized_sentinel_for = Internal::sized_sentinel_for_impl<S, I>;
|
||||
|
||||
template<class I>
|
||||
struct iterator_traits;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
// ITER_CONCEPT(I) general concept
|
||||
template<class I, class = void>
|
||||
constexpr bool use_traits_iterator_concept_for_concept = false;
|
||||
template<class I>
|
||||
constexpr bool use_traits_iterator_concept_for_concept<I, void_t<typename iterator_traits<I>::iterator_concept>> = true;
|
||||
|
||||
template<class I, class = void>
|
||||
constexpr bool use_traits_iterator_category_for_concept = false;
|
||||
template<class I>
|
||||
constexpr bool use_traits_iterator_category_for_concept<I,
|
||||
void_t<typename iterator_traits<I>::iterator_category>> = !use_traits_iterator_concept_for_concept<I>;
|
||||
|
||||
template<class I, class = void>
|
||||
constexpr bool use_random_access_iterator_tag_for_concept = false;
|
||||
template<class I>
|
||||
constexpr bool use_random_access_iterator_tag_for_concept<I,
|
||||
void_t<iterator_traits<I>>> = !use_traits_iterator_concept_for_concept<I>
|
||||
&& !use_traits_iterator_category_for_concept<I>;
|
||||
|
||||
template<class I, class = void>
|
||||
struct iter_concept;
|
||||
|
||||
template<class I>
|
||||
struct iter_concept<I, enable_if_t<use_traits_iterator_concept_for_concept<I>>>
|
||||
{
|
||||
using type = typename iterator_traits<I>::iterator_concept;
|
||||
};
|
||||
template<class I>
|
||||
struct iter_concept<I, enable_if_t<use_traits_iterator_category_for_concept<I>>>
|
||||
{
|
||||
using type = typename iterator_traits<I>::iterator_category;
|
||||
};
|
||||
|
||||
template<class I>
|
||||
struct iter_concept<I, enable_if_t<use_random_access_iterator_tag_for_concept<I>>>
|
||||
{
|
||||
using type = random_access_iterator_tag;
|
||||
};
|
||||
template<class I>
|
||||
using iter_concept_t = typename iter_concept<I>::type;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// indirectly readable
|
||||
template <class In>
|
||||
/*concept*/ constexpr bool indirectly_readable = Internal::indirectly_readable_impl<remove_cvref_t<In>>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
// model the indirectly writable concept
|
||||
template <class Out, class T, class = void>
|
||||
constexpr bool indirectly_writable_impl = false;
|
||||
|
||||
template <class Out, class T>
|
||||
constexpr bool indirectly_writable_impl<Out, T, void_t<
|
||||
decltype(*declval<Out&>() = declval<T>()),
|
||||
decltype(*declval<Out>() = declval<T>()),
|
||||
decltype(const_cast<const iter_reference_t<Out>&&>(*declval<Out&>()) = declval<T>()),
|
||||
decltype(const_cast<const iter_reference_t<Out>&&>(*declval<Out>()) = declval<T>())>
|
||||
> = true;
|
||||
}
|
||||
namespace AZStd
|
||||
{
|
||||
// indirectly writable
|
||||
template <class Out, class T>
|
||||
/*concept*/ constexpr bool indirectly_writable = Internal::indirectly_writable_impl<Out, T>;
|
||||
|
||||
// indirectly movable
|
||||
template<class In, class Out>
|
||||
/*concept*/ constexpr bool indirectly_movable = indirectly_readable<In> && indirectly_writable<Out, iter_rvalue_reference_t<In>>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class In, class Out, class = void>
|
||||
constexpr bool indirectly_movable_storage_impl = false;
|
||||
|
||||
template<class In, class Out>
|
||||
constexpr bool indirectly_movable_storage_impl<In, Out, enable_if_t<
|
||||
indirectly_movable<In, Out> &&
|
||||
indirectly_writable<Out, iter_value_t<In>> &&
|
||||
movable<iter_value_t<In>> &&
|
||||
constructible_from<iter_value_t<In>, iter_rvalue_reference_t<In>> &&
|
||||
assignable_from<iter_value_t<In>&, iter_rvalue_reference_t<In>>> > = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<class In, class Out>
|
||||
/*concept*/ constexpr bool indirectly_movable_storable = Internal::indirectly_movable_storage_impl<In, Out>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class In, class Out, class = void>
|
||||
constexpr bool indirectly_copyable_impl = false;
|
||||
|
||||
template<class In, class Out>
|
||||
constexpr bool indirectly_copyable_impl<In, Out, enable_if_t<
|
||||
indirectly_readable<In> &&
|
||||
indirectly_writable<Out, iter_reference_t<In>>> > = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// indirectly copyable
|
||||
template<class In, class Out>
|
||||
/*concept*/ constexpr bool indirectly_copyable = Internal::indirectly_copyable_impl<In, Out>;
|
||||
}
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class In, class Out, class = void>
|
||||
constexpr bool indirectly_copyable_storable_impl = false;
|
||||
|
||||
template<class In, class Out>
|
||||
constexpr bool indirectly_copyable_storable_impl<In, Out, enable_if_t<
|
||||
indirectly_copyable<In, Out> &&
|
||||
indirectly_writable<Out, iter_value_t<In>&> &&
|
||||
indirectly_writable<Out, const iter_value_t<In>&> &&
|
||||
indirectly_writable<Out, iter_value_t<In>&&> &&
|
||||
indirectly_writable<Out, const iter_value_t<In>&&> &&
|
||||
copyable<iter_value_t<In>> &&
|
||||
constructible_from<iter_value_t<In>, iter_reference_t<In>> &&
|
||||
assignable_from<iter_value_t<In>&, iter_reference_t<In>>> > = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<class In, class Out>
|
||||
/*concept*/ constexpr bool indirectly_copyable_storable = Internal::indirectly_copyable_storable_impl<In, Out>;
|
||||
}
|
||||
|
||||
namespace AZStd::ranges::Internal
|
||||
{
|
||||
template<class I1, class I2>
|
||||
void iter_swap(I1, I2) = delete;
|
||||
|
||||
template <class I1, class I2, class = void>
|
||||
constexpr bool iter_swap_adl = false;
|
||||
|
||||
template <class I1, class I2>
|
||||
constexpr bool iter_swap_adl<I1, I2, void_t<decltype(iter_swap(declval<I1>(), declval<I2>()))>> = true;
|
||||
|
||||
template <class I1, class I2, class = void>
|
||||
constexpr bool is_class_or_enum_with_iter_swap_adl = false;
|
||||
|
||||
template <class I1, class I2>
|
||||
constexpr bool is_class_or_enum_with_iter_swap_adl<I1, I2, enable_if_t<iter_swap_adl<I1, I2>
|
||||
&& (is_class_v<remove_cvref_t<I1>> || is_enum_v<remove_cvref_t<I1>>)
|
||||
&& (is_class_v<remove_cvref_t<I2>> || is_enum_v<remove_cvref_t<I2>>)>> = true;
|
||||
|
||||
struct iter_swap_fn
|
||||
{
|
||||
template <class I1, class I2>
|
||||
constexpr auto operator()(I1&& i1, I2&& i2) const
|
||||
->enable_if_t<is_class_or_enum_with_iter_swap_adl<I1, I2>
|
||||
>
|
||||
{
|
||||
iter_swap(AZStd::forward<I1>(i1), AZStd::forward<I1>(i2));
|
||||
}
|
||||
template <class I1, class I2>
|
||||
constexpr auto operator()(I1&& i1, I2&& i2) const
|
||||
->enable_if_t<!is_class_or_enum_with_iter_swap_adl<I1, I2>
|
||||
&& indirectly_readable<I1>
|
||||
&& indirectly_readable<I2>
|
||||
&& swappable_with<iter_reference_t<I1>, iter_reference_t<I2>>
|
||||
>
|
||||
{
|
||||
ranges::swap(*i1, *i2);
|
||||
}
|
||||
|
||||
template <class I1, class I2>
|
||||
constexpr auto operator()(I1&& i1, I2&& i2) const
|
||||
->enable_if_t<!is_class_or_enum_with_iter_swap_adl<I1, I2>
|
||||
&& indirectly_movable_storable<I1, I2>
|
||||
&& indirectly_movable_storable<I2, I1>
|
||||
>
|
||||
{
|
||||
*AZStd::forward<I1>(i1) = iter_exchange_move(AZStd::forward<I2>(i2), AZStd::forward<I1>(i1));
|
||||
}
|
||||
|
||||
private:
|
||||
template<class X, class Y>
|
||||
static constexpr iter_value_t<X> iter_exchange_move(X&& x, Y&& y)
|
||||
noexcept(noexcept(iter_value_t<X>(iter_move(x))) && noexcept(*x = iter_move(y)))
|
||||
{
|
||||
iter_value_t<X> old_value(iter_move(x));
|
||||
*x = iter_move(y);
|
||||
return old_value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace AZStd::ranges
|
||||
{
|
||||
inline namespace customization_point_object
|
||||
{
|
||||
inline constexpr Internal::iter_swap_fn iter_swap{};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template <class I1, class I2, class = void>
|
||||
constexpr bool indirectly_swappable_impl = false;
|
||||
template <class I1, class I2>
|
||||
constexpr bool indirectly_swappable_impl<I1, I2, enable_if_t<
|
||||
indirectly_readable<I1>&& indirectly_readable<I2>
|
||||
&& sfinae_trigger_v<
|
||||
decltype(AZStd::ranges::iter_swap(declval<I1>(), declval<I1>())),
|
||||
decltype(AZStd::ranges::iter_swap(declval<I2>(), declval<I2>())),
|
||||
decltype(AZStd::ranges::iter_swap(declval<I1>(), declval<I2>())),
|
||||
decltype(AZStd::ranges::iter_swap(declval<I2>(), declval<I1>()))>>> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<class I1, class I2 = I1>
|
||||
/*concept*/ constexpr bool indirectly_swappable = Internal::indirectly_swappable_impl<I1, I2>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class I, class = void>
|
||||
constexpr bool input_iterator_impl = false;
|
||||
template<class I>
|
||||
constexpr bool input_iterator_impl<I, enable_if_t<input_or_output_iterator<I>
|
||||
&& derived_from<iter_concept_t<I>, input_iterator_tag>
|
||||
&& indirectly_readable<I>
|
||||
>> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// input iterator
|
||||
template<class I>
|
||||
/*concept*/ constexpr bool input_iterator = Internal::input_iterator_impl<I>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class I, class T, class = void>
|
||||
constexpr bool output_iterator_impl = false;
|
||||
template<class I, class T>
|
||||
constexpr bool output_iterator_impl<I, T, enable_if_t<input_or_output_iterator<I>
|
||||
&& indirectly_writable<I, T>
|
||||
&& sfinae_trigger_v<decltype(*declval<I&>()++ = AZStd::declval<T>())>
|
||||
>> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// output iterator
|
||||
template<class I, class T>
|
||||
/*concept*/ constexpr bool output_iterator = Internal::output_iterator_impl<I, T>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class I, class = void>
|
||||
constexpr bool forward_iterator_impl = false;
|
||||
template<class I>
|
||||
constexpr bool forward_iterator_impl<I, enable_if_t<input_iterator<I>
|
||||
&& derived_from<Internal::iter_concept_t<I>, forward_iterator_tag>
|
||||
&& incrementable<I>
|
||||
&& sentinel_for<I, I>> > = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// forward_iterator
|
||||
template<class I>
|
||||
/*concept*/ constexpr bool forward_iterator = Internal::forward_iterator_impl<I>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class I, class = void>
|
||||
constexpr bool bidirectional_iterator_impl = false;
|
||||
template<class I>
|
||||
constexpr bool bidirectional_iterator_impl<I, enable_if_t<forward_iterator<I>
|
||||
&& derived_from<iter_concept_t<I>, bidirectional_iterator_tag>
|
||||
&& same_as<decltype(--declval<I&>()), I&>
|
||||
&& same_as<decltype(declval<I&>()--), I> >> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// bidirectional iterator
|
||||
template<class I>
|
||||
/*concept*/ constexpr bool bidirectional_iterator = Internal::bidirectional_iterator_impl<I>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class I, class = void>
|
||||
constexpr bool random_access_iterator_impl = false;
|
||||
template<class I>
|
||||
constexpr bool random_access_iterator_impl<I, enable_if_t<bidirectional_iterator<I>
|
||||
&& derived_from<iter_concept_t<I>, random_access_iterator_tag>
|
||||
&& totally_ordered<I>
|
||||
&& sized_sentinel_for<I, I>
|
||||
&& same_as<decltype(declval<I&>() += declval<const iter_difference_t<I>>()), I&>
|
||||
&& same_as<decltype(declval<const I>() + declval<const iter_difference_t<I>>()), I>
|
||||
&& same_as<decltype(declval<iter_difference_t<I>>() + declval<const I>()), I>
|
||||
&& same_as<decltype(declval<I&>() -= declval<const iter_difference_t<I>>()), I&>
|
||||
&& same_as<decltype(declval<const I>() - declval<const iter_difference_t<I>>()), I>
|
||||
&& same_as<decltype(declval<const I&>()[declval<iter_difference_t<I>>()]), iter_reference_t<I>>>>
|
||||
= true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template<class I>
|
||||
/*concept*/ constexpr bool random_access_iterator = Internal::random_access_iterator_impl<I>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template<class I, class = void>
|
||||
constexpr bool contiguous_iterator_impl = false;
|
||||
template<class I>
|
||||
constexpr bool contiguous_iterator_impl<I, enable_if_t<random_access_iterator<I>
|
||||
&& derived_from<iter_concept_t<I>, contiguous_iterator_tag>
|
||||
&& is_lvalue_reference_v<iter_reference_t<I>>
|
||||
&& indirectly_readable<I>
|
||||
&& same_as<iter_value_t<I>, remove_cvref_t<iter_reference_t<I>>>
|
||||
> >
|
||||
= same_as<decltype(to_address(declval<const I&>())), add_pointer_t<iter_reference_t<I>>>;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// contiguous iterator
|
||||
template<class I>
|
||||
/*concept*/ constexpr bool contiguous_iterator = Internal::contiguous_iterator_impl<I>;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
// models the predicate concept
|
||||
template <bool, class F, class... Args>
|
||||
constexpr bool predicate_impl = false;
|
||||
template <class F, class... Args>
|
||||
constexpr bool predicate_impl<true, F, Args...> = Internal::boolean_testable<invoke_result_t<F, Args...>>;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// models the predicate concept
|
||||
template <class F, class... Args>
|
||||
/*concept*/ constexpr bool predicate = Internal::predicate_impl<regular_invocable<F, Args...>, F, Args...>;
|
||||
|
||||
// models the relation concept
|
||||
template <class R, class T, class U>
|
||||
/*concept*/ constexpr bool relation = predicate<R, T, T> && predicate<R, U, U>
|
||||
&& predicate<R, T, U> && predicate<R, U, T>;
|
||||
|
||||
// models the equivalence_relation concept
|
||||
template <class R, class T, class U>
|
||||
/*concept*/ constexpr bool equivalence_relation = relation<R, T, U>;
|
||||
|
||||
// models the strict_weak_order concept
|
||||
// Note: semantically this is different than equivalence_relation
|
||||
template <class R, class T, class U>
|
||||
/*concept*/ constexpr bool strict_weak_order = relation<R, T, U>;
|
||||
}
|
||||
@@ -135,9 +135,10 @@ namespace AZStd
|
||||
AZ_FORCE_INLINE this_type& operator--() { --m_offset; return *this; }
|
||||
AZ_FORCE_INLINE this_type operator--(int) { this_type tmp = *this; --m_offset; return tmp; }
|
||||
AZ_FORCE_INLINE this_type& operator+=(difference_type offset) { m_offset += offset; return *this; }
|
||||
AZ_FORCE_INLINE this_type operator+(difference_type offset) { this_type tmp = *this; tmp += offset; return tmp; }
|
||||
AZ_FORCE_INLINE this_type operator+(difference_type offset) const { this_type tmp = *this; tmp += offset; return tmp; }
|
||||
friend AZ_FORCE_INLINE this_type operator+(difference_type offset, const this_type& rhs) { this_type tmp = rhs; tmp += offset; return tmp; }
|
||||
AZ_FORCE_INLINE this_type& operator-=(difference_type offset) { m_offset -= offset; return *this; }
|
||||
AZ_FORCE_INLINE this_type operator-(difference_type offset) { this_type tmp = *this; tmp -= offset; return tmp; }
|
||||
AZ_FORCE_INLINE this_type operator-(difference_type offset) const { this_type tmp = *this; tmp -= offset; return tmp; }
|
||||
/// ???
|
||||
AZ_FORCE_INLINE difference_type operator-(const this_type& rhs) const
|
||||
{
|
||||
@@ -197,9 +198,10 @@ namespace AZStd
|
||||
AZ_FORCE_INLINE this_type& operator--() { --base_type::m_offset; return *this; }
|
||||
AZ_FORCE_INLINE this_type operator--(int) { this_type tmp = *this; --base_type::m_offset; return tmp; }
|
||||
AZ_FORCE_INLINE this_type& operator+=(difference_type offset) { base_type::m_offset += offset; return *this; }
|
||||
AZ_FORCE_INLINE this_type operator+(difference_type offset) { this_type tmp = *this; tmp += offset; return tmp; }
|
||||
AZ_FORCE_INLINE this_type operator+(difference_type offset) const { this_type tmp = *this; tmp += offset; return tmp; }
|
||||
friend AZ_FORCE_INLINE this_type operator+(difference_type offset, const this_type& rhs) { this_type tmp = rhs; tmp += offset; return tmp; }
|
||||
AZ_FORCE_INLINE this_type& operator-=(difference_type offset) { base_type::m_offset -= offset; return *this; }
|
||||
AZ_FORCE_INLINE this_type operator-(difference_type offset) { this_type tmp = *this; tmp -= offset; return tmp; }
|
||||
AZ_FORCE_INLINE this_type operator-(difference_type offset) const { this_type tmp = *this; tmp -= offset; return tmp; }
|
||||
AZ_FORCE_INLINE difference_type operator-(const this_type& rhs) const
|
||||
{
|
||||
return rhs.m_offset <= base_type::m_offset ? base_type::m_offset - rhs.m_offset : -(difference_type)(rhs.m_offset - base_type::m_offset);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <AzCore/Casting/numeric_cast.h>
|
||||
#include <AzCore/std/algorithm.h>
|
||||
#include <AzCore/std/concepts/concepts.h>
|
||||
#include <AzCore/std/createdestroy.h>
|
||||
#include <AzCore/std/typetraits/typetraits.h>
|
||||
|
||||
@@ -101,7 +102,7 @@ namespace AZStd::Internal
|
||||
//! Invokes destructor on all elements in range
|
||||
//! No-op on empty container
|
||||
//! Nothing to destroy since the storage is empty.
|
||||
template <typename InputIt, typename = enable_if_t<Internal::is_input_iterator_v<InputIt>>>
|
||||
template <typename InputIt, typename = enable_if_t<input_iterator<InputIt>>>
|
||||
static constexpr void unsafe_destroy(InputIt, InputIt) noexcept
|
||||
{
|
||||
}
|
||||
@@ -214,7 +215,7 @@ namespace AZStd::Internal
|
||||
//! Destructs elements in the range [begin, end).
|
||||
//! This does not modify the size of the storage
|
||||
//! This is a no-op for trivial types
|
||||
template <typename InputIt, typename = enable_if_t<Internal::is_input_iterator_v<InputIt>>>
|
||||
template <typename InputIt, typename = enable_if_t<input_iterator<InputIt>>>
|
||||
void unsafe_destroy(InputIt, InputIt) noexcept
|
||||
{
|
||||
}
|
||||
@@ -334,7 +335,7 @@ namespace AZStd::Internal
|
||||
//! Destructs elements in the range [begin, end).
|
||||
//! This does not modify the size of the storage
|
||||
//! Invokes the destuctor via the AZStd::destroy method
|
||||
template <typename InputIt, typename = enable_if_t<Internal::is_input_iterator_v<InputIt>>>
|
||||
template <typename InputIt, typename = enable_if_t<input_iterator<InputIt>>>
|
||||
void unsafe_destroy(InputIt first, InputIt last) noexcept(is_nothrow_destructible_v<value_type>)
|
||||
{
|
||||
AZSTD_CONTAINER_ASSERT(first >= data() && first <= data() + size(), "begin iterator is not in range of storage");
|
||||
@@ -410,7 +411,7 @@ namespace AZStd
|
||||
AZStd::uninitialized_fill_n(data(), numElements, value);
|
||||
}
|
||||
|
||||
template <class InputIt, typename = AZStd::enable_if_t<Internal::is_input_iterator_v<InputIt>>>
|
||||
template <class InputIt, typename = AZStd::enable_if_t<input_iterator<InputIt>>>
|
||||
fixed_vector(InputIt first, InputIt last)
|
||||
{
|
||||
resize_no_construct(AZStd::distance(first, last));
|
||||
@@ -615,7 +616,7 @@ namespace AZStd
|
||||
insert(end(), numElements, value);
|
||||
}
|
||||
|
||||
template <class InputIt, typename = AZStd::enable_if_t<Internal::is_input_iterator_v<InputIt>>>
|
||||
template <class InputIt, typename = AZStd::enable_if_t<input_iterator<InputIt>>>
|
||||
void assign(InputIt first, InputIt last)
|
||||
{
|
||||
clear();
|
||||
@@ -641,8 +642,18 @@ namespace AZStd
|
||||
return &newElement;
|
||||
}
|
||||
|
||||
AZStd::uninitialized_move(insertPosPtr, dataEnd, insertPosPtr + 1);
|
||||
// We need to move data with care, it is overlapping.
|
||||
|
||||
// first move the last element into the uninitialized position as that will not overlap.
|
||||
pointer nonOverlap = dataEnd - 1;
|
||||
AZStd::uninitialized_move(nonOverlap, dataEnd, dataEnd);
|
||||
|
||||
// copy the memory backwards while performing AZStd::move on the existing elements the area with overlapping memory
|
||||
// to move the elments to the right by 1
|
||||
AZStd::move_backward(insertPosPtr, nonOverlap, dataEnd);
|
||||
// add new elements
|
||||
AZStd::construct_at(insertPosPtr, AZStd::forward<Args>(args)...);
|
||||
resize_no_construct(size() + 1);
|
||||
return iterator(insertPosPtr);
|
||||
}
|
||||
iterator insert(const_iterator insertPos, const_reference value)
|
||||
@@ -707,7 +718,7 @@ namespace AZStd
|
||||
}
|
||||
}
|
||||
|
||||
template<class InputIt, typename = AZStd::enable_if_t<Internal::is_input_iterator_v<InputIt>>>
|
||||
template<class InputIt, typename = AZStd::enable_if_t<input_iterator<InputIt>>>
|
||||
void insert(const_iterator insertPos, InputIt first, InputIt last)
|
||||
{
|
||||
// specialize for iterator categories.
|
||||
|
||||
@@ -7,9 +7,37 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#include <AzCore/std/containers/fixed_vector.h>
|
||||
#include <AzCore/std/containers/array.h>
|
||||
#include <AzCore/std/limits.h>
|
||||
#include <AzCore/std/ranges/ranges.h>
|
||||
#include <AzCore/std/typetraits/type_identity.h>
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
|
||||
|
||||
template <class T, size_t Extent = dynamic_extent>
|
||||
class span;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template <class T>
|
||||
inline constexpr bool is_std_array = false;
|
||||
|
||||
template <class U, size_t N>
|
||||
inline constexpr bool is_std_array<::AZStd::array<U, N>> = true;
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool is_std_span = false;
|
||||
|
||||
template <class U, size_t Extent>
|
||||
inline constexpr bool is_std_span<::AZStd::span<U, Extent>> = true;
|
||||
|
||||
template <class T, class U>
|
||||
inline constexpr bool is_array_convertible = is_convertible_v<T(*)[], U(*)[]>;
|
||||
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
@@ -33,97 +61,149 @@ 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 T>
|
||||
class span final
|
||||
template <class T, size_t Extent>
|
||||
class span
|
||||
{
|
||||
public:
|
||||
using element_type = T;
|
||||
using value_type = AZStd::remove_cv_t<T>;
|
||||
|
||||
using pointer = T*;
|
||||
using const_pointer = const T*;
|
||||
|
||||
using reference = T&;
|
||||
using const_reference = const T&;
|
||||
|
||||
using size_type = AZStd::size_t;
|
||||
using difference_type = AZStd::ptrdiff_t;
|
||||
|
||||
using iterator = T*;
|
||||
using const_iterator = const T*;
|
||||
using pointer = element_type*;
|
||||
using const_pointer = const element_type*;
|
||||
|
||||
using reference = element_type&;
|
||||
using const_reference = const element_type&;
|
||||
|
||||
|
||||
using iterator = element_type*;
|
||||
using const_iterator = const element_type*;
|
||||
using reverse_iterator = AZStd::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = AZStd::reverse_iterator<const_iterator>;
|
||||
|
||||
constexpr span();
|
||||
inline static constexpr size_t extent = Extent;
|
||||
|
||||
constexpr span() noexcept = default;;
|
||||
|
||||
~span() = default;
|
||||
|
||||
constexpr span(pointer s, size_type length);
|
||||
template <class It, enable_if_t<contiguous_iterator<It> &&
|
||||
Internal::is_array_convertible<remove_reference_t<iter_reference_t<It>>, T> &&
|
||||
Extent == dynamic_extent>* = nullptr>
|
||||
constexpr span(It first, size_type length);
|
||||
|
||||
constexpr span(pointer first, pointer last);
|
||||
template <class It, enable_if_t<contiguous_iterator<It> &&
|
||||
Internal::is_array_convertible<remove_reference_t<iter_reference_t<It>>, T> &&
|
||||
Extent != dynamic_extent, int> = 0>
|
||||
constexpr explicit span(It first, size_type length);
|
||||
|
||||
// We explicitly delete this constructor because it's too easy to accidentally
|
||||
// create a span to just the first element instead of an entire array.
|
||||
constexpr span(const_pointer s) = delete;
|
||||
template <class It, class End, enable_if_t<contiguous_iterator<It> &&
|
||||
Internal::is_array_convertible<remove_reference_t<iter_reference_t<It>>, T> &&
|
||||
sized_sentinel_for<End, It> &&
|
||||
Extent == dynamic_extent>* = nullptr>
|
||||
constexpr span(It first, End last);
|
||||
|
||||
template<typename Container>
|
||||
constexpr span(Container& data);
|
||||
template <class It, class End, enable_if_t<contiguous_iterator<It> &&
|
||||
Internal::is_array_convertible<remove_reference_t<iter_reference_t<It>>, T> &&
|
||||
sized_sentinel_for<End, It> &&
|
||||
Extent != dynamic_extent, int> = 0>
|
||||
constexpr explicit span(It first, End last);
|
||||
|
||||
template<typename Container>
|
||||
constexpr span(const Container& data);
|
||||
template<size_t N, class = enable_if_t<N == dynamic_extent || N == Extent>>
|
||||
constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
|
||||
|
||||
constexpr span(const span&) = default;
|
||||
template <class U, size_t N, class = enable_if_t<N == dynamic_extent || N == Extent>>
|
||||
constexpr span(array<U, N>& data) noexcept;
|
||||
template <class U, size_t N, class = enable_if_t<N == dynamic_extent || N == Extent>>
|
||||
constexpr span(const array<U, N>& data) noexcept;
|
||||
|
||||
constexpr span(span&& other);
|
||||
template <class R, class = enable_if_t<ranges::contiguous_range<R> &&
|
||||
ranges::sized_range<R> &&
|
||||
(ranges::borrowed_range<R> || is_const_v<element_type>) &&
|
||||
!Internal::is_std_span<remove_cvref_t<R>> &&
|
||||
!Internal::is_std_array<remove_cvref_t<R>> &&
|
||||
!is_array_v<remove_cvref_t<R>> &&
|
||||
Internal::is_array_convertible<remove_reference_t<ranges::range_reference_t<R>>, element_type> >>
|
||||
constexpr span(R&& r);
|
||||
|
||||
template <class U, size_t OtherExtent, class = enable_if_t<
|
||||
(extent == dynamic_extent || OtherExtent == dynamic_extent || extent == OtherExtent)
|
||||
&& Internal::is_array_convertible<U, element_type> >>
|
||||
constexpr span(const span<U, OtherExtent>& other);
|
||||
|
||||
constexpr span(const span&) noexcept = default;
|
||||
|
||||
constexpr span& operator=(const span& other) = default;
|
||||
|
||||
constexpr span& operator=(span&& other);
|
||||
// subviews -> https://eel.is/c++draft/views#span.sub
|
||||
template <size_t Count>
|
||||
constexpr span<element_type, Count> first() const;
|
||||
template <size_t Count>
|
||||
constexpr span<element_type, Count> last() const;
|
||||
template <size_t Offset, size_t Count = dynamic_extent>
|
||||
constexpr auto subspan() const;
|
||||
|
||||
constexpr size_type size() const;
|
||||
constexpr span<element_type, dynamic_extent> first(size_type count) const;
|
||||
constexpr span<element_type, dynamic_extent> last(size_type count) const;
|
||||
constexpr span<element_type, dynamic_extent> subspan(size_type offset, size_type count = dynamic_extent) const;
|
||||
|
||||
constexpr bool empty() const;
|
||||
// observers - https://eel.is/c++draft/views#span.obs
|
||||
constexpr size_type size() const noexcept;
|
||||
constexpr size_type size_bytes() const noexcept;
|
||||
|
||||
constexpr pointer data();
|
||||
constexpr const_pointer data() const;
|
||||
[[nodiscard]] constexpr bool empty() const noexcept;
|
||||
|
||||
constexpr const_reference operator[](size_type index) const;
|
||||
constexpr reference operator[](size_type index);
|
||||
// element access - https://eel.is/c++draft/views#span.elem
|
||||
constexpr reference operator[](size_type index) const;
|
||||
constexpr reference front() const;
|
||||
constexpr reference back() const;
|
||||
constexpr pointer data() const noexcept;
|
||||
|
||||
constexpr void erase();
|
||||
// iterator support - https://eel.is/c++draft/views#span.iterators
|
||||
constexpr iterator begin() const noexcept;
|
||||
constexpr iterator end() const noexcept;
|
||||
|
||||
constexpr iterator begin();
|
||||
constexpr iterator end();
|
||||
constexpr const_iterator begin() const;
|
||||
constexpr const_iterator end() const;
|
||||
|
||||
constexpr const_iterator cbegin() const;
|
||||
constexpr const_iterator cend() const;
|
||||
|
||||
constexpr reverse_iterator rbegin();
|
||||
constexpr reverse_iterator rend();
|
||||
constexpr const_reverse_iterator rbegin() const;
|
||||
constexpr const_reverse_iterator rend() const;
|
||||
|
||||
constexpr const_reverse_iterator crbegin() const;
|
||||
constexpr const_reverse_iterator crend() const;
|
||||
|
||||
friend bool operator==(span lhs, span rhs)
|
||||
{
|
||||
return lhs.m_begin == rhs.m_begin && lhs.m_end == rhs.m_end;
|
||||
}
|
||||
|
||||
friend bool operator!=(span lhs, span rhs) { return !(lhs == rhs); }
|
||||
friend bool operator< (span lhs, span rhs) { return lhs.m_begin < rhs.m_begin || lhs.m_begin == rhs.m_begin && lhs.m_end < rhs.m_end; }
|
||||
friend bool operator> (span lhs, span rhs) { return lhs.m_begin > rhs.m_begin || lhs.m_begin == rhs.m_begin && lhs.m_end > rhs.m_end; }
|
||||
friend bool operator<=(span lhs, span rhs) { return lhs == rhs || lhs < rhs; }
|
||||
friend bool operator>=(span lhs, span rhs) { return lhs == rhs || lhs > rhs; }
|
||||
constexpr reverse_iterator rbegin() const noexcept;
|
||||
constexpr reverse_iterator rend() const noexcept;
|
||||
|
||||
private:
|
||||
pointer m_begin;
|
||||
pointer m_end;
|
||||
pointer m_data{};
|
||||
size_type m_size{};
|
||||
};
|
||||
|
||||
// deduction guides https://eel.is/c++draft/views#span.deduct
|
||||
template <class It, class EndOrSize, class = enable_if_t<contiguous_iterator<It>>>
|
||||
span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>>;
|
||||
|
||||
// array deductions
|
||||
template <class T, size_t N>
|
||||
span(T(&)[N]) -> span<T, N>;
|
||||
template <class T, size_t N>
|
||||
span(array<T, N>&) -> span<T, N>;
|
||||
template <class T, size_t N>
|
||||
span(const array<T, N>&) -> span<const T, N>;
|
||||
|
||||
template <class R, class = enable_if_t<ranges::contiguous_range<R>>>
|
||||
span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
|
||||
|
||||
// [span.objectrep], views of object representation
|
||||
template <class ElementType, size_t Extent>
|
||||
auto as_bytes(span<ElementType, Extent> s) noexcept
|
||||
-> span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>;
|
||||
|
||||
template <class ElementType, size_t Extent>
|
||||
auto as_writable_bytes(span<ElementType, Extent> s) noexcept
|
||||
-> enable_if_t<!is_const_v<ElementType>, span<byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>>;
|
||||
|
||||
} // namespace AZStd
|
||||
|
||||
namespace AZStd::ranges
|
||||
{
|
||||
template<class ElementType, size_t Extent>
|
||||
inline constexpr bool enable_view<span<ElementType, Extent>> = true;
|
||||
template<class ElementType, size_t Extent>
|
||||
inline constexpr bool enable_borrowed_range<span<ElementType, Extent>> = true;
|
||||
}
|
||||
|
||||
#include <AzCore/std/containers/span.inl>
|
||||
|
||||
@@ -9,116 +9,206 @@
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template <class Element>
|
||||
inline constexpr span<Element>::span()
|
||||
: m_begin(nullptr)
|
||||
, m_end(nullptr)
|
||||
{ }
|
||||
template <class T, size_t Extent>
|
||||
template <class It, enable_if_t<contiguous_iterator<It> &&
|
||||
Internal::is_array_convertible<remove_reference_t<iter_reference_t<It>>, T> &&
|
||||
Extent == dynamic_extent>*>
|
||||
inline constexpr span<T, Extent>::span(It first, size_type length)
|
||||
: m_data{ to_address(first) }
|
||||
, m_size{ length }
|
||||
{}
|
||||
|
||||
template <class Element>
|
||||
inline constexpr span<Element>::span(pointer s, size_type length)
|
||||
: m_begin(s)
|
||||
, m_end(m_begin + length)
|
||||
template <class T, size_t Extent>
|
||||
template <class It, enable_if_t<contiguous_iterator<It> &&
|
||||
Internal::is_array_convertible<remove_reference_t<iter_reference_t<It>>, T> &&
|
||||
Extent != dynamic_extent, int>>
|
||||
inline constexpr span<T, Extent>::span(It first, size_type length)
|
||||
: m_data{ to_address(first) }
|
||||
, m_size{ length }
|
||||
{}
|
||||
|
||||
template <class T, size_t Extent>
|
||||
template <class It, class End, enable_if_t<contiguous_iterator<It> &&
|
||||
Internal::is_array_convertible<remove_reference_t<iter_reference_t<It>>, T> &&
|
||||
sized_sentinel_for<End, It> &&
|
||||
Extent == dynamic_extent>*>
|
||||
inline constexpr span<T, Extent>::span(It first, End last)
|
||||
: m_data{to_address(first)}
|
||||
, m_size(last - first)
|
||||
{}
|
||||
|
||||
template <class T, size_t Extent>
|
||||
template <class It, class End, enable_if_t<contiguous_iterator<It> &&
|
||||
Internal::is_array_convertible<remove_reference_t<iter_reference_t<It>>, T> &&
|
||||
sized_sentinel_for<End, It> &&
|
||||
Extent != dynamic_extent, int>>
|
||||
inline constexpr span<T, Extent>::span(It first, End last)
|
||||
: m_data{to_address(first)}
|
||||
, m_size(last - first)
|
||||
{}
|
||||
|
||||
template <class T, size_t Extent>
|
||||
template <size_t N, class>
|
||||
inline constexpr span<T, Extent>::span(type_identity_t<element_type>(&arr)[N]) noexcept
|
||||
: m_data{ arr }
|
||||
, m_size{ N }
|
||||
{}
|
||||
|
||||
template <class T, size_t Extent>
|
||||
template <class U, size_t N, class>
|
||||
inline constexpr span<T, Extent>::span(array<U, N>& arr) noexcept
|
||||
: m_data{ arr.data() }
|
||||
, m_size{ arr.size() }
|
||||
{}
|
||||
template <class T, size_t Extent>
|
||||
template <class U, size_t N, class>
|
||||
inline constexpr span<T, Extent>::span(const array<U, N>& arr) noexcept
|
||||
: m_data{ arr.data() }
|
||||
, m_size{ arr.size() }
|
||||
{}
|
||||
|
||||
template <class T, size_t Extent>
|
||||
template <class R, class>
|
||||
inline constexpr span<T, Extent>::span(R&& r)
|
||||
: m_data{ ranges::data(r) }
|
||||
, m_size{ ranges::size(r) }
|
||||
{
|
||||
if (length == 0) erase();
|
||||
AZ_Assert(Extent == dynamic_extent || Extent == m_size, "The extent of the span is non dynamic,"
|
||||
" therefore the range size must match the extent. Extent=%zu, Range size=%zu",
|
||||
Extent, ranges::size(r));
|
||||
}
|
||||
|
||||
template <class Element>
|
||||
inline constexpr span<Element>::span(pointer first, pointer last)
|
||||
: m_begin(first)
|
||||
, m_end(last)
|
||||
{ }
|
||||
|
||||
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>
|
||||
template<typename Container>
|
||||
inline constexpr span<Element>::span(const Container& data)
|
||||
: m_begin(data.data())
|
||||
, m_end(m_begin + data.size())
|
||||
{ }
|
||||
|
||||
template <class Element>
|
||||
inline constexpr span<Element>::span(span&& other)
|
||||
: span(other.m_begin, other.m_end)
|
||||
template <class T, size_t Extent>
|
||||
template <class U, size_t OtherExtent, class>
|
||||
inline constexpr span<T, Extent>::span(const span<U, OtherExtent>& other)
|
||||
: m_data{ other.data() }
|
||||
, m_size{ other.size() }
|
||||
{
|
||||
#if AZ_DEBUG_BUILD // Clearing the original pointers isn't necessary, but is good for debugging
|
||||
other.m_begin = nullptr;
|
||||
other.m_end = nullptr;
|
||||
#endif
|
||||
AZ_Assert(Extent == dynamic_extent || Extent == m_size, "The extent of the span is non dynamic,"
|
||||
" therefore the current size of the other span must match the extent. Extent=%zu, Other span size=%zu",
|
||||
Extent, other.size());
|
||||
}
|
||||
|
||||
template <class Element>
|
||||
inline constexpr AZStd::size_t span<Element>::size() const { return m_end - m_begin; }
|
||||
|
||||
template <class Element>
|
||||
inline constexpr bool span<Element>::empty() const { return m_end == m_begin; }
|
||||
|
||||
template <class Element>
|
||||
inline constexpr Element* span<Element>::data() { return m_begin; }
|
||||
|
||||
template <class Element>
|
||||
inline constexpr const Element* span<Element>::data() const { return m_begin; }
|
||||
|
||||
template <class Element>
|
||||
inline constexpr span<Element>& span<Element>::operator=(span<Element>&& other)
|
||||
// subviews
|
||||
template <class T, size_t Extent>
|
||||
template <size_t Count>
|
||||
inline constexpr auto span<T, Extent>::first() const -> span<element_type, Count>
|
||||
{
|
||||
m_begin = other.m_begin;
|
||||
m_end = other.m_end;
|
||||
#if AZ_DEBUG_BUILD // Clearing the original pointers isn't necessary, but is good for debugging
|
||||
other.m_begin = nullptr;
|
||||
other.m_end = nullptr;
|
||||
#endif
|
||||
return *this;
|
||||
static_assert(Count <= Extent, "Count is larger than the Extent of the span, a subview of the first"
|
||||
" Count elemnts of the span cannot be returned");
|
||||
AZ_Assert(Count <= size(), "Count %zu is larger than span size %zu", Count, size());
|
||||
return span<element_type, Count>{data(), Count};
|
||||
}
|
||||
|
||||
template <class Element>
|
||||
inline constexpr const Element& span<Element>::operator[](AZStd::size_t index) const
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::first(size_type count) const -> span<element_type, dynamic_extent>
|
||||
{
|
||||
AZ_Assert(count <= size(), "Count %zu is larger than current size of span size %zu", count, size());
|
||||
return { data(), count };
|
||||
}
|
||||
|
||||
template <class T, size_t Extent>
|
||||
template <size_t Count>
|
||||
inline constexpr auto span<T, Extent>::last() const -> span<element_type, Count>
|
||||
{
|
||||
static_assert(Count <= Extent, "Count is larger than the Extent of the span, a subview of the last"
|
||||
" Count elements of the span cannot be returned");
|
||||
AZ_Assert(Count <= size(), "Count %zu is larger than span size %zu", Count, size());
|
||||
return span<element_type, Count>{data() + (size() - Count), Count};
|
||||
}
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::last(size_type count) const -> span<element_type, dynamic_extent>
|
||||
{
|
||||
AZ_Assert(count <= size(), "Count %zu is larger than span size %zu", count, size());
|
||||
return { data() + (size() - count), count };
|
||||
}
|
||||
|
||||
template <class T, size_t Extent>
|
||||
template <size_t Offset, size_t Count>
|
||||
inline constexpr auto span<T, Extent>::subspan() const
|
||||
{
|
||||
static_assert(Offset <= Extent && (Count == dynamic_extent || Count <= Extent - Offset),
|
||||
"Subspan Offset must <= span Extent and the Count must be either dynamic_extent"
|
||||
" or <= (span Extent - Offset)");
|
||||
AZ_Assert(Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset),
|
||||
"Either the Subspan Offset %zu is larger than the span size %zu or the Count != dynamic_extent and"
|
||||
" its value %zu is greater than \"span size - Offset\" %zu",
|
||||
Offset, size(), Count, size() - Offset);
|
||||
using return_type = span<element_type, Count != dynamic_extent ? Count : (Extent != dynamic_extent ? Extent - Offset : dynamic_extent)>;
|
||||
return return_type{ data() + Offset, Count != dynamic_extent ? Count : size() - Offset };
|
||||
}
|
||||
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::subspan(size_type offset, size_type count) const -> span<element_type, dynamic_extent>
|
||||
{
|
||||
AZ_Assert(offset <= size() && (count == dynamic_extent || count <= size() - offset),
|
||||
"Either the Subspan offset %zu is larger than the span size %zu or the count != dynamic_extent and"
|
||||
" its value %zu is greater than \"span size - offset\" %zu",
|
||||
offset, size(), count, size() - offset);
|
||||
return { data() + offset, count != dynamic_extent ? count : size() - offset };
|
||||
}
|
||||
|
||||
|
||||
// observers
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::size() const noexcept -> size_type { return m_size; }
|
||||
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::size_bytes() const noexcept -> size_type { return m_size * sizeof(element_type); }
|
||||
|
||||
template <class T, size_t Extent>
|
||||
[[nodiscard]] inline constexpr bool span<T, Extent>::empty() const noexcept{ return size() == 0; }
|
||||
|
||||
// element access
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::operator[](size_type index) const -> reference
|
||||
{
|
||||
AZ_Assert(index < size(), "index value is out of range");
|
||||
return m_begin[index];
|
||||
return data()[index];
|
||||
}
|
||||
|
||||
template <class Element>
|
||||
inline constexpr Element& span<Element>::operator[](AZStd::size_t index)
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::front() const -> reference
|
||||
{
|
||||
AZ_Assert(index < size(), "index value is out of range");
|
||||
return m_begin[index];
|
||||
AZ_Assert(!empty(), "span cannot be empty when invoking front");
|
||||
return *data();
|
||||
}
|
||||
|
||||
template <class Element>
|
||||
inline constexpr void span<Element>::erase() { m_begin = m_end = nullptr; }
|
||||
|
||||
template <class Element>
|
||||
inline constexpr Element* span<Element>::begin() { return m_begin; }
|
||||
template <class Element>
|
||||
inline constexpr Element* span<Element>::end() { return m_end; }
|
||||
template <class Element>
|
||||
inline constexpr const Element* span<Element>::begin() const { return m_begin; }
|
||||
template <class Element>
|
||||
inline constexpr const Element* span<Element>::end() const { return m_end; }
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::back() const -> reference
|
||||
{
|
||||
AZ_Assert(!empty(), "span cannot be empty when invoking back");
|
||||
return *(data() + (size() - 1));
|
||||
}
|
||||
|
||||
template <class Element>
|
||||
inline constexpr const Element* span<Element>::cbegin() const { return m_begin; }
|
||||
template <class Element>
|
||||
inline constexpr const Element* span<Element>::cend() const { return m_end; }
|
||||
// iterator support
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::data() const noexcept -> pointer { return m_data; }
|
||||
|
||||
template <class Element>
|
||||
inline constexpr AZStd::reverse_iterator<Element*> span<Element>::rbegin() { return AZStd::reverse_iterator<Element*>(m_end); }
|
||||
template <class Element>
|
||||
inline constexpr AZStd::reverse_iterator<Element*> span<Element>::rend() { return AZStd::reverse_iterator<Element*>(m_begin); }
|
||||
template <class Element>
|
||||
inline constexpr AZStd::reverse_iterator<const Element*> span<Element>::rbegin() const { return AZStd::reverse_iterator<const Element*>(m_end); }
|
||||
template <class Element>
|
||||
inline constexpr AZStd::reverse_iterator<const Element*> span<Element>::rend() const { return AZStd::reverse_iterator<const Element*>(m_begin); }
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::begin() const noexcept -> iterator{ return m_data; }
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::end() const noexcept -> iterator { return m_data + m_size; }
|
||||
|
||||
template <class Element>
|
||||
inline constexpr AZStd::reverse_iterator<const Element*> span<Element>::crbegin() const { return AZStd::reverse_iterator<const Element*>(cend()); }
|
||||
template <class Element>
|
||||
inline constexpr AZStd::reverse_iterator<const Element*> span<Element>::crend() const { return AZStd::reverse_iterator<const Element*>(cbegin()); }
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::rbegin() const noexcept -> reverse_iterator { return AZStd::make_reverse_iterator(end()); }
|
||||
template <class T, size_t Extent>
|
||||
inline constexpr auto span<T, Extent>::rend() const noexcept -> reverse_iterator { return AZStd::make_reverse_iterator(begin()); }
|
||||
|
||||
|
||||
template <class ElementType, size_t Extent>
|
||||
inline auto as_bytes(span<ElementType, Extent> s) noexcept
|
||||
-> span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
|
||||
{
|
||||
return span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>(
|
||||
reinterpret_cast<const byte*>(s.data()), s.size_bytes());
|
||||
}
|
||||
|
||||
|
||||
template <class ElementType, size_t Extent>
|
||||
inline auto as_writable_bytes(span<ElementType, Extent> s) noexcept
|
||||
-> enable_if_t<!is_const_v<ElementType>, span<byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>>
|
||||
{
|
||||
return span<byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>(
|
||||
reinterpret_cast<byte*>(s.data()), s.size_bytes());
|
||||
}
|
||||
} // namespace AZStd
|
||||
|
||||
@@ -7,22 +7,19 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/concepts/concepts.h>
|
||||
#include <AzCore/std/iterator.h>
|
||||
#include <AzCore/std/typetraits/integral_constant.h>
|
||||
#include <AzCore/std/typetraits/is_array.h>
|
||||
#include <AzCore/std/typetraits/is_assignable.h>
|
||||
#include <AzCore/std/typetraits/is_constructible.h>
|
||||
#include <AzCore/std/typetraits/is_destructible.h>
|
||||
#include <AzCore/std/typetraits/is_function.h>
|
||||
#include <AzCore/std/typetraits/is_trivially_copyable.h>
|
||||
#include <AzCore/std/typetraits/is_void.h>
|
||||
#include <AzCore/std/utils.h> // AZStd::addressof
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// alias std::pointer_traits into the AZStd::namespace
|
||||
using std::pointer_traits;
|
||||
|
||||
//! Bring the names of uninitialized_default_construct and
|
||||
//! uninitialized_default_construct_n into the AZStd namespace
|
||||
using std::uninitialized_default_construct;
|
||||
@@ -34,42 +31,6 @@ namespace AZStd
|
||||
using std::uninitialized_value_construct_n;
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
template <typename T, typename = void>
|
||||
constexpr bool pointer_traits_has_to_address_v = false;
|
||||
template <typename T>
|
||||
constexpr bool pointer_traits_has_to_address_v<T, AZStd::void_t<decltype(AZStd::pointer_traits<T>::to_address(declval<const T&>()))>> = true;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
//! Implements the C++20 to_address function
|
||||
//! This obtains the address represented by ptr without forming a reference
|
||||
//! to the pointee type
|
||||
template <typename T>
|
||||
constexpr T* to_address(T* ptr) noexcept
|
||||
{
|
||||
static_assert(!AZStd::is_function_v<T>, "Invoking to address on a function pointer is not allowed");
|
||||
return ptr;
|
||||
}
|
||||
//! Fancy pointer overload which delegates to using a specialization of pointer_traits<T>::to_address
|
||||
//! if that is a well-formed expression, otherwise it returns ptr->operator->()
|
||||
//! For example invoking `to_address(AZStd::reverse_iterator<const char*>(char_ptr))`
|
||||
//! Returns an element of type const char*
|
||||
template <typename T>
|
||||
constexpr auto to_address(const T& ptr) noexcept
|
||||
{
|
||||
if constexpr (AZStd::Internal::pointer_traits_has_to_address_v<T>)
|
||||
{
|
||||
return pointer_traits<T>::to_address(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return AZStd::to_address(ptr.operator->());
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
/**
|
||||
@@ -81,7 +42,7 @@ namespace AZStd::Internal
|
||||
/**
|
||||
* Type has trivial destructor. We don't call it.
|
||||
*/
|
||||
template <class InputIterator, class ValueType = typename iterator_traits<InputIterator>::value_type, bool = is_trivially_destructible_v<ValueType>>
|
||||
template <class InputIterator, class ValueType = iter_value_t<InputIterator>, bool = is_trivially_destructible_v<ValueType>>
|
||||
struct destroy
|
||||
{
|
||||
static constexpr void range(InputIterator first, InputIterator last) { (void)first; (void)last; }
|
||||
@@ -163,7 +124,7 @@ namespace AZStd::Internal
|
||||
* Default object construction.
|
||||
*/
|
||||
// placement new isn't a core constant expression therefore it cannot be used in a constexpr function
|
||||
template<class InputIterator, class ValueType = typename iterator_traits<InputIterator>::value_type,
|
||||
template<class InputIterator, class ValueType = iter_value_t<InputIterator>,
|
||||
bool = is_trivially_constructible_v<ValueType>>
|
||||
struct construct
|
||||
{
|
||||
@@ -242,93 +203,125 @@ namespace AZStd::Internal
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Sequence copy. If we use optimized version we use memcpy.
|
||||
/**
|
||||
* Helper class to determine if we have apply fast copy. There are 2 conditions
|
||||
* Class to determine if we have apply fast copy. There are 2 conditions
|
||||
* - trivial copy ctor.
|
||||
* - all iterators satisfy the C++20 are contiguous iterator concept: pointers or iterator classes with
|
||||
* the iterator_concept typedef set to contiguous_iterator_tag
|
||||
* - all iterators satisfy the C++20 are contiguous iterator concept
|
||||
*/
|
||||
template<class Out, class = void>
|
||||
constexpr bool indirectly_trivially_copyable = false;
|
||||
template<class Out>
|
||||
constexpr bool indirectly_trivially_copyable<Out,
|
||||
enable_if_t<indirectly_readable<Out>>> = is_trivially_copyable_v<iter_value_t<Out>>;
|
||||
|
||||
template<class InputIterator, class ResultIterator>
|
||||
struct is_fast_copy_helper
|
||||
{
|
||||
using value_type = typename iterator_traits<ResultIterator>::value_type;
|
||||
static constexpr bool value = AZStd::is_trivially_copyable_v<value_type>
|
||||
&& Internal::satisfies_contiguous_iterator_concept_v<InputIterator>
|
||||
&& Internal::satisfies_contiguous_iterator_concept_v<ResultIterator>;
|
||||
};
|
||||
using is_fast_copy = bool_constant<indirectly_trivially_copyable<ResultIterator>
|
||||
&& contiguous_iterator<InputIterator>
|
||||
&& contiguous_iterator<ResultIterator>
|
||||
>;
|
||||
|
||||
// Use this trait to to determine copy mode, based on the iterator category and object copy properties,
|
||||
// Use it when when you call uninitialized_copy, Internal::copy, Internal::move, etc.
|
||||
template< typename InputIterator, typename ResultIterator >
|
||||
struct is_fast_copy
|
||||
: public ::AZStd::integral_constant<bool, ::AZStd::Internal::is_fast_copy_helper<InputIterator, ResultIterator>::value> {};
|
||||
template<class InputIterator, class ResultIterator>
|
||||
constexpr bool is_fast_copy_v = is_fast_copy<InputIterator, ResultIterator>::value;
|
||||
|
||||
|
||||
// is_fast_copy argument is no longer used.
|
||||
template <class InputIterator, class ForwardIterator>
|
||||
constexpr ForwardIterator copy(const InputIterator& first, const InputIterator& last, ForwardIterator result, const false_type& /* is_fast_copy<InputIterator,ForwardIterator>() */)
|
||||
constexpr ForwardIterator copy(InputIterator first, InputIterator last, ForwardIterator result, bool)
|
||||
{
|
||||
InputIterator iter(first);
|
||||
for (; iter != last; ++result, ++iter)
|
||||
if constexpr (is_fast_copy_v<InputIterator, ForwardIterator>)
|
||||
{
|
||||
*result = *iter;
|
||||
}
|
||||
// Specialized copy for contiguous iterators which are trivially copyable
|
||||
size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
#if az_has_builtin_memcpy
|
||||
static_assert(sizeof(iter_value_t<InputIterator>) == sizeof(iter_value_t<ForwardIterator>), "Size of value types must match for a trivial copy");
|
||||
__builtin_memcpy(to_address(result), to_address(first), numElements * sizeof(iter_value_t<InputIterator>));
|
||||
#else
|
||||
if (az_builtin_is_constant_evaluated())
|
||||
{
|
||||
for (; first != last; ++result, ++first)
|
||||
{
|
||||
*result = *first;
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(sizeof(iter_value_t<InputIterator>) == sizeof(iter_value_t<ForwardIterator>), "Size of value types must match for a trivial copy");
|
||||
AZ_Assert((static_cast<const void*>(&*result) < static_cast<const void*>(&*first))
|
||||
|| (static_cast<const void*>(&*result) >= static_cast<const void*>(&*first + numElements)),
|
||||
"AZStd::copy memory overlaps use AZStd::copy_backward!");
|
||||
::memcpy(to_address(result), to_address(first), numElements * sizeof(iter_value_t<InputIterator>));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return result + numElements;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (; first != last; ++result, ++first)
|
||||
{
|
||||
*result = *first;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Specialized copy for contiguous iterators (pointers) and trivial copy type.
|
||||
// This overload cannot be constexpr until builtin_memcpy is added to MSVC compilers
|
||||
template <class InputIterator, class ForwardIterator>
|
||||
inline ForwardIterator copy(const InputIterator& first, const InputIterator& last, ForwardIterator result, const true_type& /* is_fast_copy<InputIterator,ForwardIterator>() */)
|
||||
{
|
||||
// \todo Make sure memory ranges don't overlap, otherwise people should use move and move_backward.
|
||||
static_assert(sizeof(typename iterator_traits<InputIterator>::value_type) == sizeof(typename iterator_traits<ForwardIterator>::value_type), "Size of value types must match for a trivial copy");
|
||||
AZStd::size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
AZ_Assert((static_cast<const void*>(&*result) < static_cast<const void*>(&*first)) || (static_cast<const void*>(&*result) >= static_cast<const void*>(&*first + numElements)), "AZStd::copy memory overlaps use AZStd::copy_backward!");
|
||||
AZ_Assert((static_cast<const void*>(&*result + numElements) <= static_cast<const void*>(&*first)) || (static_cast<const void*>(&*result + numElements) > static_cast<const void*>(&*first + numElements)), "AZStd::copy memory overlaps use AZStd::copy_backward!");
|
||||
/*AZSTD_STL::*/ memcpy(&*result, &*first, numElements * sizeof(typename iterator_traits<InputIterator>::value_type));
|
||||
}
|
||||
return result + numElements;
|
||||
}
|
||||
|
||||
// Copy backward.
|
||||
template <class BidirectionalIterator1, class BidirectionalIterator2>
|
||||
constexpr BidirectionalIterator2 copy_backward(const BidirectionalIterator1& first, const BidirectionalIterator1& last, BidirectionalIterator2 result, const false_type& /* is_fast_copy<BidirectionalIterator1,BidirectionalIterator2>() */)
|
||||
constexpr BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result, bool)
|
||||
{
|
||||
BidirectionalIterator1 iter(last);
|
||||
while (first != iter)
|
||||
if constexpr (is_fast_copy_v<BidirectionalIterator1, BidirectionalIterator2>)
|
||||
{
|
||||
*--result = *--iter;
|
||||
// Specialized copy for contiguous iterators which are trivially copyable
|
||||
size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
#if az_has_builtin_memmove
|
||||
static_assert(sizeof(iter_value_t<BidirectionalIterator1>) == sizeof(iter_value_t<BidirectionalIterator2>), "Size of value types must match for a trivial copy");
|
||||
result -= numElements;
|
||||
__builtin_memmove(to_address(result), to_address(first), numElements * sizeof(iter_value_t<BidirectionalIterator1>));
|
||||
#else
|
||||
if (az_builtin_is_constant_evaluated())
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
*--result = *--last;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(sizeof(iter_value_t<BidirectionalIterator1>) == sizeof(iter_value_t<BidirectionalIterator2>), "Size of value types must match for a trivial copy");
|
||||
result -= numElements;
|
||||
AZ_Assert(((&*result + numElements) <= &*first) || ((&*result + numElements) > (&*first + numElements)), "AZStd::copy_backward memory overlaps use AZStd::copy!");
|
||||
::memmove(&*result, &*first, numElements * sizeof(iter_value_t<BidirectionalIterator1>));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Specialized copy for contiguous iterators (pointers) and trivial copy type.
|
||||
// This overload cannot be constexpr until builtin_memcpy is added to MSVC compilers
|
||||
template <class BidirectionalIterator1, class BidirectionalIterator2>
|
||||
inline BidirectionalIterator2 copy_backward(const BidirectionalIterator1& first, const BidirectionalIterator1& last, BidirectionalIterator2 result, const true_type& /* is_fast_copy<BidirectionalIterator1,BidirectionalIterator2>() */)
|
||||
{
|
||||
// \todo Make sure memory ranges don't overlap, otherwise people should use move and move_backward.
|
||||
static_assert(sizeof(typename iterator_traits<BidirectionalIterator1>::value_type) == sizeof(typename iterator_traits<BidirectionalIterator2>::value_type), "Size of value types must match for a trivial copy");
|
||||
AZStd::size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
else
|
||||
{
|
||||
result -= numElements;
|
||||
AZ_Assert((&*result < &*first) || (&*result >= (&*first + numElements)), "AZStd::copy_backward memory overlaps use AZStd::copy!");
|
||||
AZ_Assert(((&*result + numElements) <= &*first) || ((&*result + numElements) > (&*first + numElements)), "AZStd::copy_backward memory overlaps use AZStd::copy!");
|
||||
/*AZSTD_STL::*/ memcpy(&*result, &*first, numElements * sizeof(typename iterator_traits<BidirectionalIterator1>::value_type));
|
||||
while (first != last)
|
||||
{
|
||||
*--result = *--last;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class BidirectionalIterator1, class ForwardIterator>
|
||||
constexpr ForwardIterator reverse_copy(const BidirectionalIterator1& first, const BidirectionalIterator1& last, ForwardIterator dest)
|
||||
constexpr ForwardIterator reverse_copy(BidirectionalIterator1 first, BidirectionalIterator1 last, ForwardIterator dest)
|
||||
{
|
||||
BidirectionalIterator1 iter(last);
|
||||
while (iter != first)
|
||||
while (last != first)
|
||||
{
|
||||
*(dest++) = *(--iter);
|
||||
*(dest++) = *(--last);
|
||||
}
|
||||
|
||||
return dest;
|
||||
@@ -342,143 +335,209 @@ namespace AZStd
|
||||
* Specialized algorithms 20.4.4. We extend that by adding faster specialized versions when we have trivial assign type.
|
||||
*/
|
||||
template <class InputIterator, class ForwardIterator>
|
||||
constexpr ForwardIterator uninitialized_copy(const InputIterator& first, const InputIterator& last, ForwardIterator result, const false_type& /* is_fast_copy<InputIterator,ForwardIterator>() */)
|
||||
constexpr ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result, bool)
|
||||
{
|
||||
InputIterator iter(first);
|
||||
for (; iter != last; ++result, ++iter)
|
||||
// Specialized copy for contiguous iterators which are trivially copyable
|
||||
if constexpr (Internal::is_fast_copy_v<InputIterator, ForwardIterator>)
|
||||
{
|
||||
::new (static_cast<void*>(&*result)) typename iterator_traits<ForwardIterator>::value_type(*iter);
|
||||
}
|
||||
size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
#if az_has_builtin_memcpy
|
||||
static_assert(sizeof(iter_value_t<InputIterator>) == sizeof(iter_value_t<ForwardIterator>), "Value type sizes must match for a trivial copy");
|
||||
__builtin_memcpy(to_address(result), to_address(first), numElements * sizeof(iter_value_t<InputIterator>));
|
||||
#else
|
||||
if (az_builtin_is_constant_evaluated())
|
||||
{
|
||||
for (; first != last; ++result, ++first)
|
||||
{
|
||||
construct_at(static_cast<iter_value_t<ForwardIterator>*>(to_address(result)), *first);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(sizeof(iter_value_t<InputIterator>) == sizeof(iter_value_t<ForwardIterator>), "Value type sizes must match for a trivial copy");
|
||||
::memcpy(to_address(result), to_address(first), numElements * sizeof(iter_value_t<InputIterator>));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return result + numElements;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (; first != last; ++result, ++first)
|
||||
{
|
||||
construct_at(static_cast<iter_value_t<ForwardIterator>*>(to_address(result)), *first);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Specialized copy for contiguous iterators and trivial copy type.
|
||||
// This overload cannot be constexpr until builtin_memcpy is added to MSVC compilers
|
||||
template <class InputIterator, class ForwardIterator>
|
||||
inline ForwardIterator uninitialized_copy(const InputIterator& first, const InputIterator& last, ForwardIterator result, const true_type& /* is_fast_copy<InputIterator,ForwardIterator>() */)
|
||||
{
|
||||
static_assert(sizeof(typename iterator_traits<InputIterator>::value_type) == sizeof(typename iterator_traits<ForwardIterator>::value_type), "Value type sizes must match for a trivial copy");
|
||||
AZStd::size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
/*AZSTD_STL::*/
|
||||
memcpy(&*result, &*first, numElements * sizeof(typename iterator_traits<InputIterator>::value_type));
|
||||
}
|
||||
return result + numElements;
|
||||
}
|
||||
|
||||
template <class InputIterator, class ForwardIterator>
|
||||
constexpr ForwardIterator uninitialized_copy(const InputIterator& first, const InputIterator& last, ForwardIterator result)
|
||||
constexpr ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result)
|
||||
{
|
||||
return uninitialized_copy(first, last, result, Internal::is_fast_copy<InputIterator, ForwardIterator>());
|
||||
return uninitialized_copy(first, last, result, {});
|
||||
}
|
||||
|
||||
// 25.3.1 Copy
|
||||
template<class InputIterator, class OutputIterator>
|
||||
constexpr OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)
|
||||
{
|
||||
return AZStd::Internal::copy(first, last, result, AZStd::Internal::is_fast_copy<InputIterator, OutputIterator>());
|
||||
return Internal::copy(first, last, result, {});
|
||||
}
|
||||
|
||||
template <class BidirectionalIterator, class OutputIterator>
|
||||
constexpr OutputIterator reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator dest)
|
||||
{
|
||||
return AZStd::Internal::reverse_copy(first, last, dest);
|
||||
return Internal::reverse_copy(first, last, dest);
|
||||
}
|
||||
|
||||
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
||||
BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result)
|
||||
{
|
||||
return AZStd::Internal::copy_backward(first, last, result, AZStd::Internal::is_fast_copy<BidirectionalIterator1, BidirectionalIterator2>());
|
||||
return Internal::copy_backward(first, last, result, {});
|
||||
}
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Sequence move. If we use optimized version we use memmove.
|
||||
// Sequence move
|
||||
template <class InputIterator, class ForwardIterator>
|
||||
constexpr ForwardIterator move(const InputIterator& first, const InputIterator& last, ForwardIterator result, const false_type& /* is_fast_copy<InputIterator,ForwardIterator>() */)
|
||||
constexpr ForwardIterator move(InputIterator first, InputIterator last, ForwardIterator result, bool)
|
||||
{
|
||||
InputIterator iter(first);
|
||||
for (; iter != last; ++result, ++iter)
|
||||
// Specialized copy for contiguous iterators which are trivially copyable
|
||||
if constexpr (is_fast_copy_v<InputIterator, ForwardIterator>)
|
||||
{
|
||||
*result = AZStd::move(*iter);
|
||||
size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
#if az_has_builtin_memcpy
|
||||
static_assert(sizeof(iter_value_t<InputIterator>) == sizeof(iter_value_t<ForwardIterator>), "Size of value types must match for a trivial copy");
|
||||
__builtin_memcpy(to_address(result), to_address(first), numElements * sizeof(iter_value_t<InputIterator>));
|
||||
#else
|
||||
if (az_builtin_is_constant_evaluated())
|
||||
{
|
||||
for (; first != last; ++result, ++first)
|
||||
{
|
||||
*result = ::AZStd::move(*first);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(sizeof(iter_value_t<InputIterator>) == sizeof(iter_value_t<ForwardIterator>), "Size of value types must match for a trivial copy");
|
||||
AZ_Assert((static_cast<const void*>(&*result) < static_cast<const void*>(&*first))
|
||||
|| (static_cast<const void*>(&*result) >= static_cast<const void*>(&*first + numElements)),
|
||||
"AZStd::move memory overlaps use AZStd::move_backward!");
|
||||
::memcpy(to_address(result), to_address(first), numElements * sizeof(iter_value_t<InputIterator>));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return result + numElements;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (; first != last; ++result, ++first)
|
||||
{
|
||||
*result = ::AZStd::move(*first);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Specialized copy for contiguous iterators (pointers) and trivial copy type.
|
||||
// This overload cannot be constexpr until builtin_memmove is added to MSVC compilers
|
||||
template <class InputIterator, class ForwardIterator>
|
||||
inline ForwardIterator move(const InputIterator& first, const InputIterator& last, ForwardIterator result, const true_type& /* is_fast_copy<InputIterator,ForwardIterator>() */)
|
||||
{
|
||||
static_assert(sizeof(typename iterator_traits<InputIterator>::value_type) == sizeof(typename iterator_traits<ForwardIterator>::value_type), "Size of value types must match for a trivial copy");
|
||||
AZStd::size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
/*AZSTD_STL::*/
|
||||
memmove(&*result, &*first, numElements * sizeof(typename iterator_traits<InputIterator>::value_type));
|
||||
}
|
||||
return result + numElements;
|
||||
}
|
||||
|
||||
// For generic iterators, move is the same as copy.
|
||||
template <class BidirectionalIterator1, class BidirectionalIterator2>
|
||||
constexpr BidirectionalIterator2 move_backward(const BidirectionalIterator1& first, const BidirectionalIterator1& last, BidirectionalIterator2 result, const false_type& /* is_fast_copy<BidirectionalIterator1,BidirectionalIterator2>() */)
|
||||
constexpr BidirectionalIterator2 move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result, bool)
|
||||
{
|
||||
BidirectionalIterator1 iter(last);
|
||||
while (first != iter)
|
||||
// Specialized copy for contiguous iterators which are trivially copyable
|
||||
if constexpr (is_fast_copy_v<BidirectionalIterator1, BidirectionalIterator1>)
|
||||
{
|
||||
*--result = AZStd::move(*--iter);
|
||||
size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
#if az_has_builtin_memmove
|
||||
static_assert(sizeof(iter_value_t<BidirectionalIterator1>) == sizeof(iter_value_t<BidirectionalIterator2>), "Size of value types must match for a trivial copy");
|
||||
result -= numElements;
|
||||
__builtin_memmove(to_address(result), to_address(first), numElements * sizeof(iter_value_t<BidirectionalIterator1>));
|
||||
#else
|
||||
if (az_builtin_is_constant_evaluated())
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
*--result = ::AZStd::move(*--last);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(sizeof(iter_value_t<BidirectionalIterator1>) == sizeof(iter_value_t<BidirectionalIterator2>), "Size of value types must match for a trivial copy");
|
||||
result -= numElements;
|
||||
AZ_Assert((static_cast<const void*>(&*result + numElements) <= static_cast<const void*>(&*first))
|
||||
|| (static_cast<const void*>(&*result + numElements) > static_cast<const void*>(&*first + numElements)),
|
||||
"AZStd::move_backward memory overlaps use AZStd::move!");
|
||||
::memmove(to_address(result), to_address(first), numElements * sizeof(iter_value_t<BidirectionalIterator1>));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Specialized copy for contiguous iterators (pointers) and trivial copy type.
|
||||
// This overload cannot be constexpr until builtin_memmove is added to MSVC compilers
|
||||
template <class BidirectionalIterator1, class BidirectionalIterator2>
|
||||
inline BidirectionalIterator2 move_backward(const BidirectionalIterator1& first, const BidirectionalIterator1& last, BidirectionalIterator2 result, const true_type& /* is_fast_copy<BidirectionalIterator1,BidirectionalIterator2>() */)
|
||||
{
|
||||
// \todo Make sure memory ranges don't overlap, otherwise people should use move and move_backward.
|
||||
static_assert(sizeof(typename iterator_traits<BidirectionalIterator1>::value_type) == sizeof(typename iterator_traits<BidirectionalIterator2>::value_type), "Size of value types must match for a trivial copy");
|
||||
AZStd::size_t numElements = last - first;
|
||||
result -= numElements;
|
||||
if (numElements > 0)
|
||||
else
|
||||
{
|
||||
/*AZSTD_STL::*/
|
||||
memmove(&*result, &*first, numElements * sizeof(typename iterator_traits<BidirectionalIterator1>::value_type));
|
||||
while (first != last)
|
||||
{
|
||||
*--result = ::AZStd::move(*--last);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class InputIterator, class ForwardIterator>
|
||||
constexpr ForwardIterator uninitialized_move(const InputIterator& first, const InputIterator& last, ForwardIterator result, const false_type& /* is_fast_copy<InputIterator,ForwardIterator>() */)
|
||||
constexpr ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result, bool)
|
||||
{
|
||||
InputIterator iter(first);
|
||||
|
||||
for (; iter != last; ++result, ++iter)
|
||||
// Specialized copy for contiguous iterators which are trivially copyable
|
||||
if constexpr (is_fast_copy_v<InputIterator, ForwardIterator>)
|
||||
{
|
||||
::new (static_cast<void*>(&*result)) typename iterator_traits<ForwardIterator>::value_type(AZStd::move(*iter));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// Specialized copy for contiguous iterators and trivial move type. (since the object is POD we will just perform a copy)
|
||||
// This overload cannot be constexpr until builtin_memcpy is added to MSVC compilers
|
||||
template <class InputIterator, class ForwardIterator>
|
||||
inline ForwardIterator uninitialized_move(const InputIterator& first, const InputIterator& last, ForwardIterator result, const true_type& /* is_fast_copy<InputIterator,ForwardIterator>() */)
|
||||
{
|
||||
static_assert(sizeof(typename iterator_traits<InputIterator>::value_type) == sizeof(typename iterator_traits<ForwardIterator>::value_type), "Value type sizes must match for a trivial copy");
|
||||
AZStd::size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
/*AZSTD_STL::*/
|
||||
memcpy(&*result, &*first, numElements * sizeof(typename iterator_traits<InputIterator>::value_type));
|
||||
}
|
||||
return result + numElements;
|
||||
}
|
||||
size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
#if az_has_builtin_memcpy
|
||||
static_assert(sizeof(iter_value_t<InputIterator>) == sizeof(iter_value_t<ForwardIterator>), "Value type sizes must match for a trivial copy");
|
||||
__builtin_memcpy(to_address(result), to_address(first), numElements * sizeof(iter_value_t<InputIterator>));
|
||||
#else
|
||||
if (az_builtin_is_constant_evaluated())
|
||||
{
|
||||
for (; first != last; ++result, ++first)
|
||||
{
|
||||
construct_at(static_cast<iter_value_t<ForwardIterator>*>(to_address(result)), ::AZStd::move(*first));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(sizeof(iter_value_t<InputIterator>) == sizeof(iter_value_t<ForwardIterator>), "Value type sizes must match for a trivial copy");
|
||||
::memcpy(to_address(result), to_address(first), numElements * sizeof(iter_value_t<InputIterator>));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return result + numElements;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (; first != last; ++result, ++first)
|
||||
{
|
||||
construct_at(static_cast<iter_value_t<ForwardIterator>*>(to_address(result)), ::AZStd::move(*first));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// end of sequence move.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
@@ -492,19 +551,19 @@ namespace AZStd
|
||||
template <typename InputIt, typename ForwardIt>
|
||||
ForwardIt uninitialized_move(InputIt first, InputIt last, ForwardIt result)
|
||||
{
|
||||
return AZStd::Internal::uninitialized_move(first, last, result, AZStd::Internal::is_fast_copy<InputIt, InputIt>{});
|
||||
return AZStd::Internal::uninitialized_move(first, last, result, {});
|
||||
}
|
||||
// 25.3.2 Move
|
||||
template<class InputIterator, class OutputIterator>
|
||||
OutputIterator move(InputIterator first, InputIterator last, OutputIterator result)
|
||||
{
|
||||
return AZStd::Internal::move(first, last, result, AZStd::Internal::is_fast_copy<InputIterator, OutputIterator>());
|
||||
return AZStd::Internal::move(first, last, result, {});
|
||||
}
|
||||
|
||||
template<class BidirectionalIterator1, class BidirectionalIterator2>
|
||||
BidirectionalIterator2 move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result)
|
||||
{
|
||||
return AZStd::Internal::move_backward(first, last, result, AZStd::Internal::is_fast_copy<BidirectionalIterator1, BidirectionalIterator2>());
|
||||
return AZStd::Internal::move_backward(first, last, result, {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,63 +575,77 @@ namespace AZStd::Internal
|
||||
* Helper class to determine if we have apply fast fill. There are 3 conditions
|
||||
* - trivial assign
|
||||
* - size of type == 1 (chars) to use memset
|
||||
* - contiguous iterators (pointers)
|
||||
* - contiguous iterators
|
||||
*/
|
||||
template<class Out, class = void>
|
||||
constexpr bool indirectly_copy_assignable = false;
|
||||
template<class Out>
|
||||
constexpr bool indirectly_copy_assignable<Out, enable_if_t<indirectly_readable<Out>>> =
|
||||
is_trivially_copy_assignable_v<iter_value_t<Out>> && sizeof(iter_value_t<Out>) == 1;
|
||||
|
||||
template<class Iterator>
|
||||
struct is_fast_fill_helper
|
||||
{
|
||||
using value_type = typename iterator_traits<Iterator>::value_type;
|
||||
constexpr static bool value = is_trivially_copy_assignable_v<value_type> && sizeof(value_type) == 1
|
||||
&& Internal::satisfies_contiguous_iterator_concept_v<Iterator>;
|
||||
};
|
||||
|
||||
// Use this trait to to determine fill mode, based on the iterator, value size, etc.
|
||||
// Use it when you call uninitialized_fill, uninitialized_fill_n, fill and fill_n.
|
||||
template< typename Iterator >
|
||||
struct is_fast_fill
|
||||
: public ::AZStd::integral_constant<bool, ::AZStd::Internal::is_fast_fill_helper<Iterator>::value>
|
||||
{};
|
||||
using is_fast_fill = bool_constant<indirectly_copy_assignable<Iterator> && contiguous_iterator<Iterator>>;
|
||||
template<class Iterator>
|
||||
constexpr bool is_fast_fill_v = is_fast_fill<Iterator>::value;
|
||||
|
||||
// The fast fill trait is no longer used
|
||||
// It is detected using C++20 concepts now
|
||||
template <class ForwardIterator, class T>
|
||||
constexpr void fill(const ForwardIterator& first, const ForwardIterator& last, const T& value, const false_type& /* is_fast_fill<ForwardIterator>() */)
|
||||
constexpr void fill(ForwardIterator first, ForwardIterator last, const T& value, bool)
|
||||
{
|
||||
ForwardIterator iter(first);
|
||||
for (; iter != last; ++iter)
|
||||
if constexpr (is_fast_fill_v<ForwardIterator>)
|
||||
{
|
||||
*iter = value;
|
||||
size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
if (az_builtin_is_constant_evaluated())
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
{
|
||||
*first = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
::memset(to_address(first), reinterpret_cast<const unsigned char&>(value), numElements);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Specialized version for character types where memset can be used
|
||||
// This overload cannot be constexpr until builtin_memset is added to MSVC compilers
|
||||
template <class ForwardIterator, class T>
|
||||
inline void fill(const ForwardIterator& first, const ForwardIterator& last, const T& value, const true_type& /* is_fast_fill<ForwardIterator>() */)
|
||||
{
|
||||
AZStd::size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
else
|
||||
{
|
||||
/*AZSTD_STL::*/
|
||||
memset((void*)&*first, *reinterpret_cast<const unsigned char*>(&value), numElements);
|
||||
for (; first != last; ++first)
|
||||
{
|
||||
*first = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ForwardIterator, class Size, class T>
|
||||
constexpr void fill_n(ForwardIterator first, Size numElements, const T& value, const false_type& /* is_fast_fill<ForwardIterator>() */)
|
||||
constexpr void fill_n(ForwardIterator first, Size numElements, const T& value, bool)
|
||||
{
|
||||
for (; numElements--; ++first)
|
||||
if constexpr (is_fast_fill_v<ForwardIterator>)
|
||||
{
|
||||
*first = value;
|
||||
if (numElements)
|
||||
{
|
||||
if (az_builtin_is_constant_evaluated())
|
||||
{
|
||||
for (; numElements--; ++first)
|
||||
{
|
||||
*first = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
::memset(to_address(first), reinterpret_cast<const unsigned char&>(value), numElements);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Specialized version for character types where memset can be used to perform the fill
|
||||
// This overload cannot be constexpr until builtin_memset is added to MSVC compilers
|
||||
template <class ForwardIterator, class Size, class T>
|
||||
inline void fill_n(ForwardIterator first, Size numElements, const T& value, const true_type& /* is_fast_fill<ForwardIterator>() */)
|
||||
{
|
||||
if (numElements > 0)
|
||||
else
|
||||
{
|
||||
/*AZSTD_STL::*/
|
||||
memset(&*first, *reinterpret_cast<const unsigned char*>(&value), numElements);
|
||||
for (; numElements--; ++first)
|
||||
{
|
||||
*first = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -580,78 +653,85 @@ namespace AZStd::Internal
|
||||
namespace AZStd
|
||||
{
|
||||
template <class ForwardIterator, class T>
|
||||
constexpr void fill(const ForwardIterator& first, const ForwardIterator& last, const T& value)
|
||||
constexpr void fill(ForwardIterator first, ForwardIterator last, const T& value)
|
||||
{
|
||||
Internal::fill(first, last, value, Internal::is_fast_fill<ForwardIterator>());
|
||||
Internal::fill(first, last, value, {});
|
||||
}
|
||||
|
||||
|
||||
template <class ForwardIterator, class Size, class T>
|
||||
constexpr void fill_n(ForwardIterator first, Size numElements, const T& value)
|
||||
{
|
||||
Internal::fill_n(first, numElements, value, Internal::is_fast_fill<ForwardIterator>());
|
||||
Internal::fill_n(first, numElements, value, {});
|
||||
}
|
||||
|
||||
template <class ForwardIterator, class T>
|
||||
constexpr void uninitialized_fill(const ForwardIterator& first, const ForwardIterator& last, const T& value, const false_type& /* is_fast_fill<ForwardIterator>() */)
|
||||
constexpr void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& value, bool)
|
||||
{
|
||||
ForwardIterator iter(first);
|
||||
for (; iter != last; ++iter)
|
||||
if constexpr (Internal::is_fast_fill_v<ForwardIterator>)
|
||||
{
|
||||
::new (static_cast<void*>(&*iter)) typename iterator_traits<ForwardIterator>::value_type(value);
|
||||
size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
{
|
||||
if (az_builtin_is_constant_evaluated())
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
{
|
||||
construct_at(static_cast<iter_value_t<ForwardIterator>*>(to_address(first)), value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
::memset(to_address(first), reinterpret_cast<const unsigned char&>(value), numElements);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Specialized overload for types which meet the following criteria.
|
||||
// 1. Has it's iterator_traits<T>::iterator_concept type set to to contiguous_iterator_tag
|
||||
// 2. Is trivially assignable
|
||||
// 3. Has a sizeof(T) == 1
|
||||
// In such a case memset can be used to fill in the data
|
||||
// This overload cannot be constexpr until builtin_memset is added to MSVC compilers
|
||||
template <class ForwardIterator, class T>
|
||||
inline void uninitialized_fill(const ForwardIterator& first, const ForwardIterator& last, const T& value, const true_type& /* is_fast_fill<ForwardIterator>() */)
|
||||
{
|
||||
AZStd::size_t numElements = last - first;
|
||||
if (numElements > 0)
|
||||
else
|
||||
{
|
||||
/*AZSTD_STL::*/
|
||||
memset(&*first, *reinterpret_cast<const unsigned char*>(&value), numElements);
|
||||
for (; first != last; ++first)
|
||||
{
|
||||
construct_at(static_cast<iter_value_t<ForwardIterator>*>(to_address(first)), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ForwardIterator, class Size, class T>
|
||||
constexpr void uninitialized_fill(ForwardIterator first, Size numElements, const T& value)
|
||||
{
|
||||
return uninitialized_fill(first, numElements, value, Internal::is_fast_fill<ForwardIterator>());
|
||||
return uninitialized_fill(first, numElements, value, {});
|
||||
}
|
||||
|
||||
template <class ForwardIterator, class Size, class T>
|
||||
constexpr void uninitialized_fill_n(ForwardIterator first, Size numElements, const T& value, const false_type& /* is_fast_fill<ForwardIterator>() */)
|
||||
constexpr void uninitialized_fill_n(ForwardIterator first, Size numElements, const T& value, bool)
|
||||
{
|
||||
for (; numElements--; ++first)
|
||||
if constexpr (Internal::is_fast_fill_v<ForwardIterator>)
|
||||
{
|
||||
::new (static_cast<void*>(&*first)) typename iterator_traits<ForwardIterator>::value_type(value);
|
||||
if (numElements > 0)
|
||||
{
|
||||
if (az_builtin_is_constant_evaluated())
|
||||
{
|
||||
for (; numElements--; ++first)
|
||||
{
|
||||
construct_at(static_cast<iter_value_t<ForwardIterator>*>(to_address(first)), value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
::memset(to_address(first), reinterpret_cast<const unsigned char&>(value), numElements);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Specialized overload for types which meet the following criteria.
|
||||
// 1. Has it's iterator_traits<T>::iterator_concept type set to to contiguous_iterator_tag
|
||||
// 2. Is trivially assignable
|
||||
// 3. Has a sizeof(T) == 1
|
||||
// In such a case memset can be used to fill in the data
|
||||
template <class ForwardIterator, class Size, class T>
|
||||
inline void uninitialized_fill_n(ForwardIterator first, Size numElements, const T& value, const true_type& /* is_fast_fill<ForwardIterator>() */)
|
||||
{
|
||||
if (numElements)
|
||||
else
|
||||
{
|
||||
/*AZSTD_STL::*/
|
||||
memset(&*first, *reinterpret_cast<const unsigned char*>(&value), numElements);
|
||||
for (; numElements--; ++first)
|
||||
{
|
||||
construct_at(static_cast<iter_value_t<ForwardIterator>*>(to_address(first)), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ForwardIterator, class Size, class T>
|
||||
constexpr void uninitialized_fill_n(ForwardIterator first, Size numElements, const T& value)
|
||||
{
|
||||
return uninitialized_fill_n(first, numElements, value, Internal::is_fast_fill<ForwardIterator>());
|
||||
return uninitialized_fill_n(first, numElements, value, {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +38,12 @@ namespace AZStd
|
||||
{
|
||||
return Internal::INVOKE(Internal::InvokeTraits::forward<F>(f), Internal::InvokeTraits::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// models the invocable concept
|
||||
template <class F, class... Args>
|
||||
/*concept*/ constexpr bool invocable = is_invocable_v<F, Args...>;
|
||||
|
||||
// models the regular_invocable concept
|
||||
template <class F, class... Args>
|
||||
/*concept*/ constexpr bool regular_invocable = invocable<F, Args...>;
|
||||
}
|
||||
|
||||
@@ -8,19 +8,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/base.h>
|
||||
#include <AzCore/std/typetraits/integral_constant.h>
|
||||
#include <AzCore/std/typetraits/void_t.h>
|
||||
#include <AzCore/std/typetraits/is_convertible.h>
|
||||
|
||||
#include <AzCore/std/typetraits/is_base_of.h> // use by ConstIteratorCast
|
||||
#include <AzCore/std/iterator/iterator_primitives.h>
|
||||
#include <AzCore/std/typetraits/is_base_of.h>
|
||||
#include <AzCore/std/typetraits/is_convertible.h>
|
||||
#include <AzCore/std/typetraits/remove_cv.h>
|
||||
#include <AzCore/std/typetraits/is_reference.h>
|
||||
#include <AzCore/std/typetraits/void_t.h>
|
||||
#include <AzCore/std/utils.h>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// Everything unless specified is based on C++ standard 24 (lib.iterators).
|
||||
// Everything unless specified is based on C++ standard 20 (lib.iterators).
|
||||
|
||||
/// Identifying tag for input iterators.
|
||||
using input_iterator_tag = std::input_iterator_tag;
|
||||
@@ -51,16 +51,6 @@ namespace AZStd::Internal
|
||||
typename Iterator::reference>
|
||||
> = true;
|
||||
|
||||
|
||||
template <typename Iterator, typename = void>
|
||||
inline constexpr bool has_iterator_category_v = false;
|
||||
template <typename Iterator>
|
||||
inline constexpr bool has_iterator_category_v<Iterator, AZStd::void_t<typename Iterator::iterator_category>> = true;
|
||||
template <typename Iterator, typename = void>
|
||||
inline constexpr bool has_iterator_concept_v = false;
|
||||
template <typename Iterator>
|
||||
inline constexpr bool has_iterator_concept_v<Iterator, AZStd::void_t<typename Iterator::iterator_concept>> = true;
|
||||
|
||||
// Iterator iterator_category alias must be one of the iterator category tags
|
||||
template <typename Iterator, bool>
|
||||
struct iterator_traits_category_tags
|
||||
@@ -98,6 +88,8 @@ namespace AZStd
|
||||
struct iterator_traits
|
||||
: Internal::iterator_traits_type_aliases<Iterator, Internal::has_iterator_type_aliases_v<Iterator>>
|
||||
{
|
||||
// Internal type alias meant to indicate that this is the primary template
|
||||
using _is_primary_template = iterator_traits;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -114,45 +106,6 @@ namespace AZStd
|
||||
using iterator_category = random_access_iterator_tag;
|
||||
using iterator_concept = contiguous_iterator_tag;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
// iterator_category tag testers
|
||||
template <typename Iterator, typename Category, bool = has_iterator_category_v<iterator_traits<Iterator>>>
|
||||
inline constexpr bool has_iterator_category_convertible_to_v = false;
|
||||
template <typename Iterator, typename Category>
|
||||
inline constexpr bool has_iterator_category_convertible_to_v<Iterator, Category, true> = is_convertible_v<typename iterator_traits<Iterator>::iterator_category, Category>;
|
||||
|
||||
template <typename Iterator>
|
||||
inline constexpr bool is_input_iterator_v = has_iterator_category_convertible_to_v<Iterator, input_iterator_tag>;
|
||||
|
||||
template <typename Iterator>
|
||||
inline constexpr bool is_forward_iterator_v = has_iterator_category_convertible_to_v<Iterator, forward_iterator_tag>;
|
||||
|
||||
template <typename Iterator>
|
||||
inline constexpr bool is_bidirectional_iterator_v = has_iterator_category_convertible_to_v<Iterator, bidirectional_iterator_tag>;
|
||||
|
||||
template <typename Iterator>
|
||||
inline constexpr bool is_random_access_iterator_v = has_iterator_category_convertible_to_v<Iterator, random_access_iterator_tag>;
|
||||
|
||||
template <typename Iterator>
|
||||
inline constexpr bool is_contiguous_iterator_v = has_iterator_category_convertible_to_v<Iterator, contiguous_iterator_tag>;
|
||||
|
||||
template <typename Iterator>
|
||||
inline constexpr bool is_exactly_input_iterator_v = has_iterator_category_convertible_to_v<Iterator, input_iterator_tag> && !has_iterator_category_convertible_to_v<Iterator, forward_iterator_tag>;
|
||||
|
||||
// iterator concept testers
|
||||
template <typename Derived, typename Base>
|
||||
inline constexpr bool derived_from = is_base_of_v<Base, Derived> && is_convertible_v<const volatile Derived*, const volatile Base*>;
|
||||
|
||||
template <typename Iterator, typename Concept, bool = has_iterator_concept_v<iterator_traits<Iterator>>>
|
||||
inline constexpr bool satisfies_iterator_concept = false;
|
||||
template <typename Iterator, typename Concept>
|
||||
inline constexpr bool satisfies_iterator_concept<Iterator, Concept, true> = derived_from<typename iterator_traits<Iterator>::iterator_concept, Concept>;
|
||||
template <typename Iterator>
|
||||
inline constexpr bool satisfies_contiguous_iterator_concept_v = satisfies_iterator_concept<Iterator, contiguous_iterator_tag>;
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/base.h>
|
||||
|
||||
#include <AzCore/std/ranges/iter_move.h>
|
||||
#include <AzCore/std/typetraits/common_reference.h>
|
||||
#include <AzCore/std/typetraits/conditional.h>
|
||||
#include <AzCore/std/typetraits/is_array.h>
|
||||
#include <AzCore/std/typetraits/is_class.h>
|
||||
#include <AzCore/std/typetraits/is_enum.h>
|
||||
#include <AzCore/std/typetraits/is_integral.h>
|
||||
#include <AzCore/std/typetraits/is_object.h>
|
||||
#include <AzCore/std/typetraits/is_lvalue_reference.h>
|
||||
#include <AzCore/std/typetraits/is_rvalue_reference.h>
|
||||
#include <AzCore/std/typetraits/is_signed.h>
|
||||
#include <AzCore/std/typetraits/is_void.h>
|
||||
#include <AzCore/std/typetraits/remove_extent.h>
|
||||
#include <AzCore/std/typetraits/void_t.h>
|
||||
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// Bring in std utility functions into AZStd namespace
|
||||
using std::forward;
|
||||
|
||||
// forward declare iterator_traits to avoid iterator.h include
|
||||
template <class I>
|
||||
struct iterator_traits;
|
||||
}
|
||||
|
||||
// C++20 range traits for iteratable types
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
// Models the can-reference concept which isn't available until C++20
|
||||
// template <class T, class = void>
|
||||
template <class T>
|
||||
constexpr bool can_reference = true;
|
||||
template <>
|
||||
inline constexpr bool can_reference<void> = false;
|
||||
|
||||
// Models the dereferencable concept which isn't available until C++20
|
||||
template <class T, class = void>
|
||||
/*concept*/ constexpr bool dereferenceable = false;
|
||||
template <class T>
|
||||
constexpr bool dereferenceable<T, enable_if_t<can_reference<decltype(*declval<T>())>>> = true;
|
||||
|
||||
template <class T, class = void>
|
||||
constexpr bool is_primary_template_v = false;
|
||||
template <class T>
|
||||
constexpr bool is_primary_template_v<T, enable_if_t<is_same_v<T, typename T::_is_primary_template>>> = true;
|
||||
|
||||
// indirectly readable traits
|
||||
template <typename T, typename = void>
|
||||
constexpr bool has_value_type_v = false;
|
||||
template <typename T>
|
||||
constexpr bool has_value_type_v<T, void_t<typename T::value_type>> = true;
|
||||
template <typename T, typename = void>
|
||||
constexpr bool has_element_type_v = false;
|
||||
template <typename T>
|
||||
constexpr bool has_element_type_v<T, void_t<typename T::element_type>> = true;
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct object_type_value_requires {};
|
||||
template <typename T>
|
||||
struct object_type_value_requires<T, enable_if_t<is_object_v<T>>>
|
||||
{
|
||||
using value_type = remove_cv_t<T>;
|
||||
};
|
||||
template <typename T, typename = void>
|
||||
struct indirectly_readable_requires {};
|
||||
template <typename T>
|
||||
struct indirectly_readable_requires<T, enable_if_t<!is_primary_template_v<iterator_traits<T>>
|
||||
&& is_void_v<void_t<typename iterator_traits<T>::value_type>> >>
|
||||
{
|
||||
// iterator_traits has been been specialized
|
||||
using value_type = typename iterator_traits<T>::value_type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct indirectly_readable_requires<T, enable_if_t<is_primary_template_v<iterator_traits<T>>
|
||||
&& is_array_v<T>>>
|
||||
{
|
||||
using value_type = remove_cv_t<remove_extent_t<T>>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct indirectly_readable_requires<T, enable_if_t<is_primary_template_v<iterator_traits<T>>
|
||||
&& has_value_type_v<T> && !has_element_type_v<T>>>
|
||||
: object_type_value_requires<typename T::value_type> {};
|
||||
|
||||
template <typename T>
|
||||
struct indirectly_readable_requires<T, enable_if_t<is_primary_template_v<iterator_traits<T>>
|
||||
&& has_element_type_v<T> && !has_value_type_v<T>>>
|
||||
: object_type_value_requires<typename T::element_type> {};
|
||||
|
||||
template <typename T>
|
||||
struct indirectly_readable_requires<T, enable_if_t<is_primary_template_v<iterator_traits<T>>
|
||||
&& has_value_type_v<T>&& has_element_type_v<T>
|
||||
&& same_as<remove_cv_t<typename T::element_type>, remove_cv_t<typename T::value_type>> >>
|
||||
: object_type_value_requires<typename T::value_type> {};
|
||||
|
||||
// incrementable traits
|
||||
template <typename T, typename = void>
|
||||
constexpr bool has_difference_type_v = false;
|
||||
template <typename T>
|
||||
constexpr bool has_difference_type_v<T, void_t<typename T::difference_type>> = true;
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct object_type_difference_requires {};
|
||||
template <typename T>
|
||||
struct object_type_difference_requires<T, enable_if_t<is_object_v<T>>>
|
||||
{
|
||||
using difference_type = ptrdiff_t;
|
||||
};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct incrementable_requires {};
|
||||
// iterator_traits has been specialized
|
||||
template <typename T>
|
||||
struct incrementable_requires<T, enable_if_t<!is_primary_template_v<iterator_traits<T>>
|
||||
&& is_void_v<void_t<typename iterator_traits<T>::difference_type>> >>
|
||||
{
|
||||
using difference_type = typename iterator_traits<T>::difference_type;
|
||||
};
|
||||
template <typename T>
|
||||
struct incrementable_requires<T, enable_if_t<is_primary_template_v<iterator_traits<T>>
|
||||
&& has_difference_type_v<T>>>
|
||||
{
|
||||
using difference_type = typename T::difference_type;
|
||||
};
|
||||
template <typename T>
|
||||
struct incrementable_requires<T, enable_if_t<is_primary_template_v<iterator_traits<T>>
|
||||
&& !has_difference_type_v<T>
|
||||
&& integral<decltype(declval<T>() - declval<T>())> >>
|
||||
{
|
||||
using difference_type = make_signed_t<decltype(declval<T>() - declval<T>())>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// indirectly_readable_traits for iter_value_t
|
||||
template <typename T>
|
||||
struct indirectly_readable_traits
|
||||
: Internal::indirectly_readable_requires<T> {};
|
||||
template <typename T>
|
||||
struct indirectly_readable_traits<T*>
|
||||
: Internal::object_type_value_requires<T> {};
|
||||
template <typename T>
|
||||
struct indirectly_readable_traits<const T>
|
||||
: indirectly_readable_traits<T> {};
|
||||
|
||||
template <typename T>
|
||||
using iter_value_t = typename indirectly_readable_traits<remove_cvref_t<T>>::value_type;
|
||||
|
||||
template <typename T>
|
||||
using iter_reference_t = enable_if_t<Internal::dereferenceable<T>, decltype(*declval<T&>())>;
|
||||
|
||||
// incrementable_traits for iter_difference_t
|
||||
template <typename T>
|
||||
struct incrementable_traits
|
||||
: Internal::incrementable_requires<T> {};
|
||||
template <typename T>
|
||||
struct incrementable_traits<T*>
|
||||
: Internal::object_type_difference_requires<T> {};
|
||||
template <typename T>
|
||||
struct incrementable_traits<const T>
|
||||
: incrementable_traits<T> {};
|
||||
|
||||
template <typename T>
|
||||
using iter_difference_t = typename incrementable_traits<remove_cvref_t<T>>::difference_type;
|
||||
|
||||
template <typename T>
|
||||
using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>()));
|
||||
|
||||
namespace Internal
|
||||
{
|
||||
// model the indirectly readable concept
|
||||
template <class In, class = void>
|
||||
constexpr bool indirectly_readable_impl = false;
|
||||
|
||||
template <class In>
|
||||
constexpr bool indirectly_readable_impl<In, enable_if_t<same_as<decltype(*declval<In>()), iter_reference_t<In>>
|
||||
&& same_as<decltype(AZStd::ranges::iter_move(declval<In>())), iter_rvalue_reference_t<In>>
|
||||
&& common_reference_with<iter_reference_t<In>&&, iter_value_t<In>&>
|
||||
&& common_reference_with<iter_reference_t<In>&&, iter_rvalue_reference_t<In>&>
|
||||
&& common_reference_with<iter_rvalue_reference_t<In>&&, const iter_value_t<In>&>>> = true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using iter_common_reference_t = enable_if_t<Internal::indirectly_readable_impl<T>,
|
||||
common_reference_t<iter_reference_t<T>, iter_value_t<T>&>>;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/base.h>
|
||||
|
||||
#include <AzCore/std/typetraits/conditional.h>
|
||||
|
||||
#include <AzCore/std/typetraits/is_class.h>
|
||||
#include <AzCore/std/typetraits/is_enum.h>
|
||||
#include <AzCore/std/typetraits/is_lvalue_reference.h>
|
||||
#include <AzCore/std/typetraits/is_rvalue_reference.h>
|
||||
#include <AzCore/std/typetraits/remove_cvref.h>
|
||||
#include <AzCore/std/typetraits/void_t.h>
|
||||
#include <AzCore/std/utility/move.h>
|
||||
#include <AzCore/std/utility/declval.h>
|
||||
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// Bring in std utility functions into AZStd namespace
|
||||
using std::forward;
|
||||
}
|
||||
|
||||
// C++20 range traits for iteratable types
|
||||
namespace AZStd::ranges::Internal
|
||||
{
|
||||
void iter_move();
|
||||
|
||||
template <typename It, typename = void>
|
||||
constexpr bool iter_move_adl = false;
|
||||
|
||||
template <typename It>
|
||||
constexpr bool iter_move_adl<It, void_t<decltype(iter_move(declval<It>()))>> = true;
|
||||
|
||||
template <typename It, typename = void>
|
||||
constexpr bool is_class_or_enum_with_iter_move_adl = false;
|
||||
|
||||
template <typename It>
|
||||
constexpr bool is_class_or_enum_with_iter_move_adl<It, enable_if_t<iter_move_adl<It>
|
||||
&& (is_class_v<remove_cvref_t<It>> || is_enum_v<remove_cvref_t<It>>)>>
|
||||
= true;
|
||||
|
||||
struct iter_move_fn
|
||||
{
|
||||
template <typename It>
|
||||
constexpr auto operator()(It&& it) const
|
||||
->enable_if_t<is_class_or_enum_with_iter_move_adl<It>,
|
||||
decltype(iter_move(AZStd::forward<It>(it)))>
|
||||
{
|
||||
return iter_move(AZStd::forward<It>(it));
|
||||
}
|
||||
template <typename It>
|
||||
constexpr auto operator()(It&& it) const
|
||||
->enable_if_t<!is_class_or_enum_with_iter_move_adl<It>&& is_lvalue_reference_v<decltype(*AZStd::forward<It>(it))>,
|
||||
decltype(AZStd::move(*AZStd::forward<It>(it)))>
|
||||
{
|
||||
return AZStd::move(*AZStd::forward<It>(it));
|
||||
}
|
||||
template <typename It>
|
||||
constexpr auto operator()(It&& it) const
|
||||
->enable_if_t<!is_class_or_enum_with_iter_move_adl<It> && !is_lvalue_reference_v<decltype(*AZStd::forward<It>(it))>,
|
||||
decltype(*AZStd::forward<It>(it))>
|
||||
{
|
||||
return *AZStd::forward<It>(it);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace AZStd::ranges
|
||||
{
|
||||
inline namespace customization_point_object
|
||||
{
|
||||
inline constexpr auto iter_move = Internal::iter_move_fn{};
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -74,7 +74,7 @@ namespace AZStd
|
||||
constexpr basic_fixed_string(const_pointer ptr);
|
||||
|
||||
// #6
|
||||
template<class InputIt, typename = enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_t>>>
|
||||
template<class InputIt, typename = enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_t>>>
|
||||
constexpr basic_fixed_string(InputIt first, InputIt last);
|
||||
|
||||
// #7
|
||||
@@ -146,7 +146,7 @@ namespace AZStd
|
||||
constexpr auto append(size_type count, Element ch) -> basic_fixed_string&;
|
||||
template<class InputIt>
|
||||
constexpr auto append(InputIt first, InputIt last)
|
||||
-> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>;
|
||||
-> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>;
|
||||
constexpr auto append(AZStd::initializer_list<Element> ilist) -> basic_fixed_string&;
|
||||
|
||||
constexpr auto assign(const basic_fixed_string& rhs) -> basic_fixed_string&;
|
||||
@@ -161,7 +161,7 @@ namespace AZStd
|
||||
constexpr auto assign(size_type count, Element ch) -> basic_fixed_string&;
|
||||
template<class InputIt>
|
||||
constexpr auto assign(InputIt first, InputIt last)
|
||||
->enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>;
|
||||
->enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>;
|
||||
|
||||
constexpr auto assign(AZStd::initializer_list<Element> ilist) -> basic_fixed_string&;
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace AZStd
|
||||
constexpr auto insert(const_iterator insertPos, size_type count, Element ch) -> iterator;
|
||||
template<class InputIt>
|
||||
constexpr auto insert(const_iterator insertPos, InputIt first, InputIt last)
|
||||
-> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, iterator>;
|
||||
-> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, iterator>;
|
||||
|
||||
constexpr auto insert(const_iterator insertPos, AZStd::initializer_list<Element> ilist) -> iterator;
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace AZStd
|
||||
constexpr auto replace(const_iterator first, const_iterator last, size_type count, Element ch) -> basic_fixed_string&;
|
||||
template<class InputIt>
|
||||
constexpr auto replace(const_iterator first, const_iterator last, InputIt first2, InputIt last2)
|
||||
-> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>;
|
||||
-> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>;
|
||||
constexpr auto replace(const_iterator first, const_iterator last, AZStd::initializer_list<Element> ilist) -> basic_fixed_string&;
|
||||
|
||||
constexpr auto at(size_type offset) -> reference;
|
||||
|
||||
@@ -325,14 +325,14 @@ namespace AZStd
|
||||
template<class Element, size_t MaxElementCount, class Traits>
|
||||
template<class InputIt>
|
||||
inline constexpr auto basic_fixed_string<Element, MaxElementCount, Traits>::append(InputIt first, InputIt last)
|
||||
-> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>
|
||||
-> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>
|
||||
{
|
||||
if constexpr (Internal::satisfies_contiguous_iterator_concept_v<InputIt>
|
||||
if constexpr (contiguous_iterator<InputIt>
|
||||
&& is_same_v<typename AZStd::iterator_traits<InputIt>::value_type, value_type>)
|
||||
{
|
||||
return append(AZStd::to_address(first), AZStd::distance(first, last));
|
||||
}
|
||||
else if constexpr (Internal::is_forward_iterator_v<InputIt>)
|
||||
else if constexpr (forward_iterator<InputIt>)
|
||||
{
|
||||
// Input Iterator pointer type doesn't match the const_pointer type
|
||||
// So the elements need to be appended one by one into the buffer
|
||||
@@ -461,14 +461,14 @@ namespace AZStd
|
||||
template<class Element, size_t MaxElementCount, class Traits>
|
||||
template<class InputIt>
|
||||
inline constexpr auto basic_fixed_string<Element, MaxElementCount, Traits>::assign(InputIt first, InputIt last)
|
||||
-> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>
|
||||
-> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>
|
||||
{
|
||||
if constexpr (Internal::satisfies_contiguous_iterator_concept_v<InputIt>
|
||||
if constexpr (contiguous_iterator<InputIt>
|
||||
&& is_same_v<typename AZStd::iterator_traits<InputIt>::value_type, value_type>)
|
||||
{
|
||||
return assign(AZStd::to_address(first), AZStd::distance(first, last));
|
||||
}
|
||||
else if constexpr (Internal::is_forward_iterator_v<InputIt>)
|
||||
else if constexpr (forward_iterator<InputIt>)
|
||||
{
|
||||
// Input Iterator pointer type doesn't match the const_pointer type
|
||||
// So the elements need to be assigned one by one into the buffer
|
||||
@@ -627,15 +627,15 @@ namespace AZStd
|
||||
template<class Element, size_t MaxElementCount, class Traits>
|
||||
template<class InputIt>
|
||||
inline constexpr auto basic_fixed_string<Element, MaxElementCount, Traits>::insert(const_iterator insertPos,
|
||||
InputIt first, InputIt last)-> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, iterator>
|
||||
InputIt first, InputIt last)-> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, iterator>
|
||||
{ // insert [_First, _Last) at _Where
|
||||
size_type insertOffset = AZStd::distance(cbegin(), insertPos);
|
||||
if constexpr (Internal::satisfies_contiguous_iterator_concept_v<InputIt>
|
||||
if constexpr (contiguous_iterator<InputIt>
|
||||
&& is_same_v<typename AZStd::iterator_traits<InputIt>::value_type, value_type>)
|
||||
{
|
||||
insert(insertOffset, AZStd::to_address(first), AZStd::distance(first, last));
|
||||
}
|
||||
else if constexpr (Internal::is_forward_iterator_v<InputIt>)
|
||||
else if constexpr (forward_iterator<InputIt>)
|
||||
{
|
||||
// Input Iterator pointer type doesn't match the const_pointer type
|
||||
// So the elements need to be inserted one by one into the buffer
|
||||
@@ -927,14 +927,14 @@ namespace AZStd
|
||||
template<class Element, size_t MaxElementCount, class Traits>
|
||||
template<class InputIt>
|
||||
inline constexpr auto basic_fixed_string<Element, MaxElementCount, Traits>::replace(const_iterator first, const_iterator last,
|
||||
InputIt replaceFirst, InputIt replaceLast) -> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>
|
||||
InputIt replaceFirst, InputIt replaceLast) -> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, basic_fixed_string&>
|
||||
{ // replace [first, last) with [replaceFirst,replaceLast)
|
||||
if constexpr (Internal::satisfies_contiguous_iterator_concept_v<InputIt>
|
||||
if constexpr (contiguous_iterator<InputIt>
|
||||
&& is_same_v<typename AZStd::iterator_traits<InputIt>::value_type, value_type>)
|
||||
{
|
||||
return replace(first, last, AZStd::to_address(replaceFirst), AZStd::distance(replaceFirst, replaceLast));
|
||||
}
|
||||
else if constexpr (Internal::is_forward_iterator_v<InputIt>)
|
||||
else if constexpr (forward_iterator<InputIt>)
|
||||
{
|
||||
// Input Iterator pointer type doesn't match the const_pointer type
|
||||
// So the elements need to be appended one by one into the buffer
|
||||
|
||||
@@ -114,28 +114,23 @@ namespace AZStd
|
||||
assign(count, ch);
|
||||
}
|
||||
|
||||
template<class InputIt, typename = enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_t>>>
|
||||
template<class InputIt, typename = enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_t>>>
|
||||
inline basic_string(InputIt first, InputIt last, const Allocator& alloc = Allocator())
|
||||
: m_storage{ skip_element_tag{}, alloc }
|
||||
{ // construct from [first, last)
|
||||
assign(first, last);
|
||||
}
|
||||
|
||||
inline basic_string(const_pointer first, const_pointer last)
|
||||
{ // construct from [first, last), const pointers
|
||||
assign(first, last - first);
|
||||
}
|
||||
|
||||
inline basic_string(const this_type& rhs)
|
||||
: m_storage{ skip_element_tag{}, rhs.m_storage.second() }
|
||||
{
|
||||
assign(rhs, 0, npos);
|
||||
assign(rhs);
|
||||
}
|
||||
|
||||
inline basic_string(this_type&& rhs)
|
||||
: m_storage{ skip_element_tag{}, AZStd::move(rhs.m_storage.second()) }
|
||||
: m_storage{ skip_element_tag{}, rhs.m_storage.second() }
|
||||
{
|
||||
assign(AZStd::forward<this_type>(rhs));
|
||||
assign(AZStd::move(rhs));
|
||||
}
|
||||
|
||||
inline basic_string(const this_type& rhs, size_type rhsOffset, size_type count = npos)
|
||||
@@ -251,14 +246,14 @@ namespace AZStd
|
||||
|
||||
template<class InputIt>
|
||||
inline auto append(InputIt first, InputIt last)
|
||||
-> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, this_type&>
|
||||
-> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, this_type&>
|
||||
{ // append [first, last)
|
||||
if constexpr (Internal::satisfies_contiguous_iterator_concept_v<InputIt>
|
||||
if constexpr (contiguous_iterator<InputIt>
|
||||
&& is_same_v<typename AZStd::iterator_traits<InputIt>::value_type, value_type>)
|
||||
{
|
||||
return append(AZStd::to_address(first), AZStd::distance(first, last));
|
||||
}
|
||||
else if constexpr (Internal::is_forward_iterator_v<InputIt>)
|
||||
else if constexpr (forward_iterator<InputIt>)
|
||||
{
|
||||
// Input Iterator pointer type doesn't match the const_pointer type
|
||||
// So the elements need to be appended one by one into the buffer
|
||||
@@ -299,7 +294,7 @@ namespace AZStd
|
||||
|
||||
inline this_type& assign(const this_type& rhs)
|
||||
{
|
||||
return assign(rhs, 0, npos);
|
||||
return this != &rhs ? assign(rhs, 0, npos) : *this;
|
||||
}
|
||||
|
||||
inline this_type& assign(basic_string_view<Element, Traits> view)
|
||||
@@ -319,7 +314,8 @@ namespace AZStd
|
||||
pointer rhsData = rhs.data();
|
||||
// Memmove the right hand side string data if it is using the short string optimization
|
||||
// Otherwise set the pointer to the right hand side
|
||||
if (rhs.m_storage.first().ShortStringOptimizationActive())
|
||||
if (rhs.m_storage.first().ShortStringOptimizationActive() ||
|
||||
(get_allocator() != rhs.get_allocator() && !allocator_traits<allocator_type>::propagate_on_container_move_assignment::value))
|
||||
{
|
||||
Traits::move(data, rhsData, rhs.size() + 1); // string + null-terminator
|
||||
}
|
||||
@@ -395,14 +391,14 @@ namespace AZStd
|
||||
|
||||
template<class InputIt>
|
||||
auto assign(InputIt first, InputIt last)
|
||||
-> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, this_type&>
|
||||
-> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, this_type&>
|
||||
{
|
||||
if constexpr (Internal::satisfies_contiguous_iterator_concept_v<InputIt>
|
||||
if constexpr (contiguous_iterator<InputIt>
|
||||
&& is_same_v<typename AZStd::iterator_traits<InputIt>::value_type, value_type>)
|
||||
{
|
||||
return assign(AZStd::to_address(first), AZStd::distance(first, last));
|
||||
}
|
||||
else if constexpr (Internal::is_forward_iterator_v<InputIt>)
|
||||
else if constexpr (forward_iterator<InputIt>)
|
||||
{
|
||||
// forward iterator pointer type doesn't match the const_pointer type
|
||||
// So the elements need to be assigned one by one into the buffer
|
||||
@@ -431,7 +427,7 @@ namespace AZStd
|
||||
inputCopy.push_back(static_cast<Element>(*first));
|
||||
}
|
||||
|
||||
return assign(inputCopy.c_str(), inputCopy.size());
|
||||
return assign(AZStd::move(inputCopy));
|
||||
}
|
||||
}
|
||||
inline this_type& insert(size_type offset, const this_type& rhs) { return insert(offset, rhs, 0, npos); }
|
||||
@@ -539,15 +535,15 @@ namespace AZStd
|
||||
|
||||
template<class InputIt>
|
||||
auto insert(const_iterator insertPos, InputIt first, InputIt last)
|
||||
-> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, iterator>
|
||||
-> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, iterator>
|
||||
{ // insert [_First, _Last) at _Where
|
||||
size_type insertOffset = AZStd::distance(cbegin(), insertPos);
|
||||
if constexpr (Internal::satisfies_contiguous_iterator_concept_v<InputIt>
|
||||
if constexpr (contiguous_iterator<InputIt>
|
||||
&& is_same_v<typename AZStd::iterator_traits<InputIt>::value_type, value_type>)
|
||||
{
|
||||
insert(insertOffset, AZStd::to_address(first), AZStd::distance(first, last));
|
||||
}
|
||||
else if constexpr (Internal::is_forward_iterator_v<InputIt>)
|
||||
else if constexpr (forward_iterator<InputIt>)
|
||||
{
|
||||
// Input Iterator pointer type doesn't match the const_pointer type
|
||||
// So the elements need to be inserted one by one into the buffer
|
||||
@@ -834,14 +830,14 @@ namespace AZStd
|
||||
|
||||
template<class InputIt>
|
||||
inline auto replace(const_iterator first, const_iterator last, InputIt replaceFirst, InputIt replaceLast)
|
||||
-> enable_if_t<Internal::is_input_iterator_v<InputIt> && !is_convertible_v<InputIt, size_type>, this_type&>
|
||||
-> enable_if_t<input_iterator<InputIt> && !is_convertible_v<InputIt, size_type>, this_type&>
|
||||
{
|
||||
if constexpr (Internal::satisfies_contiguous_iterator_concept_v<InputIt>
|
||||
if constexpr (contiguous_iterator<InputIt>
|
||||
&& is_same_v<typename AZStd::iterator_traits<InputIt>::value_type, value_type>)
|
||||
{
|
||||
return replace(first, last, AZStd::to_address(replaceFirst), AZStd::distance(replaceFirst, replaceLast));
|
||||
}
|
||||
else if constexpr (Internal::is_forward_iterator_v<InputIt>)
|
||||
else if constexpr (forward_iterator<InputIt>)
|
||||
{
|
||||
// Input Iterator pointer type doesn't match the const_pointer type
|
||||
// So the elements need to be appended one by one into the buffer
|
||||
@@ -1031,12 +1027,19 @@ namespace AZStd
|
||||
// same allocator, swap storage
|
||||
m_storage.first().swap(rhs.m_storage.first());
|
||||
}
|
||||
else if (allocator_traits<allocator_type>::propagate_on_container_swap::value)
|
||||
{
|
||||
// The allocator propagates on swap, so the allocators can be swapped
|
||||
m_storage.first().swap(rhs.m_storage.first());
|
||||
using AZStd::swap;
|
||||
swap(m_storage.second(), rhs.m_storage.second());
|
||||
}
|
||||
else
|
||||
{
|
||||
// different allocator, do multiple assigns
|
||||
this_type tmp = *this;
|
||||
*this = rhs;
|
||||
rhs = tmp;
|
||||
this_type tmp = AZStd::move(*this);
|
||||
*this = AZStd::move(rhs);
|
||||
rhs = AZStd::move(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/ranges/ranges.h>
|
||||
#include <AzCore/std/createdestroy.h>
|
||||
#include <AzCore/std/iterator.h>
|
||||
#include <AzCore/std/limits.h>
|
||||
@@ -613,8 +614,9 @@ namespace AZStd
|
||||
{}
|
||||
|
||||
template <typename It, typename End, typename = AZStd::enable_if_t<
|
||||
Internal::satisfies_contiguous_iterator_concept_v<It>
|
||||
&& is_same_v<typename AZStd::iterator_traits<It>::value_type, value_type>
|
||||
contiguous_iterator<It>
|
||||
&& sized_sentinel_for<End, It>
|
||||
&& is_same_v<iter_value_t<It>, value_type>
|
||||
&& !is_convertible_v<End, size_type>>
|
||||
>
|
||||
constexpr basic_string_view(It first, End last)
|
||||
@@ -961,23 +963,6 @@ namespace AZStd
|
||||
using string_view = basic_string_view<char>;
|
||||
using wstring_view = basic_string_view<wchar_t>;
|
||||
|
||||
template<class Element, class Traits = AZStd::char_traits<Element>>
|
||||
using basic_const_string = basic_string_view<Element, Traits>;
|
||||
using const_string = string_view;
|
||||
using const_wstring = wstring_view;
|
||||
|
||||
template <class Element, class Traits = AZStd::char_traits<Element>>
|
||||
constexpr typename basic_string_view<Element, Traits>::const_iterator begin(basic_string_view<Element, Traits> sv)
|
||||
{
|
||||
return sv.begin();
|
||||
}
|
||||
|
||||
template <class Element, class Traits = AZStd::char_traits<Element>>
|
||||
constexpr typename basic_string_view<Element, Traits>::const_iterator end(basic_string_view<Element, Traits> sv)
|
||||
{
|
||||
return sv.end();
|
||||
}
|
||||
|
||||
inline namespace literals
|
||||
{
|
||||
inline namespace string_view_literals
|
||||
@@ -1024,6 +1009,15 @@ namespace AZStd
|
||||
|
||||
} // namespace AZStd
|
||||
|
||||
namespace AZStd::ranges
|
||||
{
|
||||
template <class Element, class Traits>
|
||||
inline constexpr bool enable_borrowed_range<basic_string_view<Element, Traits>> = true;
|
||||
|
||||
template <class Element, class Traits>
|
||||
inline constexpr bool enable_view<basic_string_view<Element, Traits>> = true;
|
||||
}
|
||||
|
||||
//! Use this macro to simplify safe printing of a string_view which may not be null-terminated.
|
||||
//! Example: AZStd::string::format("Safely formatted: %.*s", AZ_STRING_ARG(myString));
|
||||
#define AZ_STRING_ARG(str) aznumeric_cast<int>(str.size()), str.data()
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/typetraits/config.h>
|
||||
#include <AzCore/std/typetraits/common_type.h>
|
||||
#include <AzCore/std/typetraits/conditional.h>
|
||||
#include <AzCore/std/typetraits/is_const.h>
|
||||
#include <AzCore/std/typetraits/is_convertible.h>
|
||||
#include <AzCore/std/typetraits/is_lvalue_reference.h>
|
||||
#include <AzCore/std/typetraits/is_rvalue_reference.h>
|
||||
#include <AzCore/std/typetraits/is_same.h>
|
||||
#include <AzCore/std/typetraits/is_volatile.h>
|
||||
#include <AzCore/std/typetraits/remove_reference.h>
|
||||
#include <AzCore/std/typetraits/remove_cvref.h>
|
||||
#include <AzCore/std/typetraits/void_t.h>
|
||||
#include <AzCore/std/utility/declval.h>
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
template <class T, class U, template<class> class TQual, template<class> class UQual>
|
||||
struct basic_common_reference
|
||||
{};
|
||||
}
|
||||
|
||||
namespace AZStd::Internal
|
||||
{
|
||||
// const volatile and reference qualifier copy templates
|
||||
template <class T, class QualType>
|
||||
struct copy_cv_qual
|
||||
{
|
||||
using type = conditional_t<is_const_v<T>, conditional_t<is_volatile_v<T>, const volatile QualType, const QualType>,
|
||||
conditional_t<is_volatile_v<T>, volatile QualType, QualType>>;
|
||||
};
|
||||
|
||||
template <class T,class QualType>
|
||||
using copy_cv_qual_t = typename copy_cv_qual<T, QualType>::type;
|
||||
|
||||
static_assert(is_same_v<copy_cv_qual_t<int, float>, float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<const int, float>, const float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<volatile int, float>, volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<const volatile int, float>, const volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<int, const float>, const float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<const int, const float>, const float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<volatile int, const float>, const volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<const volatile int, const float>, const volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<int, volatile float>, volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<const int, volatile float>, const volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<volatile int, volatile float>, volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<const volatile int, volatile float>, const volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<int, const volatile float>, const volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<const int, const volatile float>, const volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<volatile int, const volatile float>, const volatile float>);
|
||||
static_assert(is_same_v<copy_cv_qual_t<const volatile int, const volatile float>, const volatile float>);
|
||||
|
||||
template <class T, class QualType>
|
||||
struct copy_reference_qual
|
||||
{
|
||||
using type = conditional_t<is_lvalue_reference_v<T>, QualType&,
|
||||
conditional_t<is_rvalue_reference_v<T>, QualType&&, QualType>>;
|
||||
};
|
||||
|
||||
template <class T, class QualType>
|
||||
using copy_reference_qual_t = typename copy_reference_qual<T, QualType>::type;
|
||||
|
||||
static_assert(is_same_v<copy_reference_qual_t<int, float>, float>);
|
||||
static_assert(is_same_v<copy_reference_qual_t<int&, float>, float&>);
|
||||
static_assert(is_same_v<copy_reference_qual_t<int&&, float>, float&&>);
|
||||
static_assert(is_same_v<copy_reference_qual_t<int, float&>, float&>);
|
||||
static_assert(is_same_v<copy_reference_qual_t<int&, float&>, float&>);
|
||||
static_assert(is_same_v<copy_reference_qual_t<int&&, float&>, float&>);
|
||||
static_assert(is_same_v<copy_reference_qual_t<int, float&&>, float&&>);
|
||||
static_assert(is_same_v<copy_reference_qual_t<int&, float&&>, float&>);
|
||||
static_assert(is_same_v<copy_reference_qual_t<int&&, float&&>, float&&>);
|
||||
|
||||
template <class T, class QualType>
|
||||
using copy_cvref_qual_t = copy_cv_qual_t<copy_reference_qual_t<T, QualType>, QualType>;
|
||||
|
||||
template <class T>
|
||||
struct copy_qualifiers_from_t
|
||||
{
|
||||
template <class X>
|
||||
using templ = copy_cvref_qual_t<T, X>;
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
using cond_res = decltype(false ? declval<copy_cv_qual_t<remove_reference_t<T>, remove_reference_t<U>>&>()
|
||||
: declval<copy_cv_qual_t<remove_reference_t<U>, remove_reference_t<T>>&>());
|
||||
|
||||
// common reference helper templates begin
|
||||
template <class T, class U, typename = void>
|
||||
struct common_reference_base_reference_test;
|
||||
|
||||
// COMMON_REF is defined within the C++ standard at https://eel.is/c++draft/meta.trans.other#3.5
|
||||
template <class T, class U>
|
||||
struct common_reference_base_reference_test<T, U,
|
||||
enable_if_t<is_lvalue_reference_v<T>&& is_lvalue_reference_v<U>,
|
||||
void_t<cond_res<T,U>> >>
|
||||
{
|
||||
// Uses the ternary operator for determining the common type
|
||||
using type = cond_res<T, U>;
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct common_reference_base_reference_test<T, U, enable_if_t<is_rvalue_reference_v<T>&& is_rvalue_reference_v<U>>>
|
||||
{
|
||||
using C = remove_reference_t<typename common_reference_base_reference_test<remove_reference_t<T>&, remove_reference_t<U>&>::type>;
|
||||
using type = AZStd::enable_if_t<is_convertible_v<T, C>&& is_convertible_v<U, C>, C>;
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct common_reference_base_reference_test<T, U, enable_if_t<is_rvalue_reference_v<T>&& is_lvalue_reference_v<U>>>
|
||||
{
|
||||
// Turn rvalue references to const lvalue references
|
||||
using D = typename common_reference_base_reference_test<const remove_reference_t<T>&, remove_reference_t<U>&>::type;
|
||||
using type = AZStd::enable_if_t<is_convertible_v<T, D>, D>;
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct common_reference_base_reference_test<T, U, enable_if_t<is_lvalue_reference_v<T>&& is_rvalue_reference_v<U>>>
|
||||
{
|
||||
// Swap the parameters to call the 3rd specialization for common_reference_base_reference_test
|
||||
using type = typename common_reference_base_reference_test<U, T>::type;
|
||||
};
|
||||
|
||||
template <class T, class U, typename = void>
|
||||
constexpr bool has_reference_test = false;
|
||||
|
||||
template <class T, class U>
|
||||
constexpr bool has_reference_test<T, U, void_t<typename common_reference_base_reference_test<T, U>::type>> = true;
|
||||
|
||||
template <class T, class U, typename = void>
|
||||
struct basic_common_reference_test;
|
||||
|
||||
template <class T, class U>
|
||||
struct basic_common_reference_test<T, U, void_t<typename basic_common_reference<remove_cvref_t<T>, remove_cvref_t<U>,
|
||||
copy_qualifiers_from_t<T>::template templ, copy_qualifiers_from_t<U>::template templ>::type>>
|
||||
{
|
||||
using type = typename basic_common_reference<remove_cvref_t<T>, remove_cvref_t<U>,
|
||||
copy_qualifiers_from_t<T>::template templ, copy_qualifiers_from_t<U>::template templ>::type;
|
||||
};
|
||||
|
||||
template <class T, class U, typename = void>
|
||||
constexpr bool has_basic_common_reference_test = false;
|
||||
|
||||
template <class T, class U>
|
||||
constexpr bool has_basic_common_reference_test<T, U,
|
||||
void_t<typename basic_common_reference_test<T, U>::type>> = true;
|
||||
|
||||
template <class T, class U, typename = void>
|
||||
constexpr bool has_condition_result_test = false;
|
||||
|
||||
template <class T, class U>
|
||||
constexpr bool has_condition_result_test<T, U, void_t<decltype(false ? declval<T>() : declval<U>())>> = true;
|
||||
|
||||
template <class T, class U, typename = void>
|
||||
struct common_reference_base_test
|
||||
{};
|
||||
|
||||
template <class T, class U>
|
||||
struct common_reference_base_test<T, U, enable_if_t<has_reference_test<T, U>>>
|
||||
: common_reference_base_reference_test<T, U>
|
||||
{};
|
||||
template <class T, class U>
|
||||
struct common_reference_base_test<T, U, enable_if_t<!has_reference_test<T, U>
|
||||
&& has_basic_common_reference_test<T, U>>>
|
||||
: basic_common_reference_test<T, U>
|
||||
{};
|
||||
template <class T, class U>
|
||||
struct common_reference_base_test<T, U, enable_if_t<!has_reference_test<T, U>
|
||||
&& !has_basic_common_reference_test<T, U> && has_condition_result_test<T,U>>>
|
||||
{
|
||||
using type = decltype(false ? declval<T>() : declval<U>());
|
||||
};
|
||||
template <class T, class U>
|
||||
struct common_reference_base_test<T, U, enable_if_t<!has_reference_test<T, U>
|
||||
&& !has_basic_common_reference_test<T, U> && !has_condition_result_test<T, U>>>
|
||||
: common_type<T, U>
|
||||
{};
|
||||
|
||||
template <class... T>
|
||||
struct common_reference_base
|
||||
{};
|
||||
|
||||
template <class T>
|
||||
struct common_reference_base<T>
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
template <class T, class U>
|
||||
struct common_reference_base<T, U>
|
||||
: common_reference_base_test<T, U>
|
||||
{};
|
||||
|
||||
template <class T, class U, class V, class... Rs>
|
||||
struct common_reference_base<T, U, V, Rs...>
|
||||
: common_reference_base<typename common_reference_base<T, U>::type, V, Rs...>
|
||||
{};
|
||||
}
|
||||
namespace AZStd
|
||||
{
|
||||
template <class... T>
|
||||
struct common_reference
|
||||
: Internal::common_reference_base<T...>
|
||||
{};
|
||||
|
||||
template <class... T>
|
||||
using common_reference_t = typename common_reference<T...>::type;
|
||||
|
||||
// models the common reference concept
|
||||
namespace Internal
|
||||
{
|
||||
template<class T, class U, typename = void>
|
||||
constexpr bool common_reference_with_impl = false;
|
||||
template<class T, class U>
|
||||
constexpr bool common_reference_with_impl<T, U, enable_if_t<
|
||||
same_as<common_reference_t<T, U>, common_reference_t<U, T>>
|
||||
&& convertible_to<T, common_reference_t<T, U>>
|
||||
&& convertible_to<U, common_reference_t<T, U>>
|
||||
>> = true;
|
||||
}
|
||||
|
||||
template<class T, class U>
|
||||
/*concept*/ constexpr bool common_reference_with = Internal::common_reference_with_impl<T, U>;
|
||||
}
|
||||
@@ -8,12 +8,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/typetraits/conditional.h>
|
||||
#include <AzCore/std/typetraits/intrinsics.h>
|
||||
#include <AzCore/std/typetraits/void_t.h>
|
||||
#include <AzCore/std/utility/declval.h>
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
using std::is_convertible;
|
||||
using std::is_convertible_v;
|
||||
|
||||
// models the C++20 convertible_to concept
|
||||
namespace Internal
|
||||
{
|
||||
template<typename From, typename To, typename = void>
|
||||
constexpr bool convertible_to_impl = false;
|
||||
template<typename From, typename To>
|
||||
constexpr bool convertible_to_impl<From, To, enable_if_t<
|
||||
is_convertible_v<From, To>, void_t<decltype(static_cast<To>(declval<From>()))>>> = true;
|
||||
}
|
||||
template<typename From, typename To>
|
||||
constexpr bool is_convertible_v = std::is_convertible_v<From, To>;
|
||||
/*concept*/ constexpr bool convertible_to = Internal::convertible_to_impl<From, To>;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,4 +21,7 @@ namespace AZStd
|
||||
constexpr bool is_trivially_destructible_v = std::is_trivially_destructible<T>::value;
|
||||
template<class T>
|
||||
constexpr bool is_nothrow_destructible_v = std::is_nothrow_destructible<T>::value;
|
||||
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool destructible = is_nothrow_destructible_v<T>;
|
||||
}
|
||||
|
||||
@@ -13,4 +13,7 @@ namespace AZStd
|
||||
{
|
||||
using std::is_floating_point;
|
||||
using std::is_floating_point_v;
|
||||
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool floating_point = is_floating_point_v<T>;
|
||||
}
|
||||
|
||||
@@ -13,4 +13,7 @@ namespace AZStd
|
||||
{
|
||||
using std::is_integral;
|
||||
using std::is_integral_v;
|
||||
|
||||
template<class T>
|
||||
/*concept*/ constexpr bool integral = is_integral_v<T>;
|
||||
}
|
||||
|
||||
@@ -13,4 +13,8 @@ namespace AZStd
|
||||
{
|
||||
using std::is_same;
|
||||
using std::is_same_v;
|
||||
|
||||
// models the same_as concept
|
||||
template <class T, class U>
|
||||
/*concept*/ constexpr bool same_as = is_same_v<T, U>;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include <AzCore/std/typetraits/add_volatile.h>
|
||||
#include <AzCore/std/typetraits/alignment_of.h>
|
||||
#include <AzCore/std/typetraits/aligned_storage.h>
|
||||
#include <AzCore/std/typetraits/common_reference.h>
|
||||
#include <AzCore/std/typetraits/common_type.h>
|
||||
#include <AzCore/std/typetraits/conditional.h>
|
||||
#include <AzCore/std/typetraits/conjunction.h>
|
||||
#include <AzCore/std/typetraits/decay.h>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
using std::declval;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
// rvalue
|
||||
// rvalue move
|
||||
template<class T>
|
||||
constexpr AZStd::remove_reference_t<T>&& move(T&& t)
|
||||
{
|
||||
return static_cast<AZStd::remove_reference_t<T>&&>(t);
|
||||
}
|
||||
}
|
||||
@@ -22,22 +22,15 @@
|
||||
#include <AzCore/std/typetraits/is_convertible.h>
|
||||
#include <AzCore/std/typetraits/is_lvalue_reference.h>
|
||||
#include <AzCore/std/typetraits/void_t.h>
|
||||
#include <AzCore/std/utility/declval.h>
|
||||
#include <AzCore/std/utility/move.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace AZStd
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// rvalue
|
||||
// rvalue move
|
||||
template<class T>
|
||||
constexpr AZStd::remove_reference_t<T>&& move(T && t)
|
||||
{
|
||||
return static_cast<AZStd::remove_reference_t<T>&&>(t);
|
||||
}
|
||||
|
||||
using std::forward;
|
||||
using std::declval;
|
||||
using std::exchange;
|
||||
|
||||
template <class T>
|
||||
|
||||
Reference in New Issue
Block a user