From d7ee248df5f7362d61f27d1a2e036fa5a57d3411 Mon Sep 17 00:00:00 2001 From: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> Date: Fri, 11 Feb 2022 12:50:12 -0600 Subject: [PATCH] Range adaptor support (#7388) * Updated the SFINAE checks in concepts.h and range.h To use conjunction and disjunction for short-circuiting behavior. Replaced AZStd::optional implementation with std::optional alias Added range adaptor support and the following views: ref_view, owning_view Added bitwise or(|) overload for chaining range adaptor closures together Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding indirectly invocable concepts. These concepts are used to determine whether a callable can be invoked with a dereferenced iterator instance. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Add implementation of range relational function objects Add implementation of range min max functions which uses the range relation function objects(ranges::less, ranges::equal_to, etc...) This is needed to implement ranges::zip_view Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding interface for zip_view which compiles successfully The implementation for the zip view functions still need to be filled. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding function definitions for zip_view classes. Adding empty header of subrange.h for the ranges::subrange class Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding additional view implementations. The following range and view classes have been added: empty_view, single_view and subrange. Moved the AZ_NO_UNIQUE_ADDRESS macro to PlatformDef.h to allow other code to specify the [[no_unique_address]] attribute. Added additional test for view structures. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding missing includes for non-unity builds Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Workaround for NDK21 clang 9.0.9 compile issue. The AZStd::ranges::zip_view::iterator::iter_swap friend function is in the AZStd::ranges namespace, while the customization point object of `AZStd::ranges::customization_point_object::iter_swap` is in the regular namespace of `AZStd::ranges` and the inline namespace of `customization_point`. This issue is fixed in NDK23, but as Jenkins uses NDK21 at the time, the entire zip_view implementation has moved to inline namespace of `zip_view_internal` Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Added iterator algorithm requiremetn concepts Fixed the ambiguity in the ranges::iter_swap exchange overload to exclude itself as a candidate if the iterator reference types are swappable with each other. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding type alias for borrowed_subrange_t Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed convertible to ref_view check in the ranges::all customization_point Updated SFINAE detection of whether AZStd::to_address is invocable Moved the Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed private variable access in ranges::subrange get specialization. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removing ranges::view constraint from the ranges::views::single customization_point. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding C++23 range overload for string_view. It is detailed in the [C++draft strings](https://eel.is/c++draft/strings#lib:basic_string_view,constructor____) section Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding implementations of ranges, find, search, mismatch and equal functions. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding implementation of ranges split_view along with test. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding const overloads to SceneAPI ProxyPointer container The Proxy Pointer class operator* and operator-> was unable to be invoked with a const instance before. Now it returns a const view of the pointer it contains. This allows it to be invoked in `AZStd::to_address` as part of an SINAE context for the contiguous_iterator concept Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Refactored the to_address implementation to better work with SFINAE. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding general non-unity build fixes This is unrelated to the RangeAdaptor changes. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Allow range algorithms to be used with rvalue ranges Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Workaround MSVC Internal Compiler erroy by removing enable_if condition in the operator bool of the view_interface class. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Corrected the non_propagating_cache helper class to have public functions Fixed the order of creating the perfect forwarding call wrapper for an outer closure around another closure. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Specialized the borrowed_range and view concepts For the AZ PathView class, since it is a immutable view around a path. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed inline namespace around the zip_view class. It was needed to workaround a clang 10 or below issue where a friend function in a namespace and a variable within underneath an inline namespace within the function namespace would cause an improper symbol redefinition. The workaround is to create a placeholder namespace containing the inline namespace and then bring that placeholder namespace into the parent scope. https://bugs.llvm.org/show_bug.cgi?id=37556 Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding implementation of the elemetns_view and join_view classes It is up to date with the standard as of the current draft: https://eel.is/c++draft/ranges. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Separated definitions of concepts out of concepts.h This allows the ranges::iter_swap and ranges::swap customization point to be moved outside of the concepts folder and into the ranges folder. The concepts.h header previously had to define those objects to avoid circular dependencies. Added the work around for ranges::iter_swap and ranges::iter_move customization_point causing an improper symbol redefinition in clang 10 or below: https://bugs.llvm.org/show_bug.cgi?id=37556 Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Alias more std:: names into the AZStd namespace. Removed our custom implementation of toaddress. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding more range view test. The join_view and elements_view classes now have UnitTest. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Adding deduction guides for AZStd associative containers Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Moved zip_view::sentinel iterator accessor function to zip_view.inl Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fixed variable shadowing issues with clang 12+ Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> --- Code/Framework/AzCore/AzCore/IO/Path/Path.h | 5 +- Code/Framework/AzCore/AzCore/IO/Path/Path.inl | 16 +- Code/Framework/AzCore/AzCore/PlatformDef.h | 11 +- .../AzCore/RTTI/AzStdOnDemandReflection.inl | 5 +- Code/Framework/AzCore/AzCore/RTTI/TypeInfo.h | 14 +- .../AzCore/Serialization/AZStdContainers.inl | 4 +- .../AzCore/Threading/ThreadSafeObject.h | 1 + .../AzCore/AzCore/std/azstd_files.cmake | 20 + .../AzCore/AzCore/std/concepts/concepts.h | 793 ++++++------- .../AzCore/std/concepts/concepts_assignable.h | 34 + .../std/concepts/concepts_constructible.h | 26 + .../AzCore/std/concepts/concepts_copyable.h | 60 + .../AzCore/std/concepts/concepts_movable.h | 35 + .../AzCore/AzCore/std/containers/map.h | 48 +- .../AzCore/std/containers/node_handle.h | 23 +- .../AzCore/AzCore/std/containers/set.h | 46 +- .../AzCore/std/containers/unordered_map.h | 123 +- .../AzCore/std/containers/unordered_set.h | 103 +- .../AzCore/AzCore/std/function/identity.h | 2 +- .../AzCore/AzCore/std/function/invoke.h | 16 + Code/Framework/AzCore/AzCore/std/iterator.h | 4 - .../AzCore/std/iterator/iterator_primitives.h | 129 ++- Code/Framework/AzCore/AzCore/std/optional.h | 1006 +---------------- .../AzCore/AzCore/std/ranges/all_view.h | 67 ++ .../AzCore/AzCore/std/ranges/elements_view.h | 475 ++++++++ .../AzCore/AzCore/std/ranges/empty_view.h | 37 + .../AzCore/AzCore/std/ranges/iter_move.h | 12 +- .../AzCore/AzCore/std/ranges/iter_swap.h | 120 ++ .../AzCore/AzCore/std/ranges/join_view.h | 430 +++++++ .../AzCore/AzCore/std/ranges/owning_view.h | 114 ++ .../AzCore/AzCore/std/ranges/ranges.h | 429 ++++--- .../AzCore/AzCore/std/ranges/ranges_adaptor.h | 333 ++++++ .../AzCore/std/ranges/ranges_algorithm.h | 996 ++++++++++++++++ .../AzCore/std/ranges/ranges_functional.h | 121 ++ .../AzCore/AzCore/std/ranges/ref_view.h | 77 ++ .../AzCore/AzCore/std/ranges/single_view.h | 89 ++ .../AzCore/AzCore/std/ranges/split_view.h | 235 ++++ .../AzCore/AzCore/std/ranges/subrange.h | 290 +++++ .../Framework/AzCore/AzCore/std/ranges/swap.h | 116 ++ .../AzCore/AzCore/std/ranges/zip_view.h | 395 +++++++ .../AzCore/AzCore/std/ranges/zip_view.inl | 308 +++++ .../AzCore/AzCore/std/string/string_view.h | 41 + Code/Framework/AzCore/AzCore/std/tuple.h | 20 +- .../AzCore/std/typetraits/conjunction.h | 26 +- .../AzCore/std/typetraits/disjunction.h | 25 +- .../AzCore/std/typetraits/is_constructible.h | 43 +- .../AzCore/AzCore/std/typetraits/negation.h | 12 +- Code/Framework/AzCore/AzCore/std/utils.h | 114 +- .../AzCore/Tests/AZStd/ConceptsTests.cpp | 119 ++ .../Tests/AZStd/RangesAlgorithmTests.cpp | 250 ++++ .../AzCore/Tests/AZStd/RangesViewTests.cpp | 483 ++++++++ Code/Framework/AzCore/Tests/Main.cpp | 1 + .../AzCore/Tests/azcoretests_files.cmake | 2 + .../AzFramework/Viewport/ClickDetector.h | 3 +- .../LuaIDE/Source/LUA/BreakpointPanel.cpp | 2 +- .../Containers/Utilities/ProxyPointer.h | 6 +- .../Containers/Utilities/ProxyPointer.inl | 20 + .../Source/TestImpactCommandLineOptions.h | 1 + .../Atom/Feature/CoreLights/ShadowConstants.h | 3 +- .../Shader/ShaderVariantListSourceData.h | 3 +- .../AtomToolsAssetBrowserInteractions.h | 1 + .../Code/Source/PythonBuilderMessageSink.h | 1 + 62 files changed, 6486 insertions(+), 1858 deletions(-) create mode 100644 Code/Framework/AzCore/AzCore/std/concepts/concepts_assignable.h create mode 100644 Code/Framework/AzCore/AzCore/std/concepts/concepts_constructible.h create mode 100644 Code/Framework/AzCore/AzCore/std/concepts/concepts_copyable.h create mode 100644 Code/Framework/AzCore/AzCore/std/concepts/concepts_movable.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/all_view.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/elements_view.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/empty_view.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/iter_swap.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/join_view.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/owning_view.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/ranges_adaptor.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/ranges_algorithm.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/ranges_functional.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/ref_view.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/single_view.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/split_view.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/subrange.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/swap.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/zip_view.h create mode 100644 Code/Framework/AzCore/AzCore/std/ranges/zip_view.inl create mode 100644 Code/Framework/AzCore/Tests/AZStd/RangesAlgorithmTests.cpp create mode 100644 Code/Framework/AzCore/Tests/AZStd/RangesViewTests.cpp diff --git a/Code/Framework/AzCore/AzCore/IO/Path/Path.h b/Code/Framework/AzCore/AzCore/IO/Path/Path.h index 235310a5da..3c2c4f0a8c 100644 --- a/Code/Framework/AzCore/AzCore/IO/Path/Path.h +++ b/Code/Framework/AzCore/AzCore/IO/Path/Path.h @@ -709,7 +709,10 @@ namespace AZ::IO constexpr reference operator*() const; - constexpr pointer operator->() const; + constexpr pointer operator->() const + { + return &m_stashed_elem; + } constexpr PathIterator& operator++(); diff --git a/Code/Framework/AzCore/AzCore/IO/Path/Path.inl b/Code/Framework/AzCore/AzCore/IO/Path/Path.inl index bde2353112..5046b43127 100644 --- a/Code/Framework/AzCore/AzCore/IO/Path/Path.inl +++ b/Code/Framework/AzCore/AzCore/IO/Path/Path.inl @@ -1397,12 +1397,6 @@ namespace AZ::IO return m_stashed_elem; } - template - constexpr auto PathIterator::operator->() const -> pointer - { - return &m_stashed_elem; - } - template constexpr auto PathIterator::operator++() -> PathIterator& { @@ -1542,3 +1536,13 @@ namespace AZ::IO extern template bool operator!=(const PathIterator& lhs, const PathIterator& rhs); } + +namespace AZStd::ranges +{ + // A PathView is a borrowed range, it does not own the content of the Path it is viewing + template<> + inline constexpr bool enable_borrowed_range = true; + + template<> + inline constexpr bool enable_view = true; +} diff --git a/Code/Framework/AzCore/AzCore/PlatformDef.h b/Code/Framework/AzCore/AzCore/PlatformDef.h index 8416099f15..d10b155127 100644 --- a/Code/Framework/AzCore/AzCore/PlatformDef.h +++ b/Code/Framework/AzCore/AzCore/PlatformDef.h @@ -83,7 +83,7 @@ #define AZ_PUSH_DISABLE_WARNING_GCC(_gccOption) /// Compiler specific AZ_POP_DISABLE_WARNING. This needs to be matched with the compiler specific AZ_PUSH_DISABLE_WARNINGs -#define AZ_POP_DISABLE_WARNING_CLANG +#define AZ_POP_DISABLE_WARNING_CLANG #define AZ_POP_DISABLE_WARNING_MSVC \ __pragma(warning(pop)) #define AZ_POP_DISABLE_WARNING_GCC @@ -176,7 +176,7 @@ #define AZ_PUSH_DISABLE_WARNING_3(_1, _2, _gccOption) AZ_PUSH_DISABLE_WARNING_GCC(_gccOption) /// Pops the warning stack. For use matched with an AZ_PUSH_DISABLE_WARNING -#define AZ_POP_DISABLE_WARNING +#define AZ_POP_DISABLE_WARNING _Pragma("GCC diagnostic pop") #endif // defined(AZ_COMPILER_CLANG) @@ -303,3 +303,10 @@ #if !defined(az_has_builtin_wmemmove) #define az_has_builtin_wmemmove false #endif + +// no unique address attribute support in C++17 +#if __has_cpp_attribute(no_unique_address) + #define AZ_NO_UNIQUE_ADDRESS [[no_unique_address]] +#else + #define AZ_NO_UNIQUE_ADDRESS +#endif diff --git a/Code/Framework/AzCore/AzCore/RTTI/AzStdOnDemandReflection.inl b/Code/Framework/AzCore/AzCore/RTTI/AzStdOnDemandReflection.inl index bba79e36f7..af814fbd32 100644 --- a/Code/Framework/AzCore/AzCore/RTTI/AzStdOnDemandReflection.inl +++ b/Code/Framework/AzCore/AzCore/RTTI/AzStdOnDemandReflection.inl @@ -13,6 +13,7 @@ #include #include #include +#include #ifndef AZ_USE_CUSTOM_SCRIPT_BIND struct lua_State; @@ -47,10 +48,6 @@ namespace AZStd class intrusive_ptr; template class shared_ptr; - - // Wrapper types - template - class optional; } namespace AZ diff --git a/Code/Framework/AzCore/AzCore/RTTI/TypeInfo.h b/Code/Framework/AzCore/AzCore/RTTI/TypeInfo.h index 2cff17a638..0f292140dc 100644 --- a/Code/Framework/AzCore/AzCore/RTTI/TypeInfo.h +++ b/Code/Framework/AzCore/AzCore/RTTI/TypeInfo.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -89,9 +90,6 @@ namespace AZStd template class function; - template - class optional; - struct monostate; template @@ -150,7 +148,7 @@ namespace AZ template