From 04ccbca4c7d5445a2a22ddfa4bf1bc41ae47955a Mon Sep 17 00:00:00 2001 From: Benjamin Ransom Ryan Date: Mon, 13 Apr 2020 17:02:27 -0600 Subject: [PATCH] clang-format and mdspan guards --- .../__p0009_bits/accessor_basic.hpp | 17 +- src/experimental/__p0009_bits/all_type.hpp | 4 +- .../__p0009_bits/basic_mdspan.hpp | 372 ++++++------ src/experimental/__p0009_bits/config.hpp | 151 ++--- src/experimental/__p0009_bits/extents.hpp | 268 ++++----- .../__p0009_bits/fixed_layout_impl.hpp | 144 +++-- src/experimental/__p0009_bits/layout_left.hpp | 94 +-- .../__p0009_bits/layout_right.hpp | 90 +-- .../__p0009_bits/layout_stride.hpp | 231 ++++--- src/experimental/__p0009_bits/macros.hpp | 562 +++++++++--------- .../__p0009_bits/maybe_static_value.hpp | 27 +- .../__p0009_bits/no_unique_address.hpp | 25 +- .../standard_layout_static_array.hpp | 54 +- .../__p0009_bits/static_array.hpp | 165 +++-- src/experimental/__p0009_bits/subspan.hpp | 517 ++++++++-------- .../__p0009_bits/trait_backports.hpp | 36 +- src/experimental/__p0009_bits/type_list.hpp | 34 +- src/experimental/mdspan | 32 +- 18 files changed, 1416 insertions(+), 1407 deletions(-) diff --git a/src/experimental/__p0009_bits/accessor_basic.hpp b/src/experimental/__p0009_bits/accessor_basic.hpp index 86895dce8b..927a21ccac 100644 --- a/src/experimental/__p0009_bits/accessor_basic.hpp +++ b/src/experimental/__p0009_bits/accessor_basic.hpp @@ -50,17 +50,15 @@ namespace std { namespace experimental { -template -struct accessor_basic { - +template struct accessor_basic { + using offset_policy = accessor_basic; using element_type = ElementType; - using reference = ElementType&; - using pointer = ElementType*; + using reference = ElementType &; + using pointer = ElementType *; MDSPAN_INLINE_FUNCTION - constexpr pointer - offset(pointer p, ptrdiff_t i) const noexcept { + constexpr pointer offset(pointer p, ptrdiff_t i) const noexcept { return p + i; } @@ -70,10 +68,7 @@ struct accessor_basic { } MDSPAN_INLINE_FUNCTION - constexpr pointer decay(pointer p) const noexcept { - return p; - } - + constexpr pointer decay(pointer p) const noexcept { return p; } }; } // end namespace experimental diff --git a/src/experimental/__p0009_bits/all_type.hpp b/src/experimental/__p0009_bits/all_type.hpp index 6631c7e168..a6276c662a 100644 --- a/src/experimental/__p0009_bits/all_type.hpp +++ b/src/experimental/__p0009_bits/all_type.hpp @@ -48,9 +48,9 @@ namespace std { namespace experimental { -struct all_type { }; +struct all_type {}; -_MDSPAN_INLINE_VARIABLE constexpr auto all = all_type{ }; +_MDSPAN_INLINE_VARIABLE constexpr auto all = all_type{}; } // end namespace experimental } // namespace std diff --git a/src/experimental/__p0009_bits/basic_mdspan.hpp b/src/experimental/__p0009_bits/basic_mdspan.hpp index e86a9d714a..9dc20a5741 100644 --- a/src/experimental/__p0009_bits/basic_mdspan.hpp +++ b/src/experimental/__p0009_bits/basic_mdspan.hpp @@ -41,66 +41,51 @@ //@HEADER */ - #pragma once #include "accessor_basic.hpp" -#include "layout_right.hpp" #include "extents.hpp" +#include "layout_right.hpp" #include "trait_backports.hpp" namespace std { namespace experimental { - -template < - class ElementType, - class Extents, - class LayoutPolicy = layout_right, - class AccessorPolicy = accessor_basic -> +template > class basic_mdspan; - -template < - class ElementType, - ptrdiff_t... Exts, - class LayoutPolicy, - class AccessorPolicy -> -class basic_mdspan< - ElementType, - std::experimental::extents, - LayoutPolicy, - AccessorPolicy -> -{ +template +class basic_mdspan, + LayoutPolicy, AccessorPolicy> { private: - using __mapping_base_t = detail::__no_unique_address_emulation< - typename LayoutPolicy::template mapping>, 0>; - using __accessor_base_t = detail::__no_unique_address_emulation; + typename LayoutPolicy::template mapping>, + 0>; + using __accessor_base_t = + detail::__no_unique_address_emulation; // Workaround for non-deducibility of the index sequence template parameter if it's given at the top level - template > - struct __impl; - - template - struct __impl> - { - MDSPAN_FORCE_INLINE_FUNCTION static constexpr - ptrdiff_t __size(basic_mdspan const& __self) noexcept { - return _MDSPAN_FOLD_TIMES_RIGHT((__self.__mapping_ref().extents().template __extent()), /* * ... * */ 1); + template > struct __impl; + + template struct __impl> { + MDSPAN_FORCE_INLINE_FUNCTION static constexpr ptrdiff_t + __size(basic_mdspan const &__self) noexcept { + return _MDSPAN_FOLD_TIMES_RIGHT( + (__self.__mapping_ref().extents().template __extent()), + /* * ... * */ 1); } template - MDSPAN_FORCE_INLINE_FUNCTION static constexpr - ReferenceType __callop(basic_mdspan const& __self, const array& indices) noexcept { - return __self.__accessor_ref().access(__self.__pointer_ref(), __self.__mapping_ref()(indices[Idxs]...)); + MDSPAN_FORCE_INLINE_FUNCTION static constexpr ReferenceType + __callop(basic_mdspan const &__self, + const array &indices) noexcept { + return __self.__accessor_ref().access( + __self.__pointer_ref(), __self.__mapping_ref()(indices[Idxs]...)); } }; public: - //-------------------------------------------------------------------------------- // Domain and codomain types @@ -116,106 +101,116 @@ class basic_mdspan< using reference = typename accessor_type::reference; private: - - using __map_acc_pair_t = detail::__compressed_pair; + using __map_acc_pair_t = + detail::__compressed_pair; public: - //-------------------------------------------------------------------------------- // [mdspan.basic.cons], basic_mdspan constructors, assignment, and destructor MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr basic_mdspan() noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr basic_mdspan(const basic_mdspan&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr basic_mdspan(basic_mdspan&&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr basic_mdspan( + const basic_mdspan &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr basic_mdspan( + basic_mdspan &&) noexcept = default; // TODO noexcept specification MDSPAN_TEMPLATE_REQUIRES( - class... IndexType, - /* requires */ ( - _MDSPAN_FOLD_AND(_MDSPAN_TRAIT(is_convertible, IndexType, index_type) /* && ... */) && - (sizeof...(IndexType) == extents_type::rank_dynamic()) && - _MDSPAN_TRAIT(is_constructible, mapping_type, extents_type) && - _MDSPAN_TRAIT(is_default_constructible, accessor_type) - ) - ) + class... IndexType, + /* requires */ ( + _MDSPAN_FOLD_AND(_MDSPAN_TRAIT(is_convertible, IndexType, + index_type) /* && ... */) && + (sizeof...(IndexType) == extents_type::rank_dynamic()) && + _MDSPAN_TRAIT(is_constructible, mapping_type, extents_type) && + _MDSPAN_TRAIT(is_default_constructible, accessor_type))) MDSPAN_INLINE_FUNCTION - explicit constexpr basic_mdspan(pointer p, IndexType... dynamic_extents) - noexcept - // TODO @proposal-bug shouldn't I be allowed to do `move(p)` here? - : __members(p, __map_acc_pair_t(mapping_type(extents_type(dynamic_extents...)), accessor_type())) - { } + explicit constexpr basic_mdspan(pointer p, + IndexType... dynamic_extents) noexcept + // TODO @proposal-bug shouldn't I be allowed to do `move(p)` here? + : __members( + p, __map_acc_pair_t(mapping_type(extents_type(dynamic_extents...)), + accessor_type())) {} // TODO noexcept specification MDSPAN_TEMPLATE_REQUIRES( - class IndexType, size_t N, - /* requires */ ( - _MDSPAN_TRAIT(is_convertible, IndexType, index_type) && - (N == extents_type::rank_dynamic()) && - _MDSPAN_TRAIT(is_constructible, mapping_type, extents_type) && - _MDSPAN_TRAIT(is_default_constructible, accessor_type) - ) - ) + class IndexType, size_t N, + /* requires */ + (_MDSPAN_TRAIT(is_convertible, IndexType, index_type) && + (N == extents_type::rank_dynamic()) && + _MDSPAN_TRAIT(is_constructible, mapping_type, extents_type) && + _MDSPAN_TRAIT(is_default_constructible, accessor_type))) MDSPAN_INLINE_FUNCTION - explicit constexpr basic_mdspan(pointer p, const array& dynamic_extents) - noexcept - : __members(p, __map_acc_pair_t(mapping_type(extents_type(dynamic_extents)), accessor_type())) - { } + explicit constexpr basic_mdspan( + pointer p, const array &dynamic_extents) noexcept + : __members(p, + __map_acc_pair_t(mapping_type(extents_type(dynamic_extents)), + accessor_type())) {} // TODO noexcept specification MDSPAN_FUNCTION_REQUIRES( - (MDSPAN_INLINE_FUNCTION constexpr), - basic_mdspan, (pointer p, const mapping_type& m), noexcept, - /* requires */ (_MDSPAN_TRAIT(is_default_constructible, accessor_type)) - ) : __members(p, __map_acc_pair_t(m, accessor_type())) - { } + (MDSPAN_INLINE_FUNCTION constexpr), basic_mdspan, + (pointer p, const mapping_type &m), noexcept, + /* requires */ (_MDSPAN_TRAIT(is_default_constructible, accessor_type))) + : __members(p, __map_acc_pair_t(m, accessor_type())) {} // TODO noexcept specification MDSPAN_INLINE_FUNCTION - constexpr basic_mdspan(pointer p, const mapping_type& m, const accessor_type& a) noexcept - : __members(p, __map_acc_pair_t(m, a)) - { } + constexpr basic_mdspan(pointer p, const mapping_type &m, + const accessor_type &a) noexcept + : __members(p, __map_acc_pair_t(m, a)) {} // TODO noexcept specification MDSPAN_TEMPLATE_REQUIRES( - class OtherElementType, class OtherExtents, class OtherLayoutPolicy, class OtherAccessor, - /* requires */ ( - _MDSPAN_TRAIT(is_convertible, typename OtherLayoutPolicy::template mapping, mapping_type) && - _MDSPAN_TRAIT(is_convertible, OtherAccessor, accessor_type) && - _MDSPAN_TRAIT(is_convertible, typename OtherAccessor::pointer, pointer) && - // TODO @proposal-bug there is a redundant constraint in the proposal; the convertibility of the extents is effectively stated twice - _MDSPAN_TRAIT(is_convertible, OtherExtents, extents_type) - ) - ) + class OtherElementType, class OtherExtents, class OtherLayoutPolicy, + class OtherAccessor, + /* requires */ + (_MDSPAN_TRAIT(is_convertible, + typename OtherLayoutPolicy::template mapping, + mapping_type) && + _MDSPAN_TRAIT(is_convertible, OtherAccessor, accessor_type) && + _MDSPAN_TRAIT(is_convertible, typename OtherAccessor::pointer, + pointer) && + // TODO @proposal-bug there is a redundant constraint in the proposal; the convertibility of the extents is effectively stated twice + _MDSPAN_TRAIT(is_convertible, OtherExtents, extents_type))) MDSPAN_INLINE_FUNCTION - constexpr basic_mdspan(const basic_mdspan& other) - : __members(other.__ptr_ref(), __map_acc_pair_t(other.__mapping_ref(), other.__accessor_ref())) - { } + constexpr basic_mdspan( + const basic_mdspan &other) + : __members(other.__ptr_ref(), __map_acc_pair_t(other.__mapping_ref(), + other.__accessor_ref())) { + } MDSPAN_INLINE_FUNCTION_DEFAULTED ~basic_mdspan() noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED basic_mdspan& operator=(const basic_mdspan&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED basic_mdspan& operator=(basic_mdspan&&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED basic_mdspan & + operator=(const basic_mdspan &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED basic_mdspan & + operator=(basic_mdspan &&) noexcept = default; MDSPAN_TEMPLATE_REQUIRES( - class OtherElementType, ptrdiff_t... OtherExtents, class OtherLayoutPolicy, class OtherAccessorPolicy, - /* requires */ ( - _MDSPAN_TRAIT(is_assignable, mapping_type, typename OtherLayoutPolicy::template mapping>) && - _MDSPAN_TRAIT(is_assignable, accessor_type, OtherAccessorPolicy) && - _MDSPAN_TRAIT(is_assignable, pointer, typename OtherAccessorPolicy::pointer) && - sizeof...(OtherExtents) == extents_type::rank() && - // "For all r in the range [0, rank()), if other.static_extent(r) != dynamic_extent - // && static_extent(r) != dynamic_extent is true, then - // other.static_extent(r) == static_extent(r) is true." - // (this is just the convertiblity constraint on extents...) - _MDSPAN_TRAIT(is_convertible, std::experimental::extents, std::experimental::extents) - ) - ) + class OtherElementType, ptrdiff_t... OtherExtents, + class OtherLayoutPolicy, class OtherAccessorPolicy, + /* requires */ + (_MDSPAN_TRAIT(is_assignable, mapping_type, + typename OtherLayoutPolicy::template mapping< + std::experimental::extents>) && + _MDSPAN_TRAIT(is_assignable, accessor_type, OtherAccessorPolicy) && + _MDSPAN_TRAIT(is_assignable, pointer, + typename OtherAccessorPolicy::pointer) && + sizeof...(OtherExtents) == extents_type::rank() && + // "For all r in the range [0, rank()), if other.static_extent(r) != dynamic_extent + // && static_extent(r) != dynamic_extent is true, then + // other.static_extent(r) == static_extent(r) is true." + // (this is just the convertiblity constraint on extents...) + _MDSPAN_TRAIT(is_convertible, std::experimental::extents, + std::experimental::extents))) MDSPAN_INLINE_FUNCTION - _MDSPAN_CONSTEXPR_14 basic_mdspan& operator=( - const basic_mdspan, OtherLayoutPolicy, OtherAccessorPolicy>& other - ) noexcept(/* TODO noexcept specification */ true) - { + _MDSPAN_CONSTEXPR_14 basic_mdspan & + operator=(const basic_mdspan, + OtherLayoutPolicy, OtherAccessorPolicy> + &other) noexcept(/* TODO noexcept specification */ true) { __ptr_ref() = other.__ptr_ref(); __mapping_ref() = other.__mapping_ref(); __accessor_ref() = other.__accessor_ref(); @@ -225,71 +220,76 @@ class basic_mdspan< //-------------------------------------------------------------------------------- // [mdspan.basic.mapping], basic_mdspan mapping domain multidimensional index to access codomain element - MDSPAN_TEMPLATE_REQUIRES( - class Index, - /* requires */ ( - _MDSPAN_TRAIT(is_convertible, Index, index_type) && - sizeof...(Exts) == 1 - ) - ) + MDSPAN_TEMPLATE_REQUIRES(class Index, + /* requires */ (_MDSPAN_TRAIT(is_convertible, Index, + index_type) && + sizeof...(Exts) == 1)) MDSPAN_FORCE_INLINE_FUNCTION - constexpr reference operator[](Index idx) const noexcept - { - return __accessor_ref().access(__ptr_ref(), __mapping_ref()(index_type(idx))); + constexpr reference operator[](Index idx) const noexcept { + return __accessor_ref().access(__ptr_ref(), + __mapping_ref()(index_type(idx))); } - MDSPAN_TEMPLATE_REQUIRES( - class... IndexType, - /* requires */ ( - _MDSPAN_FOLD_AND(_MDSPAN_TRAIT(is_convertible, IndexType, index_type) /* && ... */) && - sizeof...(Exts) == extents_type::rank() - ) - ) + MDSPAN_TEMPLATE_REQUIRES(class... IndexType, + /* requires */ (_MDSPAN_FOLD_AND(_MDSPAN_TRAIT( + is_convertible, IndexType, + index_type) /* && ... */) && + sizeof...(Exts) == + extents_type::rank())) MDSPAN_FORCE_INLINE_FUNCTION - constexpr reference operator()(IndexType... indices) const noexcept - { - return __accessor_ref().access(__ptr_ref(), __mapping_ref()(index_type(indices)...)); + constexpr reference operator()(IndexType... indices) const noexcept { + return __accessor_ref().access(__ptr_ref(), + __mapping_ref()(index_type(indices)...)); } - MDSPAN_TEMPLATE_REQUIRES( - class IndexType, size_t N, - /* requires */ ( - _MDSPAN_TRAIT(is_convertible, IndexType, index_type) && - N == extents_type::rank() - ) - ) + MDSPAN_TEMPLATE_REQUIRES(class IndexType, size_t N, + /* requires */ + (_MDSPAN_TRAIT(is_convertible, IndexType, + index_type) && + N == extents_type::rank())) MDSPAN_FORCE_INLINE_FUNCTION - constexpr reference operator()(const array& indices) const noexcept - { + constexpr reference operator()(const array &indices) const + noexcept { return __impl<>::template __callop(*this, indices); } // TODO @proposal-bug The proposal is missing constexpr here - MDSPAN_INLINE_FUNCTION constexpr - accessor_type accessor() const { return __accessor_ref(); }; + MDSPAN_INLINE_FUNCTION constexpr accessor_type accessor() const { + return __accessor_ref(); + }; //-------------------------------------------------------------------------------- // [mdspan.basic.domobs], basic_mdspan observers of the domain multidimensional index space - MDSPAN_INLINE_FUNCTION static constexpr int rank() noexcept { return extents_type::rank(); } - MDSPAN_INLINE_FUNCTION static constexpr int rank_dynamic() noexcept { return extents_type::rank_dynamic(); } - MDSPAN_INLINE_FUNCTION static constexpr index_type static_extent(size_t r) noexcept { return extents_type::static_extent(r); } + MDSPAN_INLINE_FUNCTION static constexpr int rank() noexcept { + return extents_type::rank(); + } + MDSPAN_INLINE_FUNCTION static constexpr int rank_dynamic() noexcept { + return extents_type::rank_dynamic(); + } + MDSPAN_INLINE_FUNCTION static constexpr index_type + static_extent(size_t r) noexcept { + return extents_type::static_extent(r); + } - MDSPAN_INLINE_FUNCTION constexpr extents_type extents() const noexcept { return __mapping_ref().extents(); }; - MDSPAN_INLINE_FUNCTION constexpr index_type extent(size_t r) const noexcept { return __mapping_ref().extents().extent(r); }; + MDSPAN_INLINE_FUNCTION constexpr extents_type extents() const noexcept { + return __mapping_ref().extents(); + }; + MDSPAN_INLINE_FUNCTION constexpr index_type extent(size_t r) const noexcept { + return __mapping_ref().extents().extent(r); + }; MDSPAN_INLINE_FUNCTION constexpr index_type size() const noexcept { return __impl<>::__size(*this); }; // TODO @proposal-bug for non-unique, non-contiguous mappings this is unimplementable - MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 index_type unique_size() const noexcept { - if(__mapping_ref().is_unique()) { + MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 index_type unique_size() const + noexcept { + if (__mapping_ref().is_unique()) { return size(); - } - else if(__mapping_ref().is_contiguous()) { + } else if (__mapping_ref().is_contiguous()) { return __mapping_ref().required_span_size(); - } - else { + } else { // ??? guess, for now, until this gets fixed in the proposal ??? return __mapping_ref().required_span_size(); } @@ -299,38 +299,70 @@ class basic_mdspan< // TODO span (or just `codomain` function, as discussed) // constexpr span span() const noexcept; - MDSPAN_INLINE_FUNCTION constexpr pointer data() const noexcept { return __ptr_ref(); }; + MDSPAN_INLINE_FUNCTION constexpr pointer data() const noexcept { + return __ptr_ref(); + }; //-------------------------------------------------------------------------------- // [mdspan.basic.obs], basic_mdspan observers of the mapping - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { return mapping_type::is_always_unique(); }; - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_contiguous() noexcept { return mapping_type::is_always_contiguous(); }; - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { return mapping_type::is_always_strided(); }; + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { + return mapping_type::is_always_unique(); + }; + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_contiguous() noexcept { + return mapping_type::is_always_contiguous(); + }; + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { + return mapping_type::is_always_strided(); + }; - MDSPAN_INLINE_FUNCTION constexpr mapping_type mapping() const noexcept { return __mapping_ref(); }; - MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { return __mapping_ref().is_unique(); }; - MDSPAN_INLINE_FUNCTION constexpr bool is_contiguous() const noexcept { return __mapping_ref().is_contiguous(); }; - MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { return __mapping_ref().is_strided(); }; - MDSPAN_INLINE_FUNCTION constexpr index_type stride(size_t r) const { return __mapping_ref().stride(r); }; + MDSPAN_INLINE_FUNCTION constexpr mapping_type mapping() const noexcept { + return __mapping_ref(); + }; + MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { + return __mapping_ref().is_unique(); + }; + MDSPAN_INLINE_FUNCTION constexpr bool is_contiguous() const noexcept { + return __mapping_ref().is_contiguous(); + }; + MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { + return __mapping_ref().is_strided(); + }; + MDSPAN_INLINE_FUNCTION constexpr index_type stride(size_t r) const { + return __mapping_ref().stride(r); + }; private: - detail::__compressed_pair __members; - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 pointer& __ptr_ref() noexcept { return __members.__first(); } - MDSPAN_FORCE_INLINE_FUNCTION constexpr pointer const& __ptr_ref() const noexcept { return __members.__first(); } - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 mapping_type& __mapping_ref() noexcept { return __members.__second().__first(); } - MDSPAN_FORCE_INLINE_FUNCTION constexpr mapping_type const& __mapping_ref() const noexcept { return __members.__second().__first(); } - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 accessor_type& __accessor_ref() noexcept { return __members.__second().__second(); } - MDSPAN_FORCE_INLINE_FUNCTION constexpr accessor_type const& __accessor_ref() const noexcept { return __members.__second().__second(); } - - template - friend class basic_mdspan; + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 pointer & + __ptr_ref() noexcept { + return __members.__first(); + } + MDSPAN_FORCE_INLINE_FUNCTION constexpr pointer const &__ptr_ref() const + noexcept { + return __members.__first(); + } + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 mapping_type & + __mapping_ref() noexcept { + return __members.__second().__first(); + } + MDSPAN_FORCE_INLINE_FUNCTION constexpr mapping_type const & + __mapping_ref() const noexcept { + return __members.__second().__first(); + } + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 accessor_type & + __accessor_ref() noexcept { + return __members.__second().__second(); + } + MDSPAN_FORCE_INLINE_FUNCTION constexpr accessor_type const & + __accessor_ref() const noexcept { + return __members.__second().__second(); + } + template friend class basic_mdspan; }; - template using mdspan = basic_mdspan>; diff --git a/src/experimental/__p0009_bits/config.hpp b/src/experimental/__p0009_bits/config.hpp index aaa4a15674..c392c93bf6 100644 --- a/src/experimental/__p0009_bits/config.hpp +++ b/src/experimental/__p0009_bits/config.hpp @@ -45,14 +45,14 @@ #define _MDSPAN_INCLUDE_EXPERIMENTAL_BITS_CONFIG_HPP_ #ifndef __has_include -# define __has_include(x) 0 +#define __has_include(x) 0 #endif #if __has_include() -# include +#include #else -# include -# include +#include +#include #endif #define MDSPAN_CXX_STD_14 201402L @@ -62,119 +62,128 @@ #define MDSPAN_HAS_CXX_17 (__cplusplus >= MDSPAN_CXX_STD_17) #ifdef __apple_build_version__ -# define _MDSPAN_COMPILER_APPLECLANG +#define _MDSPAN_COMPILER_APPLECLANG #endif #ifndef __has_cpp_attribute -# define __has_cpp_attribute(x) 0 +#define __has_cpp_attribute(x) 0 #endif #ifndef _MDSPAN_PRESERVE_STANDARD_LAYOUT // Preserve standard layout by default, but we're not removing the old version // that turns this off until we're sure this doesn't have an unreasonable cost // to the compiler or optimizer. -# define _MDSPAN_PRESERVE_STANDARD_LAYOUT 1 +#define _MDSPAN_PRESERVE_STANDARD_LAYOUT 1 #endif #ifndef _MDSPAN_NO_UNIQUE_ADDRESS -# if __has_cpp_attribute(no_unique_address) >= 201803L -# define _MDSPAN_NO_UNIQUE_ADDRESS [[no_unique_address]] -# else -# define _MDSPAN_NO_UNIQUE_ADDRESS -# endif +#if __has_cpp_attribute(no_unique_address) >= 201803L +#define _MDSPAN_NO_UNIQUE_ADDRESS [[no_unique_address]] +#else +#define _MDSPAN_NO_UNIQUE_ADDRESS +#endif #endif #ifndef _MDSPAN_USE_CONCEPTS -# if defined(__cpp_concepts) && __cpp_concepts >= 201507L -# define _MDSPAN_USE_CONCEPTS 1 -# endif +#if defined(__cpp_concepts) && __cpp_concepts >= 201507L +#define _MDSPAN_USE_CONCEPTS 1 +#endif #endif #ifndef _MDSPAN_USE_FOLD_EXPRESSIONS -# if (defined(__cpp_fold_expressions) && __cpp_fold_expressions >= 201603L) \ - || (!defined(__cpp_fold_expressions) && MDSPAN_HAS_CXX_17) -# define _MDSPAN_USE_FOLD_EXPRESSIONS 1 -# endif +#if (defined(__cpp_fold_expressions) && __cpp_fold_expressions >= 201603L) || \ + (!defined(__cpp_fold_expressions) && MDSPAN_HAS_CXX_17) +#define _MDSPAN_USE_FOLD_EXPRESSIONS 1 +#endif #endif #ifndef _MDSPAN_USE_INLINE_VARIABLES -# if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L \ - || (!defined(__cpp_inline_variables) && MDSPAN_HAS_CXX_17) -# define _MDSPAN_USE_INLINE_VARIABLES 1 -# endif +#if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L || \ + (!defined(__cpp_inline_variables) && MDSPAN_HAS_CXX_17) +#define _MDSPAN_USE_INLINE_VARIABLES 1 +#endif #endif #ifndef _MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS -# if !(defined(__cpp_lib_type_trait_variable_templates) && __cpp_lib_type_trait_variable_templates >= 201510L) \ - || !MDSPAN_HAS_CXX_17 -# define _MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS 1 -# endif +#if !(defined(__cpp_lib_type_trait_variable_templates) && \ + __cpp_lib_type_trait_variable_templates >= 201510L) || \ + !MDSPAN_HAS_CXX_17 +#define _MDSPAN_NEEDS_TRAIT_VARIABLE_TEMPLATE_BACKPORTS 1 +#endif #endif #ifndef _MDSPAN_USE_VARIABLE_TEMPLATES -# if (defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304) \ - || (!defined(__cpp_variable_templates) && MDSPAN_HAS_CXX_14) -# define _MDSPAN_USE_VARIABLE_TEMPLATES 1 -# endif +#if (defined(__cpp_variable_templates) && \ + __cpp_variable_templates >= 201304) || \ + (!defined(__cpp_variable_templates) && MDSPAN_HAS_CXX_14) +#define _MDSPAN_USE_VARIABLE_TEMPLATES 1 +#endif #endif // _MDSPAN_USE_VARIABLE_TEMPLATES #ifndef _MDSPAN_USE_CONSTEXPR_14 -# if (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) \ - || (!defined(__cpp_constexpr) && MDSPAN_HAS_CXX_14) \ - && (!(defined(__INTEL_COMPILER) && __INTEL_COMPILER <= 1700)) -# define _MDSPAN_USE_CONSTEXPR_14 1 -# endif +#if (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) || \ + (!defined(__cpp_constexpr) && MDSPAN_HAS_CXX_14) && \ + (!(defined(__INTEL_COMPILER) && __INTEL_COMPILER <= 1700)) +#define _MDSPAN_USE_CONSTEXPR_14 1 +#endif #endif #ifndef _MDSPAN_USE_INTEGER_SEQUENCE -# ifdef _MSC_VER -# if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) -# define _MDSPAN_USE_INTEGER_SEQUENCE 1 -# endif -# endif +#ifdef _MSC_VER +#if (defined(__cpp_lib_integer_sequence) && \ + __cpp_lib_integer_sequence >= 201304) +#define _MDSPAN_USE_INTEGER_SEQUENCE 1 +#endif +#endif #endif #ifndef _MDSPAN_USE_INTEGER_SEQUENCE -# if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) \ - || (!defined(__cpp_lib_integer_sequence) && MDSPAN_HAS_CXX_14) \ - /* as far as I can tell, libc++ seems to think this is a C++11 feature... */ \ - || (defined(__GLIBCXX__) && __GLIBCXX__ > 20150422 && __GNUC__ < 5 && !defined(__INTEL_CXX11_MODE__)) - // several compilers lie about integer_sequence working properly unless the C++14 standard is used -# define _MDSPAN_USE_INTEGER_SEQUENCE 1 -# elif defined(_MDSPAN_COMPILER_APPLECLANG) && MDSPAN_HAS_CXX_14 - // appleclang seems to be missing the __cpp_lib_... macros, but doesn't seem to lie about C++14 making - // integer_sequence work -# define _MDSPAN_USE_INTEGER_SEQUENCE 1 -# endif +#if (defined(__cpp_lib_integer_sequence) && \ + __cpp_lib_integer_sequence >= 201304) || \ + (!defined(__cpp_lib_integer_sequence) && \ + MDSPAN_HAS_CXX_14) /* as far as I can tell, libc++ seems to think this is a C++11 feature... */ \ + || (defined(__GLIBCXX__) && __GLIBCXX__ > 20150422 && __GNUC__ < 5 && \ + !defined(__INTEL_CXX11_MODE__)) +// several compilers lie about integer_sequence working properly unless the C++14 standard is used +#define _MDSPAN_USE_INTEGER_SEQUENCE 1 +#elif defined(_MDSPAN_COMPILER_APPLECLANG) && MDSPAN_HAS_CXX_14 +// appleclang seems to be missing the __cpp_lib_... macros, but doesn't seem to lie about C++14 making +// integer_sequence work +#define _MDSPAN_USE_INTEGER_SEQUENCE 1 +#endif #endif #ifndef _MDSPAN_USE_RETURN_TYPE_DEDUCTION -# ifdef _MSC_VER -# if (defined(__cpp_lib_integer_sequence) && __cpp_lib_integer_sequence >= 201304) && MDSPAN_HAS_CXX_14 -# define _MDSPAN_USE_RETURN_TYPE_DEDUCTION 1 -# endif -# endif +#ifdef _MSC_VER +#if (defined(__cpp_lib_integer_sequence) && \ + __cpp_lib_integer_sequence >= 201304) && \ + MDSPAN_HAS_CXX_14 +#define _MDSPAN_USE_RETURN_TYPE_DEDUCTION 1 +#endif +#endif #endif #ifndef _MDSPAN_USE_RETURN_TYPE_DEDUCTION -# if (defined(__cpp_return_type_deduction) && __cpp_return_type_deduction >= 201304) \ - || (!defined(__cpp_return_type_deduction) && MDSPAN_HAS_CXX_14) -# define _MDSPAN_USE_RETURN_TYPE_DEDUCTION 1 -# endif +#if (defined(__cpp_return_type_deduction) && \ + __cpp_return_type_deduction >= 201304) || \ + (!defined(__cpp_return_type_deduction) && MDSPAN_HAS_CXX_14) +#define _MDSPAN_USE_RETURN_TYPE_DEDUCTION 1 +#endif #endif #ifndef _MDSPAN_USE_STANDARD_TRAIT_ALIASES -# if (defined(__cpp_lib_transformation_trait_aliases) && __cpp_lib_transformation_trait_aliases >= 201304) \ - || (!defined(__cpp_lib_transformation_trait_aliases) && MDSPAN_HAS_CXX_14) -# define _MDSPAN_USE_STANDARD_TRAIT_ALIASES 1 -# elif defined(_MDSPAN_COMPILER_APPLECLANG) && MDSPAN_HAS_CXX_14 - // appleclang seems to be missing the __cpp_lib_... macros, but doesn't seem to lie about C++14 -# define _MDSPAN_USE_STANDARD_TRAIT_ALIASES 1 -# endif +#if (defined(__cpp_lib_transformation_trait_aliases) && \ + __cpp_lib_transformation_trait_aliases >= 201304) || \ + (!defined(__cpp_lib_transformation_trait_aliases) && MDSPAN_HAS_CXX_14) +#define _MDSPAN_USE_STANDARD_TRAIT_ALIASES 1 +#elif defined(_MDSPAN_COMPILER_APPLECLANG) && MDSPAN_HAS_CXX_14 +// appleclang seems to be missing the __cpp_lib_... macros, but doesn't seem to lie about C++14 +#define _MDSPAN_USE_STANDARD_TRAIT_ALIASES 1 +#endif #endif #ifndef _MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND -# if __GNUC__ < 9 -# define _MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND 1 -# endif +#if __GNUC__ < 9 +#define _MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND 1 +#endif #endif #endif // _MDSPAN_INCLUDE_EXPERIMENTAL_BITS_CONFIG_HPP_ diff --git a/src/experimental/__p0009_bits/extents.hpp b/src/experimental/__p0009_bits/extents.hpp index b4dce31764..d60c986a9d 100644 --- a/src/experimental/__p0009_bits/extents.hpp +++ b/src/experimental/__p0009_bits/extents.hpp @@ -44,9 +44,9 @@ #pragma once #include "macros.hpp" -#include "static_array.hpp" -#include "standard_layout_static_array.hpp" #include "no_unique_address.hpp" +#include "standard_layout_static_array.hpp" +#include "static_array.hpp" #include "trait_backports.hpp" // integer_sequence, etc. #include @@ -59,232 +59,220 @@ namespace detail { template static constexpr std::false_type _check_compatible_extents( - std::false_type, std::integer_sequence, std::integer_sequence -) noexcept { return { }; } + std::false_type, std::integer_sequence, + std::integer_sequence) noexcept { + return {}; +} template static std::integral_constant< - bool, - _MDSPAN_FOLD_AND( - ( - Extents == dynamic_extent - || OtherExtents == dynamic_extent - || Extents == OtherExtents - ) /* && ... */ - ) -> + bool, _MDSPAN_FOLD_AND((Extents == dynamic_extent || + OtherExtents == dynamic_extent || + Extents == OtherExtents) /* && ... */ + )> _check_compatible_extents( - std::true_type, std::integer_sequence, std::integer_sequence -) noexcept { return { }; } + std::true_type, std::integer_sequence, + std::integer_sequence) noexcept { + return {}; +} -struct __extents_tag { }; +struct __extents_tag {}; } // end namespace detail template class extents - : private detail::__no_unique_address_emulation< - detail::__partially_static_sizes_tagged> -{ + : private detail::__no_unique_address_emulation< + detail::__partially_static_sizes_tagged> { public: - using index_type = ptrdiff_t; - using __storage_t = detail::__partially_static_sizes_tagged; + using __storage_t = + detail::__partially_static_sizes_tagged; using __base_t = detail::__no_unique_address_emulation<__storage_t>; - private: - - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 - __storage_t& __storage() noexcept { return this->__base_t::__ref(); } +private: + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 __storage_t & + __storage() noexcept { + return this->__base_t::__ref(); + } MDSPAN_FORCE_INLINE_FUNCTION - constexpr __storage_t const& __storage() const noexcept { return this->__base_t::__ref(); } + constexpr __storage_t const &__storage() const noexcept { + return this->__base_t::__ref(); + } template - MDSPAN_FORCE_INLINE_FUNCTION - static constexpr - index_type _static_extent_impl(size_t n, std::integer_sequence) noexcept { - return _MDSPAN_FOLD_PLUS_RIGHT(((Idxs == n) ? Extents : 0), /* + ... + */ 0); + MDSPAN_FORCE_INLINE_FUNCTION static constexpr index_type + _static_extent_impl(size_t n, + std::integer_sequence) noexcept { + return _MDSPAN_FOLD_PLUS_RIGHT(((Idxs == n) ? Extents : 0), + /* + ... + */ 0); } - template - friend class extents; - + template friend class extents; template - MDSPAN_INLINE_FUNCTION - constexpr bool _eq_impl(std::experimental::extents, false_type, index_sequence) const noexcept { return false; } + MDSPAN_INLINE_FUNCTION constexpr bool + _eq_impl(std::experimental::extents, false_type, + index_sequence) const noexcept { + return false; + } template - MDSPAN_INLINE_FUNCTION - constexpr bool _eq_impl( - std::experimental::extents other, - true_type, index_sequence - ) const noexcept { + MDSPAN_INLINE_FUNCTION constexpr bool + _eq_impl(std::experimental::extents other, true_type, + index_sequence) const noexcept { return _MDSPAN_FOLD_AND( - (__storage().template __get_n() == other.__storage().template __get_n()) /* && ... */ + (__storage().template __get_n() == + other.__storage().template __get_n()) /* && ... */ ); } template - MDSPAN_INLINE_FUNCTION - constexpr bool _not_eq_impl(std::experimental::extents, false_type, index_sequence) const noexcept { return true; } + MDSPAN_INLINE_FUNCTION constexpr bool + _not_eq_impl(std::experimental::extents, false_type, + index_sequence) const noexcept { + return true; + } template - MDSPAN_INLINE_FUNCTION - constexpr bool _not_eq_impl( - std::experimental::extents other, - true_type, index_sequence - ) const noexcept { - return _MDSPAN_FOLD_OR( - (this->__base_t::template __get_n() != other.template __get_n()) /* || ... */ + MDSPAN_INLINE_FUNCTION constexpr bool + _not_eq_impl(std::experimental::extents other, true_type, + index_sequence) const noexcept { + return _MDSPAN_FOLD_OR((this->__base_t::template __get_n() != + other.template __get_n()) /* || ... */ ); } - MDSPAN_INLINE_FUNCTION constexpr explicit - extents(__base_t&& __b) noexcept - : __base_t(::std::move(__b)) - { } - + MDSPAN_INLINE_FUNCTION constexpr explicit extents(__base_t &&__b) noexcept + : __base_t(::std::move(__b)) {} public: - - MDSPAN_INLINE_FUNCTION static constexpr size_t rank() noexcept { return sizeof...(Extents); } MDSPAN_INLINE_FUNCTION - static constexpr size_t rank_dynamic() noexcept { return _MDSPAN_FOLD_PLUS_RIGHT((int(Extents == dynamic_extent)), /* + ... + */ 0); } + static constexpr size_t rank_dynamic() noexcept { + return _MDSPAN_FOLD_PLUS_RIGHT((int(Extents == dynamic_extent)), + /* + ... + */ 0); + } //-------------------------------------------------------------------------------- // Constructors, Destructors, and Assignment MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents() noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents(extents const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents(extents&&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED extents& operator=(extents const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED extents& operator=(extents&&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents(extents const &) noexcept = + default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr extents(extents &&) noexcept = + default; + MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED extents & + operator=(extents const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED extents & + operator=(extents &&) noexcept = default; MDSPAN_INLINE_FUNCTION_DEFAULTED ~extents() noexcept = default; MDSPAN_TEMPLATE_REQUIRES( - ptrdiff_t... OtherExtents, - /* requires */ ( - /* multi-stage check to protect from invalid pack expansion when sizes don't match? */ - decltype(detail::_check_compatible_extents( - std::integral_constant{}, - std::integer_sequence{}, - std::integer_sequence{} - ))::value - ) - ) + ptrdiff_t... OtherExtents, + /* requires */ ( + /* multi-stage check to protect from invalid pack expansion when sizes don't match? */ + decltype(detail::_check_compatible_extents( + std::integral_constant{}, + std::integer_sequence{}, + std::integer_sequence{}))::value)) MDSPAN_INLINE_FUNCTION - constexpr extents(const extents& __other) - noexcept - : __base_t(__base_t{__storage_t{__other.__storage().__enable_psa_conversion()}}) - { } + constexpr extents(const extents &__other) noexcept + : __base_t(__base_t{ + __storage_t{__other.__storage().__enable_psa_conversion()}}) {} MDSPAN_TEMPLATE_REQUIRES( - class... Integral, - /* requires */ ( - _MDSPAN_FOLD_AND(_MDSPAN_TRAIT(is_convertible, Integral, index_type) /* && ... */) - && sizeof...(Integral) == rank_dynamic() - ) - ) + class... Integral, + /* requires */ (_MDSPAN_FOLD_AND(_MDSPAN_TRAIT( + is_convertible, Integral, index_type) /* && ... */) && + sizeof...(Integral) == rank_dynamic())) MDSPAN_INLINE_FUNCTION constexpr explicit extents(Integral... dyn) noexcept - : __base_t(__base_t{typename __base_t::__stored_type{ - detail::__construct_partially_static_array_from_sizes_tag, - detail::__construct_partially_static_array_from_sizes_tag, dyn...}}) - { } - + : __base_t(__base_t{typename __base_t::__stored_type{ + detail::__construct_partially_static_array_from_sizes_tag, + detail::__construct_partially_static_array_from_sizes_tag, + dyn...}}) {} // TODO @proposal-bug this constructor should be explicit MDSPAN_TEMPLATE_REQUIRES( - class IndexType, - /* requires */ ( - _MDSPAN_TRAIT(is_convertible, IndexType, index_type) - ) - ) + class IndexType, + /* requires */ (_MDSPAN_TRAIT(is_convertible, IndexType, index_type))) MDSPAN_INLINE_FUNCTION - constexpr explicit - extents(std::array const& dyn) noexcept - : __base_t(__base_t{typename __base_t::stored_type{ - detail::__construct_psa_from_dynamic_values_tag_t<>{}, dyn}}) - { } + constexpr explicit extents( + std::array const &dyn) noexcept + : __base_t(__base_t{typename __base_t::stored_type{ + detail::__construct_psa_from_dynamic_values_tag_t<>{}, dyn}}) {} MDSPAN_TEMPLATE_REQUIRES( - ptrdiff_t... OtherExtents, - /* requires */ ( - /* multi-stage check to protect from invalid pack expansion when sizes don't match? */ - decltype(detail::_check_compatible_extents( - std::integral_constant{}, - std::integer_sequence{}, - std::integer_sequence{} - ))::value - ) - ) + ptrdiff_t... OtherExtents, + /* requires */ ( + /* multi-stage check to protect from invalid pack expansion when sizes don't match? */ + decltype(detail::_check_compatible_extents( + std::integral_constant{}, + std::integer_sequence{}, + std::integer_sequence{}))::value)) MDSPAN_INLINE_FUNCTION - _MDSPAN_CONSTEXPR_14 extents& operator=(const extents& other) noexcept - { + _MDSPAN_CONSTEXPR_14 extents & + operator=(const extents &other) noexcept { __storage() = other.__storage().__enable_psa_conversion(); return *this; } //-------------------------------------------------------------------------------- - + MDSPAN_INLINE_FUNCTION - static constexpr - index_type static_extent(size_t n) noexcept { - return _static_extent_impl(n, std::make_integer_sequence{}); + static constexpr index_type static_extent(size_t n) noexcept { + return _static_extent_impl( + n, std::make_integer_sequence{}); } MDSPAN_INLINE_FUNCTION - constexpr - index_type extent(size_t n) const noexcept { + constexpr index_type extent(size_t n) const noexcept { return __storage().__get(n); } //-------------------------------------------------------------------------------- - template - MDSPAN_INLINE_FUNCTION - friend constexpr bool operator==(extents const& lhs, extents const& rhs) noexcept { + template + MDSPAN_INLINE_FUNCTION friend constexpr bool + operator==(extents const &lhs, extents const &rhs) noexcept { return lhs._eq_impl( - rhs, std::integral_constant{}, - make_index_sequence{} - ); + rhs, std::integral_constant{}, + make_index_sequence{}); } - template - MDSPAN_INLINE_FUNCTION - friend constexpr bool operator!=(extents const& lhs, extents const& rhs) noexcept { + template + MDSPAN_INLINE_FUNCTION friend constexpr bool + operator!=(extents const &lhs, extents const &rhs) noexcept { return lhs._not_eq_impl( - rhs, std::integral_constant{}, - make_index_sequence{} - ); + rhs, std::integral_constant{}, + make_index_sequence{}); } -public: // (but not really) - - MDSPAN_INLINE_FUNCTION static constexpr - extents __make_extents_impl(detail::__partially_static_sizes&& __bs) noexcept { +public: // (but not really) + MDSPAN_INLINE_FUNCTION static constexpr extents __make_extents_impl( + detail::__partially_static_sizes &&__bs) noexcept { // This effectively amounts to a sideways cast that can be done in a constexpr // context, but we have to do it to handle the case where the extents and the // strides could accidentally end up with the same types in their hierarchies // somehow (which would cause layout_stride::mapping to not be standard_layout) - return extents(__base_t{::std::move(__bs.template __with_tag())}); + return extents(__base_t{ + ::std::move(__bs.template __with_tag())}); } template - MDSPAN_FORCE_INLINE_FUNCTION - constexpr - index_type __extent() const noexcept { + MDSPAN_FORCE_INLINE_FUNCTION constexpr index_type __extent() const noexcept { return __storage().template __get_n(); } - template - MDSPAN_INLINE_FUNCTION - static constexpr - index_type __static_extent() noexcept { + template + MDSPAN_INLINE_FUNCTION static constexpr index_type + __static_extent() noexcept { return __base_t::__stored_type::template __get_static_n(); } - }; } // end namespace experimental diff --git a/src/experimental/__p0009_bits/fixed_layout_impl.hpp b/src/experimental/__p0009_bits/fixed_layout_impl.hpp index 2455d74830..a51a0eee5c 100644 --- a/src/experimental/__p0009_bits/fixed_layout_impl.hpp +++ b/src/experimental/__p0009_bits/fixed_layout_impl.hpp @@ -45,13 +45,13 @@ #include "macros.hpp" -#include "static_array.hpp" #include "dynamic_extent.hpp" #include "extents.hpp" +#include "static_array.hpp" #include "trait_backports.hpp" -#include #include +#include //============================================================================================================== @@ -65,29 +65,37 @@ namespace detail { template struct stride_storage_impl; template -struct stride_storage_impl, integer_sequence, IdxConditional> - : __no_unique_address_emulation> -{ +struct stride_storage_impl, + integer_sequence, IdxConditional> + : __no_unique_address_emulation> { protected: - using __base_t = __no_unique_address_emulation>; -public: + using __base_t = + __no_unique_address_emulation>; +public: using extents_type = experimental::extents; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr stride_storage_impl() noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr stride_storage_impl(stride_storage_impl const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr stride_storage_impl(stride_storage_impl&&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED stride_storage_impl& operator=(stride_storage_impl const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED stride_storage_impl& operator=(stride_storage_impl&&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr stride_storage_impl() noexcept = + default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr stride_storage_impl( + stride_storage_impl const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr stride_storage_impl( + stride_storage_impl &&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED + _MDSPAN_CONSTEXPR_14_DEFAULTED stride_storage_impl & + operator=(stride_storage_impl const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED + _MDSPAN_CONSTEXPR_14_DEFAULTED stride_storage_impl & + operator=(stride_storage_impl &&) noexcept = default; MDSPAN_INLINE_FUNCTION_DEFAULTED ~stride_storage_impl() noexcept = default; // The layouts need to be implicitly convertible from extents (as currently specified), // which means we need to make this not explicit here // TODO @proposal-bug make this explicit? MDSPAN_INLINE_FUNCTION - constexpr /* implicit */ stride_storage_impl(extents_type const& __exts) noexcept - : __base_t(__base_t{__exts}) - { } + constexpr /* implicit */ stride_storage_impl( + extents_type const &__exts) noexcept + : __base_t(__base_t{__exts}) {} // The layouts need to be implicitly convertible from extents (as currently specified), // which means we need to make this not explicit here @@ -98,66 +106,85 @@ struct stride_storage_impl, integer_sequence // { } template - MDSPAN_FORCE_INLINE_FUNCTION - constexpr ptrdiff_t get_stride() const noexcept { + MDSPAN_FORCE_INLINE_FUNCTION constexpr ptrdiff_t get_stride() const noexcept { return _MDSPAN_FOLD_TIMES_RIGHT( - (IdxConditional{}(Idxs, N) ? this->__base_t::__ref().template __extent() : 1), - /* * ... * */ 1 - ); + (IdxConditional{}(Idxs, N) + ? this->__base_t::__ref().template __extent() + : 1), + /* * ... * */ 1); } MDSPAN_INLINE_FUNCTION constexpr ptrdiff_t get_stride(size_t n) const noexcept { return _MDSPAN_FOLD_TIMES_RIGHT( - (IdxConditional{}(Idxs, n) ? this->__base_t::__ref().template __extent() : 1), - /* * ... * */ 1 - ); + (IdxConditional{}(Idxs, n) + ? this->__base_t::__ref().template __extent() + : 1), + /* * ... * */ 1); } - }; //============================================================================================================== -template -class fixed_layout_common_impl; +template class fixed_layout_common_impl; template -class fixed_layout_common_impl, integer_sequence, IdxConditional> - : protected stride_storage_impl, integer_sequence, IdxConditional> -{ +class fixed_layout_common_impl, + integer_sequence, + IdxConditional> + : protected stride_storage_impl, + integer_sequence, + IdxConditional> { private: - - using base_t = stride_storage_impl, integer_sequence, IdxConditional>; + using base_t = + stride_storage_impl, + integer_sequence, IdxConditional>; public: - - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr fixed_layout_common_impl() noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr fixed_layout_common_impl(fixed_layout_common_impl const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr fixed_layout_common_impl(fixed_layout_common_impl&&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED fixed_layout_common_impl& operator=(fixed_layout_common_impl const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED fixed_layout_common_impl& operator=(fixed_layout_common_impl&&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED ~fixed_layout_common_impl() noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr fixed_layout_common_impl() noexcept = + default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr fixed_layout_common_impl( + fixed_layout_common_impl const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr fixed_layout_common_impl( + fixed_layout_common_impl &&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED + _MDSPAN_CONSTEXPR_14_DEFAULTED fixed_layout_common_impl & + operator=(fixed_layout_common_impl const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED + _MDSPAN_CONSTEXPR_14_DEFAULTED fixed_layout_common_impl & + operator=(fixed_layout_common_impl &&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED ~fixed_layout_common_impl() noexcept = + default; using base_t::base_t; - MDSPAN_INLINE_FUNCTION constexpr typename base_t::extents_type extents() const noexcept { + MDSPAN_INLINE_FUNCTION constexpr typename base_t::extents_type extents() const + noexcept { return typename base_t::extents_type(this->base_t::__ref()); }; template - MDSPAN_FORCE_INLINE_FUNCTION - constexpr ptrdiff_t operator()(Integral... idxs) const noexcept { - return _MDSPAN_FOLD_PLUS_RIGHT((idxs * this->base_t::template get_stride()), /* + ... + */ 0); + MDSPAN_FORCE_INLINE_FUNCTION constexpr ptrdiff_t + operator()(Integral... idxs) const noexcept { + return _MDSPAN_FOLD_PLUS_RIGHT( + (idxs * this->base_t::template get_stride()), /* + ... + */ 0); } MDSPAN_INLINE_FUNCTION constexpr ptrdiff_t required_span_size() const noexcept { - return _MDSPAN_FOLD_TIMES_RIGHT((base_t::__ref().template __extent()), /* * ... * */ 1); + return _MDSPAN_FOLD_TIMES_RIGHT((base_t::__ref().template __extent()), + /* * ... * */ 1); } - MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { return true; } - MDSPAN_INLINE_FUNCTION constexpr bool is_contiguous() const noexcept { return true; } - MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { return true; } + MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { + return true; + } + MDSPAN_INLINE_FUNCTION constexpr bool is_contiguous() const noexcept { + return true; + } + MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { + return true; + } MDSPAN_INLINE_FUNCTION constexpr ptrdiff_t stride(size_t r) const noexcept { @@ -166,31 +193,26 @@ class fixed_layout_common_impl, integer_sequ //-------------------------------------------------------------------------------- -public: // (but not really) - +public: // (but not really) template - MDSPAN_INLINE_FUNCTION - constexpr ptrdiff_t __stride() const noexcept { + MDSPAN_INLINE_FUNCTION constexpr ptrdiff_t __stride() const noexcept { return this->base_t::template get_stride(); } - template - struct __static_stride_workaround { + template struct __static_stride_workaround { static constexpr ptrdiff_t __result = _MDSPAN_FOLD_TIMES_RIGHT( - (IdxConditional{}(Idxs, N) ? - base_t::__stored_type::template __static_extent() : 1 - ), /* * ... * */ 1 - ); - static constexpr ptrdiff_t value = __result == 0 ? dynamic_extent : __result; + (IdxConditional{}(Idxs, N) + ? base_t::__stored_type::template __static_extent() + : 1), + /* * ... * */ 1); + static constexpr ptrdiff_t value = + __result == 0 ? dynamic_extent : __result; }; template - MDSPAN_INLINE_FUNCTION - static constexpr ptrdiff_t __static_stride() noexcept - { + MDSPAN_INLINE_FUNCTION static constexpr ptrdiff_t __static_stride() noexcept { return __static_stride_workaround::value; } - }; //============================================================================================================== diff --git a/src/experimental/__p0009_bits/layout_left.hpp b/src/experimental/__p0009_bits/layout_left.hpp index c3bf7cc3a1..1e381ae1ce 100644 --- a/src/experimental/__p0009_bits/layout_left.hpp +++ b/src/experimental/__p0009_bits/layout_left.hpp @@ -43,8 +43,8 @@ #pragma once -#include "macros.hpp" #include "fixed_layout_impl.hpp" +#include "macros.hpp" #include "trait_backports.hpp" namespace std { @@ -67,84 +67,88 @@ template class layout_left_impl; template class layout_left_impl> - : public fixed_layout_common_impl, make_index_sequence, layout_left_idx_conditional> -{ + : public fixed_layout_common_impl, + make_index_sequence, + layout_left_idx_conditional> { private: + using idx_seq = make_index_sequence; + using base_t = fixed_layout_common_impl, + make_index_sequence, + layout_left_idx_conditional>; -using idx_seq = make_index_sequence; - using base_t = fixed_layout_common_impl, make_index_sequence, layout_left_idx_conditional>; - - template - friend class layout_left_impl; + template friend class layout_left_impl; public: - //-------------------------------------------------------------------------------- - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_left_impl() noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_left_impl(layout_left_impl const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_left_impl(layout_left_impl&&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED layout_left_impl& operator=(layout_left_impl const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED layout_left_impl& operator=(layout_left_impl&&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_left_impl() noexcept = + default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_left_impl( + layout_left_impl const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_left_impl( + layout_left_impl &&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED + _MDSPAN_CONSTEXPR_14_DEFAULTED layout_left_impl & + operator=(layout_left_impl const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED + _MDSPAN_CONSTEXPR_14_DEFAULTED layout_left_impl & + operator=(layout_left_impl &&) noexcept = default; MDSPAN_INLINE_FUNCTION_DEFAULTED ~layout_left_impl() noexcept = default; using base_t::base_t; // TODO noexcept specification MDSPAN_TEMPLATE_REQUIRES( - class OtherExtents, - /* requires */ ( - _MDSPAN_TRAIT(is_convertible, OtherExtents, std::experimental::extents) - ) - ) + class OtherExtents, + /* requires */ (_MDSPAN_TRAIT(is_convertible, OtherExtents, + std::experimental::extents))) MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 - layout_left_impl(layout_left_impl const& other) // NOLINT(google-explicit-constructor) - : base_t(other.extents()) - { } - + layout_left_impl(layout_left_impl const + &other) // NOLINT(google-explicit-constructor) + : base_t(other.extents()) {} // TODO noexcept specification MDSPAN_TEMPLATE_REQUIRES( - class OtherExtents, - /* requires */ ( - _MDSPAN_TRAIT(is_convertible, OtherExtents, std::experimental::extents) - ) - ) - MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 - layout_left_impl& operator=(layout_left_impl const& other) - { + class OtherExtents, + /* requires */ (_MDSPAN_TRAIT(is_convertible, OtherExtents, + std::experimental::extents))) + MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 layout_left_impl & + operator=(layout_left_impl const &other) { this->base_t::__ref() = other.extents(); return *this; } //-------------------------------------------------------------------------------- - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { return true; } - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_contiguous() noexcept { return true; } - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { return true; } + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { + return true; + } + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_contiguous() noexcept { + return true; + } + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { + return true; + } // TODO @proposal-bug these (and other analogous operators) should be non-member functions - template - MDSPAN_INLINE_FUNCTION - constexpr bool operator==(layout_left_impl const& other) const noexcept { + template + MDSPAN_INLINE_FUNCTION constexpr bool + operator==(layout_left_impl const &other) const noexcept { return this->base_t::extents() == other.extents(); } - template - MDSPAN_INLINE_FUNCTION - constexpr bool operator!=(layout_left_impl const& other) const noexcept { + template + MDSPAN_INLINE_FUNCTION constexpr bool + operator!=(layout_left_impl const &other) const noexcept { return this->base_t::extents() != other.extents(); } - }; -} // namespace detail +} // namespace detail //============================================================================== struct layout_left { - template - using mapping = detail::layout_left_impl; + template using mapping = detail::layout_left_impl; }; - } // end namespace experimental } // end namespace std \ No newline at end of file diff --git a/src/experimental/__p0009_bits/layout_right.hpp b/src/experimental/__p0009_bits/layout_right.hpp index 3ccf45c1de..b1937b900e 100644 --- a/src/experimental/__p0009_bits/layout_right.hpp +++ b/src/experimental/__p0009_bits/layout_right.hpp @@ -43,8 +43,8 @@ #pragma once -#include "macros.hpp" #include "fixed_layout_impl.hpp" +#include "macros.hpp" #include "trait_backports.hpp" namespace std { @@ -54,7 +54,6 @@ namespace experimental { namespace detail { - struct layout_right_idx_conditional { MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_right_idx_conditional() noexcept = default; @@ -68,73 +67,80 @@ template class layout_right_impl; template class layout_right_impl> - : public fixed_layout_common_impl, make_index_sequence, layout_right_idx_conditional> -{ + : public fixed_layout_common_impl, + make_index_sequence, + layout_right_idx_conditional> { private: - using idx_seq = make_index_sequence; - using base_t = fixed_layout_common_impl, make_index_sequence, layout_right_idx_conditional>; + using base_t = fixed_layout_common_impl, + make_index_sequence, + layout_right_idx_conditional>; - template - friend class layout_right_impl; + template friend class layout_right_impl; public: - //-------------------------------------------------------------------------------- - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_right_impl() noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_right_impl(layout_right_impl const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_right_impl(layout_right_impl&&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED layout_right_impl& operator=(layout_right_impl const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED layout_right_impl& operator=(layout_right_impl&&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_right_impl() noexcept = + default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_right_impl( + layout_right_impl const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_right_impl( + layout_right_impl &&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED + _MDSPAN_CONSTEXPR_14_DEFAULTED layout_right_impl & + operator=(layout_right_impl const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED + _MDSPAN_CONSTEXPR_14_DEFAULTED layout_right_impl & + operator=(layout_right_impl &&) noexcept = default; MDSPAN_INLINE_FUNCTION_DEFAULTED ~layout_right_impl() noexcept = default; using base_t::base_t; // TODO noexcept specification MDSPAN_TEMPLATE_REQUIRES( - class OtherExtents, - /* requires */ ( - _MDSPAN_TRAIT(is_convertible, OtherExtents, std::experimental::extents) - ) - ) + class OtherExtents, + /* requires */ (_MDSPAN_TRAIT(is_convertible, OtherExtents, + std::experimental::extents))) MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 - layout_right_impl(layout_right_impl const& other) // NOLINT(google-explicit-constructor) - : base_t(other.extents()) - { } + layout_right_impl(layout_right_impl const + &other) // NOLINT(google-explicit-constructor) + : base_t(other.extents()) {} // TODO noexcept specification MDSPAN_TEMPLATE_REQUIRES( - class OtherExtents, - /* requires */ ( - _MDSPAN_TRAIT(is_convertible, OtherExtents, std::experimental::extents) - ) - ) - MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 - layout_right_impl& operator=(layout_right_impl const& other) - { + class OtherExtents, + /* requires */ (_MDSPAN_TRAIT(is_convertible, OtherExtents, + std::experimental::extents))) + MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 layout_right_impl & + operator=(layout_right_impl const &other) { this->base_t::__ref() = other.extents(); return *this; } //-------------------------------------------------------------------------------- - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { return true; } - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_contiguous() noexcept { return true; } - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { return true; } + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { + return true; + } + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_contiguous() noexcept { + return true; + } + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { + return true; + } // TODO @proposal-bug these (and other analogous operators) should be non-member functions - template - MDSPAN_INLINE_FUNCTION - constexpr bool operator==(layout_right_impl const& other) const noexcept { + template + MDSPAN_INLINE_FUNCTION constexpr bool + operator==(layout_right_impl const &other) const noexcept { return this->base_t::extents() == other.extents(); } - template - MDSPAN_INLINE_FUNCTION - constexpr bool operator!=(layout_right_impl const& other) const noexcept { + template + MDSPAN_INLINE_FUNCTION constexpr bool + operator!=(layout_right_impl const &other) const noexcept { return this->base_t::extents() != other.extents(); } - }; } // namespace detail @@ -142,10 +148,8 @@ class layout_right_impl> //============================================================================== struct layout_right { - template - using mapping = detail::layout_right_impl; + template using mapping = detail::layout_right_impl; }; - } // end namespace experimental } // end namespace std \ No newline at end of file diff --git a/src/experimental/__p0009_bits/layout_stride.hpp b/src/experimental/__p0009_bits/layout_stride.hpp index 54981b24b4..0078a790f3 100644 --- a/src/experimental/__p0009_bits/layout_stride.hpp +++ b/src/experimental/__p0009_bits/layout_stride.hpp @@ -43,15 +43,15 @@ #pragma once -#include "macros.hpp" +#include "extents.hpp" #include "fixed_layout_impl.hpp" +#include "macros.hpp" #include "static_array.hpp" -#include "extents.hpp" #include "trait_backports.hpp" #include -#include #include +#include namespace std { namespace experimental { @@ -63,19 +63,14 @@ namespace detail { template class layout_stride_impl; template -class layout_stride_impl< - std::experimental::extents, Strides... -> : private __no_unique_address_emulation< - __compressed_pair< - ::std::experimental::extents, - __partially_static_sizes - > - > -{ +class layout_stride_impl, Strides...> + : private __no_unique_address_emulation< + __compressed_pair<::std::experimental::extents, + __partially_static_sizes>> { public: using extents_type = experimental::extents; -private: +private: using idx_seq = make_index_sequence; //---------------------------------------------------------------------------- @@ -84,117 +79,118 @@ class layout_stride_impl< using __member_pair_t = __compressed_pair; using __base_t = __no_unique_address_emulation<__member_pair_t>; - MDSPAN_FORCE_INLINE_FUNCTION constexpr __strides_storage_t const& - __strides_storage() const noexcept { return this->__base_t::__ref().__second(); } - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 __strides_storage_t& - __strides_storage() noexcept { return this->__base_t::__ref().__second(); } + MDSPAN_FORCE_INLINE_FUNCTION constexpr __strides_storage_t const & + __strides_storage() const noexcept { + return this->__base_t::__ref().__second(); + } + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 __strides_storage_t & + __strides_storage() noexcept { + return this->__base_t::__ref().__second(); + } //---------------------------------------------------------------------------- - template - friend class layout_stride_impl; + template friend class layout_stride_impl; //---------------------------------------------------------------------------- // Workaround for non-deducibility of the index sequence template parameter if it's given at the top level - template > - struct __impl; + template > struct __impl; - template - struct __impl> - { + template struct __impl> { template - MDSPAN_INLINE_FUNCTION - static constexpr bool _eq_impl(layout_stride_impl const& self, layout_stride_impl const& other) noexcept { - return _MDSPAN_FOLD_AND((self.template __stride() == other.template __stride()) /* && ... */); + MDSPAN_INLINE_FUNCTION static constexpr bool + _eq_impl(layout_stride_impl const &self, + layout_stride_impl const + &other) noexcept { + return _MDSPAN_FOLD_AND((self.template __stride() == + other.template __stride()) /* && ... */); } template - MDSPAN_INLINE_FUNCTION - static constexpr bool _not_eq_impl(layout_stride_impl const& self, layout_stride_impl const& other) noexcept { - return _MDSPAN_FOLD_OR((self.template __stride() != other.template __stride()) /* || ... */); + MDSPAN_INLINE_FUNCTION static constexpr bool + _not_eq_impl(layout_stride_impl const &self, + layout_stride_impl const + &other) noexcept { + return _MDSPAN_FOLD_OR((self.template __stride() != + other.template __stride()) /* || ... */); } template - MDSPAN_FORCE_INLINE_FUNCTION - static constexpr ptrdiff_t _call_op_impl(layout_stride_impl const& self, Integral... idxs) noexcept { - return _MDSPAN_FOLD_PLUS_RIGHT((idxs * self.template __stride()), /* + ... + */ 0); + MDSPAN_FORCE_INLINE_FUNCTION static constexpr ptrdiff_t + _call_op_impl(layout_stride_impl const &self, Integral... idxs) noexcept { + return _MDSPAN_FOLD_PLUS_RIGHT((idxs * self.template __stride()), + /* + ... + */ 0); } MDSPAN_INLINE_FUNCTION - static constexpr size_t _req_span_size_impl(layout_stride_impl const& self) noexcept { + static constexpr size_t + _req_span_size_impl(layout_stride_impl const &self) noexcept { // assumes no negative strides; not sure if I'm allowed to assume that or not - return __impl::_call_op_impl(self, (self.extents().template __extent() - 1)...) + 1; + return __impl::_call_op_impl( + self, (self.extents().template __extent() - 1)...) + + 1; } }; //---------------------------------------------------------------------------- - MDSPAN_INLINE_FUNCTION constexpr explicit - layout_stride_impl( - __base_t&& __b - ) : __base_t(::std::move(__b)) {} + MDSPAN_INLINE_FUNCTION constexpr explicit layout_stride_impl(__base_t &&__b) + : __base_t(::std::move(__b)) {} //---------------------------------------------------------------------------- public: // (but not really) - template - MDSPAN_FORCE_INLINE_FUNCTION - constexpr ptrdiff_t __stride() const noexcept { + MDSPAN_FORCE_INLINE_FUNCTION constexpr ptrdiff_t __stride() const noexcept { return __strides_storage().template __get_n(); } - template - struct __static_stride_workaround { - static constexpr ptrdiff_t value = __strides_storage_t::template __get_static_n(); + template struct __static_stride_workaround { + static constexpr ptrdiff_t value = + __strides_storage_t::template __get_static_n(); }; template - MDSPAN_INLINE_FUNCTION - static constexpr ptrdiff_t __static_stride() noexcept - { + MDSPAN_INLINE_FUNCTION static constexpr ptrdiff_t __static_stride() noexcept { return __strides_storage_t::template __get_static_n(); } MDSPAN_INLINE_FUNCTION - static constexpr layout_stride_impl - __make_layout_stride_impl( - __partially_static_sizes&& __exts, - __partially_static_sizes&& __strs - ) noexcept { + static constexpr layout_stride_impl __make_layout_stride_impl( + __partially_static_sizes &&__exts, + __partially_static_sizes &&__strs) noexcept { // call the private constructor we created for this purpose - return layout_stride_impl( - __base_t{ - __member_pair_t( - extents_type::__make_extents_impl(::std::move(__exts)), - ::std::move(__strs) - ) - } - ); + return layout_stride_impl(__base_t{ + __member_pair_t(extents_type::__make_extents_impl(::std::move(__exts)), + ::std::move(__strs))}); } public: - //-------------------------------------------------------------------------------- - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_stride_impl() noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_stride_impl(layout_stride_impl const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_stride_impl(layout_stride_impl&&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED - layout_stride_impl& operator=(layout_stride_impl const&) noexcept = default; - MDSPAN_INLINE_FUNCTION_DEFAULTED _MDSPAN_CONSTEXPR_14_DEFAULTED - layout_stride_impl& operator=(layout_stride_impl&&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_stride_impl() noexcept = + default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_stride_impl( + layout_stride_impl const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr layout_stride_impl( + layout_stride_impl &&) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED + _MDSPAN_CONSTEXPR_14_DEFAULTED layout_stride_impl & + operator=(layout_stride_impl const &) noexcept = default; + MDSPAN_INLINE_FUNCTION_DEFAULTED + _MDSPAN_CONSTEXPR_14_DEFAULTED layout_stride_impl & + operator=(layout_stride_impl &&) noexcept = default; MDSPAN_INLINE_FUNCTION_DEFAULTED ~layout_stride_impl() noexcept = default; // TODO @proposal-bug layout stride needs this constructor MDSPAN_INLINE_FUNCTION - constexpr - layout_stride_impl( - std::experimental::extents const& e, - array const& strides - ) noexcept - : __base_t(__base_t{__member_pair_t(e, __strides_storage_t(__construct_psa_from_dynamic_values_tag_t<>{}, strides))}) - { } + constexpr layout_stride_impl( + std::experimental::extents const &e, + array const + &strides) noexcept + : __base_t(__base_t{__member_pair_t( + e, __strides_storage_t( + __construct_psa_from_dynamic_values_tag_t<>{}, strides))}) {} // TODO @proposal-bug @proposal-extension layout stride needs this constructor // clang-format off @@ -214,7 +210,7 @@ class layout_stride_impl< { } // clang-format on -// TODO conversion constructors and assignment + // TODO conversion constructors and assignment //-------------------------------------------------------------------------------- @@ -222,59 +218,65 @@ class layout_stride_impl< return this->__base_t::__ref().__first(); }; - MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { return true; } + MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { + return true; + } // TODO @proposal-bug this wording for this is (at least slightly) broken (should at least be "... stride(p[0]) == 1...") - MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 bool is_contiguous() const noexcept { + MDSPAN_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 bool is_contiguous() const + noexcept { // TODO @testing test layout_stride is_contiguous() - auto rem = array{ }; + auto rem = array{}; std::iota(rem.begin(), rem.end(), ptrdiff_t(0)); auto next_idx_iter = std::find_if( - rem.begin(), rem.end(), - [&](ptrdiff_t i) { this->stride(i) == 1; } - ); - if(next_idx_iter != rem.end()) { + rem.begin(), rem.end(), [&](ptrdiff_t i) { this->stride(i) == 1; }); + if (next_idx_iter != rem.end()) { ptrdiff_t prev_stride_times_prev_extent = - this->extents().extent(*next_idx_iter) * this->stride(*next_idx_iter); + this->extents().extent(*next_idx_iter) * this->stride(*next_idx_iter); // "remove" the index constexpr ptrdiff_t removed_index_sentinel = -1; *next_idx_iter = removed_index_sentinel; int found_count = 1; while (found_count != sizeof...(Exts)) { - next_idx_iter = std::find_if( - rem.begin(), rem.end(), - [&](ptrdiff_t i) { - return i != removed_index_sentinel - && this->stride(i) * this->extents().extent(i) == prev_stride_times_prev_extent; - } - ); + next_idx_iter = std::find_if(rem.begin(), rem.end(), [&](ptrdiff_t i) { + return i != removed_index_sentinel && + this->stride(i) * this->extents().extent(i) == + prev_stride_times_prev_extent; + }); if (next_idx_iter != rem.end()) { // "remove" the index *next_idx_iter = removed_index_sentinel; ++found_count; - prev_stride_times_prev_extent = stride(*next_idx_iter) * this->extents().extent(*next_idx_iter); - } else { break; } + prev_stride_times_prev_extent = + stride(*next_idx_iter) * this->extents().extent(*next_idx_iter); + } else { + break; + } } return found_count == sizeof...(Exts); } return false; } - MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { return true; } + MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { + return true; + } - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { return true; } + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { + return true; + } MDSPAN_INLINE_FUNCTION static constexpr bool is_always_contiguous() noexcept { // TODO @proposal-bug this will need to be updated with the incorporation of static strides into the layout stride definition // TODO this should actually check whether we know statically from the strides if this is always contiguous return false; } - MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { return true; } + MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { + return true; + } MDSPAN_TEMPLATE_REQUIRES( - class... Indices, - /* requires */ ( - sizeof...(Indices) == sizeof...(Exts) && - _MDSPAN_FOLD_AND(_MDSPAN_TRAIT(is_constructible, Indices, ptrdiff_t) /*&& ...*/) - ) - ) + class... Indices, + /* requires */ (sizeof...(Indices) == sizeof...(Exts) && + _MDSPAN_FOLD_AND(_MDSPAN_TRAIT(is_constructible, Indices, + ptrdiff_t) /*&& ...*/))) MDSPAN_FORCE_INLINE_FUNCTION constexpr ptrdiff_t operator()(Indices... idxs) const noexcept { return __impl<>::_call_op_impl(*this, idxs...); @@ -294,32 +296,29 @@ class layout_stride_impl< // TODO @proposal-bug these (and other analogous operators) should be non-member functions // TODO @proposal-bug these should do more than just compare extents! - template - MDSPAN_INLINE_FUNCTION - constexpr bool operator==(layout_stride_impl const& other) const noexcept { + template + MDSPAN_INLINE_FUNCTION constexpr bool operator==( + layout_stride_impl const &other) + const noexcept { return __impl<>::_eq_impl(*this, other); } - template - MDSPAN_INLINE_FUNCTION - constexpr bool operator!=(layout_stride_impl const& other) const noexcept { + template + MDSPAN_INLINE_FUNCTION constexpr bool operator!=( + layout_stride_impl const &other) + const noexcept { return __impl<>::_not_eq_impl(*this, other); } - }; } // namespace detail //============================================================================== - // TODO @proposal-bug layout_stride needs these non-type template parameters -template -struct layout_stride { +template struct layout_stride { template - using mapping = detail::layout_stride_impl< - Extents, StaticStrides... - >; + using mapping = detail::layout_stride_impl; }; } // end namespace experimental diff --git a/src/experimental/__p0009_bits/macros.hpp b/src/experimental/__p0009_bits/macros.hpp index bef124f89f..a42414798a 100644 --- a/src/experimental/__p0009_bits/macros.hpp +++ b/src/experimental/__p0009_bits/macros.hpp @@ -41,7 +41,6 @@ //@HEADER */ - #pragma once #include "config.hpp" @@ -49,87 +48,75 @@ #include // std::is_void #ifndef MDSPAN_FORCE_INLINE_FUNCTION -# ifdef _MSC_VER // Microsoft compilers -# define MDSPAN_FORCE_INLINE_FUNCTION __forceinline -# elif defined(__CUDA_ARCH__) -# define MDSPAN_FORCE_INLINE_FUNCTION __attribute__((always_inline)) __host__ __device__ -# else -# define MDSPAN_FORCE_INLINE_FUNCTION __attribute__((always_inline)) -# endif +#ifdef _MSC_VER // Microsoft compilers +#define MDSPAN_FORCE_INLINE_FUNCTION __forceinline +#elif defined(__CUDA_ARCH__) +#define MDSPAN_FORCE_INLINE_FUNCTION \ + __attribute__((always_inline)) __host__ __device__ +#else +#define MDSPAN_FORCE_INLINE_FUNCTION __attribute__((always_inline)) +#endif #endif #ifndef MDSPAN_INLINE_FUNCTION -# if defined(__CUDA_ARCH__) -# define MDSPAN_INLINE_FUNCTION inline __host__ __device__ -# else -# define MDSPAN_INLINE_FUNCTION inline -# endif +#if defined(__CUDA_ARCH__) +#define MDSPAN_INLINE_FUNCTION inline __host__ __device__ +#else +#define MDSPAN_INLINE_FUNCTION inline +#endif #endif #ifndef MDSPAN_INLINE_FUNCTION_DEFAULTED -# define MDSPAN_INLINE_FUNCTION_DEFAULTED inline +#define MDSPAN_INLINE_FUNCTION_DEFAULTED inline #endif //============================================================================== // {{{1 - #ifdef _MSC_VER // Microsoft compilers -#define MDSPAN_PP_COUNT(...) \ - _MDSPAN_PP_INTERNAL_EXPAND_ARGS_PRIVATE( \ - _MDSPAN_PP_INTERNAL_ARGS_AUGMENTER(__VA_ARGS__) \ - ) +#define MDSPAN_PP_COUNT(...) \ + _MDSPAN_PP_INTERNAL_EXPAND_ARGS_PRIVATE( \ + _MDSPAN_PP_INTERNAL_ARGS_AUGMENTER(__VA_ARGS__)) #define _MDSPAN_PP_INTERNAL_ARGS_AUGMENTER(...) unused, __VA_ARGS__ #define _MDSPAN_PP_INTERNAL_EXPAND(x) x -#define _MDSPAN_PP_INTERNAL_EXPAND_ARGS_PRIVATE(...) \ - _MDSPAN_PP_INTERNAL_EXPAND( \ - _MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ - __VA_ARGS__, 69, 68, 67, 66, 65, 64, 63, 62, 61, \ - 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, \ - 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, \ - 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, \ - 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, \ - 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 \ - ) \ - ) -# define _MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ - _1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, \ - _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ - _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ - _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, \ - _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, \ - _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, \ - _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, \ - _70, count, ...) count \ - /**/ +#define _MDSPAN_PP_INTERNAL_EXPAND_ARGS_PRIVATE(...) \ + _MDSPAN_PP_INTERNAL_EXPAND(_MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ + __VA_ARGS__, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, \ + 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, \ + 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, \ + 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define _MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ + _1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, _10, _11, _12, _13, _14, _15, \ + _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ + _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, \ + _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \ + _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, count, ...) \ + count /**/ #else // Non-Microsoft compilers -# define MDSPAN_PP_COUNT(...) \ - _MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ - 0, ## __VA_ARGS__, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \ - 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, \ - 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \ - 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, \ - 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) \ - /**/ -# define _MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ - _0_, _1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, \ - _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \ - _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ - _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, \ - _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, \ - _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, \ - _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, \ - _70, count, ...) count \ - /**/ +#define MDSPAN_PP_COUNT(...) \ + _MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ + 0, ##__VA_ARGS__, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, \ + 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \ + 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, \ + 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, \ + 1, 0) \ + /**/ +#define _MDSPAN_PP_INTERNAL_COUNT_PRIVATE( \ + _0_, _1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, _10, _11, _12, _13, _14, \ + _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, \ + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, \ + _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, \ + _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, count, ...) \ + count /**/ #endif #define MDSPAN_PP_STRINGIFY_IMPL(x) #x #define MDSPAN_PP_STRINGIFY(x) MDSPAN_PP_STRINGIFY_IMPL(x) -#define MDSPAN_PP_CAT_IMPL(x, y) x ## y +#define MDSPAN_PP_CAT_IMPL(x, y) x##y #define MDSPAN_PP_CAT(x, y) MDSPAN_PP_CAT_IMPL(x, y) #define MDSPAN_PP_EVAL(X, ...) X(__VA_ARGS__) @@ -146,63 +133,50 @@ // These compatibility macros don't help with partial ordering, but they should do the trick // for what we need to do with concepts in mdspan #ifdef _MDSPAN_USE_CONCEPTS -# define MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) > requires REQ -# define MDSPAN_FUNCTION_REQUIRES(PAREN_PREQUALS, FNAME, PAREN_PARAMS, QUALS, REQ) \ - MDSPAN_PP_REMOVE_PARENS(PAREN_PREQUALS) FNAME PAREN_PARAMS QUALS requires REQ \ - /**/ +#define MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) > requires REQ +#define MDSPAN_FUNCTION_REQUIRES(PAREN_PREQUALS, FNAME, PAREN_PARAMS, QUALS, \ + REQ) \ + MDSPAN_PP_REMOVE_PARENS(PAREN_PREQUALS) \ + FNAME PAREN_PARAMS QUALS requires REQ /**/ #else -# define MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) , typename ::std::enable_if<(REQ), int>::type = 0> -# define MDSPAN_FUNCTION_REQUIRES(PAREN_PREQUALS, FNAME, PAREN_PARAMS, QUALS, REQ) \ - MDSPAN_TEMPLATE_REQUIRES( \ - class __function_requires_ignored=void, \ - (std::is_void<__function_requires_ignored>::value && REQ) \ - ) MDSPAN_PP_REMOVE_PARENS(PAREN_PREQUALS) FNAME PAREN_PARAMS QUALS \ - /**/ +#define MDSPAN_CLOSE_ANGLE_REQUIRES(REQ) \ + , typename ::std::enable_if<(REQ), int>::type = 0 > +#define MDSPAN_FUNCTION_REQUIRES(PAREN_PREQUALS, FNAME, PAREN_PARAMS, QUALS, \ + REQ) \ + MDSPAN_TEMPLATE_REQUIRES( \ + class __function_requires_ignored = void, \ + (std::is_void<__function_requires_ignored>::value && REQ)) \ + MDSPAN_PP_REMOVE_PARENS(PAREN_PREQUALS) FNAME PAREN_PARAMS QUALS /**/ #endif - #ifdef _MSC_VER -# define MDSPAN_TEMPLATE_REQUIRES(...) \ - MDSPAN_PP_CAT( \ - MDSPAN_PP_CAT(MDSPAN_TEMPLATE_REQUIRES_, MDSPAN_PP_COUNT(__VA_ARGS__))\ - (__VA_ARGS__), \ - ) \ - /**/ +#define MDSPAN_TEMPLATE_REQUIRES(...) \ + MDSPAN_PP_CAT(MDSPAN_PP_CAT(MDSPAN_TEMPLATE_REQUIRES_, \ + MDSPAN_PP_COUNT(__VA_ARGS__))(__VA_ARGS__), ) \ + /**/ #else -# define MDSPAN_TEMPLATE_REQUIRES(...) \ - MDSPAN_PP_EVAL( \ - MDSPAN_PP_CAT(MDSPAN_TEMPLATE_REQUIRES_, MDSPAN_PP_COUNT(__VA_ARGS__)), \ - __VA_ARGS__ \ - ) \ - /**/ +#define MDSPAN_TEMPLATE_REQUIRES(...) \ + MDSPAN_PP_EVAL( \ + MDSPAN_PP_CAT(MDSPAN_TEMPLATE_REQUIRES_, MDSPAN_PP_COUNT(__VA_ARGS__)), \ + __VA_ARGS__) \ + /**/ #endif -#define MDSPAN_TEMPLATE_REQUIRES_2(TP1, REQ) \ - template end Concept emulation }}}1 @@ -212,9 +186,9 @@ // {{{1 #if _MDSPAN_USE_INLINE_VARIABLES -# define _MDSPAN_INLINE_VARIABLE inline +#define _MDSPAN_INLINE_VARIABLE inline #else -# define _MDSPAN_INLINE_VARIABLE +#define _MDSPAN_INLINE_VARIABLE #endif // end inline variables }}}1 @@ -224,19 +198,24 @@ // {{{1 #if _MDSPAN_USE_RETURN_TYPE_DEDUCTION -# define _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ - auto MDSPAN_PP_REMOVE_PARENS(SIGNATURE) { return MDSPAN_PP_REMOVE_PARENS(BODY); } -# define _MDSPAN_DEDUCE_DECLTYPE_AUTO_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ - decltype(auto) MDSPAN_PP_REMOVE_PARENS(SIGNATURE) { return MDSPAN_PP_REMOVE_PARENS(BODY); } +#define _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ + auto MDSPAN_PP_REMOVE_PARENS(SIGNATURE) { \ + return MDSPAN_PP_REMOVE_PARENS(BODY); \ + } +#define _MDSPAN_DEDUCE_DECLTYPE_AUTO_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ + decltype(auto) MDSPAN_PP_REMOVE_PARENS(SIGNATURE) { \ + return MDSPAN_PP_REMOVE_PARENS(BODY); \ + } #else -# define _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ - auto MDSPAN_PP_REMOVE_PARENS(SIGNATURE) \ - -> typename std::remove_cv::type>::type \ - { return MDSPAN_PP_REMOVE_PARENS(BODY); } -# define _MDSPAN_DEDUCE_DECLTYPE_AUTO_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ - auto MDSPAN_PP_REMOVE_PARENS(SIGNATURE) \ - -> decltype(BODY) \ - { return MDSPAN_PP_REMOVE_PARENS(BODY); } +#define _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ + auto MDSPAN_PP_REMOVE_PARENS(SIGNATURE)->typename std:: \ + remove_cv::type>::type { \ + return MDSPAN_PP_REMOVE_PARENS(BODY); \ + } +#define _MDSPAN_DEDUCE_DECLTYPE_AUTO_RETURN_TYPE_SINGLE_LINE(SIGNATURE, BODY) \ + auto MDSPAN_PP_REMOVE_PARENS(SIGNATURE)->decltype(BODY) { \ + return MDSPAN_PP_REMOVE_PARENS(BODY); \ + } #endif @@ -246,17 +225,17 @@ //============================================================================== // {{{1 -struct __mdspan_enable_fold_comma { }; +struct __mdspan_enable_fold_comma {}; #ifdef _MDSPAN_USE_FOLD_EXPRESSIONS -# define _MDSPAN_FOLD_AND(...) ((__VA_ARGS__) && ...) -# define _MDSPAN_FOLD_AND_TEMPLATE(...) ((__VA_ARGS__) && ...) -# define _MDSPAN_FOLD_OR(...) ((__VA_ARGS__) || ...) -# define _MDSPAN_FOLD_ASSIGN_LEFT(INIT, ...) (INIT = ... = (__VA_ARGS__)) -# define _MDSPAN_FOLD_ASSIGN_RIGHT(PACK, ...) (PACK = ... = (__VA_ARGS__)) -# define _MDSPAN_FOLD_TIMES_RIGHT(PACK, ...) (PACK * ... * (__VA_ARGS__)) -# define _MDSPAN_FOLD_PLUS_RIGHT(PACK, ...) (PACK + ... + (__VA_ARGS__)) -# define _MDSPAN_FOLD_COMMA(...) ((__VA_ARGS__), ...) +#define _MDSPAN_FOLD_AND(...) ((__VA_ARGS__) && ...) +#define _MDSPAN_FOLD_AND_TEMPLATE(...) ((__VA_ARGS__) && ...) +#define _MDSPAN_FOLD_OR(...) ((__VA_ARGS__) || ...) +#define _MDSPAN_FOLD_ASSIGN_LEFT(INIT, ...) (INIT = ... = (__VA_ARGS__)) +#define _MDSPAN_FOLD_ASSIGN_RIGHT(PACK, ...) (PACK = ... = (__VA_ARGS__)) +#define _MDSPAN_FOLD_TIMES_RIGHT(PACK, ...) (PACK * ... * (__VA_ARGS__)) +#define _MDSPAN_FOLD_PLUS_RIGHT(PACK, ...) (PACK + ... + (__VA_ARGS__)) +#define _MDSPAN_FOLD_COMMA(...) ((__VA_ARGS__), ...) #else namespace std { @@ -269,73 +248,75 @@ namespace __fold_compatibility_impl { #if _MDSPAN_USE_RETURN_TYPE_DEDUCTION MDSPAN_FORCE_INLINE_FUNCTION -constexpr decltype(auto) __fold_right_and_impl() { - return true; -} +constexpr decltype(auto) __fold_right_and_impl() { return true; } template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr decltype(auto) __fold_right_and_impl(Arg&& arg, Args&&... args) { - return ((Arg&&)arg) && __fold_compatibility_impl::__fold_right_and_impl((Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr decltype(auto) +__fold_right_and_impl(Arg &&arg, Args &&... args) { + return ((Arg &&) arg) && + __fold_compatibility_impl::__fold_right_and_impl((Args &&) args...); } MDSPAN_FORCE_INLINE_FUNCTION -constexpr decltype(auto) __fold_right_or_impl() { - return false; -} +constexpr decltype(auto) __fold_right_or_impl() { return false; } template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr auto __fold_right_or_impl(Arg&& arg, Args&&... args) { - return ((Arg&&)arg) || __fold_compatibility_impl::__fold_right_or_impl((Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr auto +__fold_right_or_impl(Arg &&arg, Args &&... args) { + return ((Arg &&) arg) || + __fold_compatibility_impl::__fold_right_or_impl((Args &&) args...); } template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr auto __fold_left_assign_impl(Arg1&& arg1) { - return (Arg1&&)arg1; +MDSPAN_FORCE_INLINE_FUNCTION constexpr auto +__fold_left_assign_impl(Arg1 &&arg1) { + return (Arg1 &&) arg1; } template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr auto __fold_left_assign_impl(Arg1&& arg1, Arg2&& arg2, Args&&... args) { - return __fold_compatibility_impl::__fold_left_assign_impl((((Arg1&&)arg1) = ((Arg2&&)arg2)), (Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr auto +__fold_left_assign_impl(Arg1 &&arg1, Arg2 &&arg2, Args &&... args) { + return __fold_compatibility_impl::__fold_left_assign_impl( + (((Arg1 &&) arg1) = ((Arg2 &&) arg2)), (Args &&) args...); } template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr auto __fold_right_assign_impl(Arg1&& arg1) { - return (Arg1&&)arg1; +MDSPAN_FORCE_INLINE_FUNCTION constexpr auto +__fold_right_assign_impl(Arg1 &&arg1) { + return (Arg1 &&) arg1; } template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr auto __fold_right_assign_impl(Arg1&& arg1, Arg2&& arg2, Args&&... args) { - return ((Arg1&&)arg1) = __fold_compatibility_impl::__fold_right_assign_impl((Arg2&&)arg2, (Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr auto +__fold_right_assign_impl(Arg1 &&arg1, Arg2 &&arg2, Args &&... args) { + return ((Arg1 &&) arg1) = __fold_compatibility_impl::__fold_right_assign_impl( + (Arg2 &&) arg2, (Args &&) args...); } template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr auto __fold_right_plus_impl(Arg1&& arg1) { - return (Arg1&&)arg1; +MDSPAN_FORCE_INLINE_FUNCTION constexpr auto +__fold_right_plus_impl(Arg1 &&arg1) { + return (Arg1 &&) arg1; } template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr auto __fold_right_plus_impl(Arg1&& arg1, Arg2&& arg2, Args&&... args) { - return ((Arg1&&)arg1) + __fold_compatibility_impl::__fold_right_plus_impl((Arg2&&)arg2, (Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr auto +__fold_right_plus_impl(Arg1 &&arg1, Arg2 &&arg2, Args &&... args) { + return ((Arg1 &&) arg1) + __fold_compatibility_impl::__fold_right_plus_impl( + (Arg2 &&) arg2, (Args &&) args...); } template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr auto __fold_right_times_impl(Arg1&& arg1) { - return (Arg1&&)arg1; +MDSPAN_FORCE_INLINE_FUNCTION constexpr auto +__fold_right_times_impl(Arg1 &&arg1) { + return (Arg1 &&) arg1; } template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr auto __fold_right_times_impl(Arg1&& arg1, Arg2&& arg2, Args&&... args) { - return ((Arg1&&)arg1) * __fold_compatibility_impl::__fold_right_times_impl((Arg2&&)arg2, (Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr auto +__fold_right_times_impl(Arg1 &&arg1, Arg2 &&arg2, Args &&... args) { + return ((Arg1 &&) arg1) * __fold_compatibility_impl::__fold_right_times_impl( + (Arg2 &&) arg2, (Args &&) args...); } #else @@ -343,33 +324,28 @@ constexpr auto __fold_right_times_impl(Arg1&& arg1, Arg2&& arg2, Args&&... args) //------------------------------------------------------------------------------ // {{{2 -template -struct __fold_right_and_impl_; -template <> -struct __fold_right_and_impl_<> { +template struct __fold_right_and_impl_; +template <> struct __fold_right_and_impl_<> { using __rv = bool; MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl() noexcept { - return true; - } + static constexpr __rv __impl() noexcept { return true; } }; template struct __fold_right_and_impl_ { using __next_t = __fold_right_and_impl_; - using __rv = decltype(std::declval() && std::declval()); + using __rv = + decltype(std::declval() && std::declval()); MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl(Arg&& arg, Args&&... args) noexcept { - return ((Arg&&)arg) && __next_t::__impl((Args&&)args...); + static constexpr __rv __impl(Arg &&arg, Args &&... args) noexcept { + return ((Arg &&) arg) && __next_t::__impl((Args &&) args...); } }; template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr typename __fold_right_and_impl_::__rv -__fold_right_and_impl(Args&&... args) { - return __fold_right_and_impl_::__impl((Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr + typename __fold_right_and_impl_::__rv + __fold_right_and_impl(Args &&... args) { + return __fold_right_and_impl_::__impl((Args &&) args...); } // end right and }}}2 @@ -378,33 +354,27 @@ __fold_right_and_impl(Args&&... args) { //------------------------------------------------------------------------------ // {{{2 -template -struct __fold_right_or_impl_; -template <> -struct __fold_right_or_impl_<> { +template struct __fold_right_or_impl_; +template <> struct __fold_right_or_impl_<> { using __rv = bool; MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl() noexcept { - return false; - } + static constexpr __rv __impl() noexcept { return false; } }; -template -struct __fold_right_or_impl_ { +template struct __fold_right_or_impl_ { using __next_t = __fold_right_or_impl_; - using __rv = decltype(std::declval() || std::declval()); + using __rv = + decltype(std::declval() || std::declval()); MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl(Arg&& arg, Args&&... args) noexcept { - return ((Arg&&)arg) || __next_t::__impl((Args&&)args...); + static constexpr __rv __impl(Arg &&arg, Args &&... args) noexcept { + return ((Arg &&) arg) || __next_t::__impl((Args &&) args...); } }; template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr typename __fold_right_or_impl_::__rv -__fold_right_or_impl(Args&&... args) { - return __fold_right_or_impl_::__impl((Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr + typename __fold_right_or_impl_::__rv + __fold_right_or_impl(Args &&... args) { + return __fold_right_or_impl_::__impl((Args &&) args...); } // end right or }}}2 @@ -413,33 +383,30 @@ __fold_right_or_impl(Args&&... args) { //------------------------------------------------------------------------------ // {{{2 -template -struct __fold_right_plus_impl_; -template -struct __fold_right_plus_impl_ { - using __rv = Arg&&; +template struct __fold_right_plus_impl_; +template struct __fold_right_plus_impl_ { + using __rv = Arg &&; MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl(Arg&& arg) noexcept { - return (Arg&&)arg; - } + static constexpr __rv __impl(Arg &&arg) noexcept { return (Arg &&) arg; } }; template struct __fold_right_plus_impl_ { using __next_t = __fold_right_plus_impl_; - using __rv = decltype(std::declval() + std::declval()); + using __rv = + decltype(std::declval() + std::declval()); MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl(Arg1&& arg, Arg2&& arg2, Args&&... args) noexcept { - return ((Arg1&&)arg) + __next_t::__impl((Arg2&&)arg2, (Args&&)args...); + static constexpr __rv __impl(Arg1 &&arg, Arg2 &&arg2, + Args &&... args) noexcept { + return ((Arg1 &&) arg) + + __next_t::__impl((Arg2 &&) arg2, (Args &&) args...); } }; template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr typename __fold_right_plus_impl_::__rv -__fold_right_plus_impl(Args&&... args) { - return __fold_right_plus_impl_::__impl((Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr + typename __fold_right_plus_impl_::__rv + __fold_right_plus_impl(Args &&... args) { + return __fold_right_plus_impl_::__impl((Args &&) args...); } // end right plus }}}2 @@ -448,33 +415,30 @@ __fold_right_plus_impl(Args&&... args) { //------------------------------------------------------------------------------ // {{{2 -template -struct __fold_right_times_impl_; -template -struct __fold_right_times_impl_ { - using __rv = Arg&&; +template struct __fold_right_times_impl_; +template struct __fold_right_times_impl_ { + using __rv = Arg &&; MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl(Arg&& arg) noexcept { - return (Arg&&)arg; - } + static constexpr __rv __impl(Arg &&arg) noexcept { return (Arg &&) arg; } }; template struct __fold_right_times_impl_ { using __next_t = __fold_right_times_impl_; - using __rv = decltype(std::declval() * std::declval()); + using __rv = + decltype(std::declval() * std::declval()); MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl(Arg1&& arg, Arg2&& arg2, Args&&... args) noexcept { - return ((Arg1&&)arg) * __next_t::__impl((Arg2&&)arg2, (Args&&)args...); + static constexpr __rv __impl(Arg1 &&arg, Arg2 &&arg2, + Args &&... args) noexcept { + return ((Arg1 &&) arg) * + __next_t::__impl((Arg2 &&) arg2, (Args &&) args...); } }; template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr typename __fold_right_times_impl_::__rv -__fold_right_times_impl(Args&&... args) { - return __fold_right_times_impl_::__impl((Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr + typename __fold_right_times_impl_::__rv + __fold_right_times_impl(Args &&... args) { + return __fold_right_times_impl_::__impl((Args &&) args...); } // end right times }}}2 @@ -483,33 +447,30 @@ __fold_right_times_impl(Args&&... args) { //------------------------------------------------------------------------------ // {{{2 -template -struct __fold_right_assign_impl_; -template -struct __fold_right_assign_impl_ { - using __rv = Arg&&; +template struct __fold_right_assign_impl_; +template struct __fold_right_assign_impl_ { + using __rv = Arg &&; MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl(Arg&& arg) noexcept { - return (Arg&&)arg; - } + static constexpr __rv __impl(Arg &&arg) noexcept { return (Arg &&) arg; } }; template struct __fold_right_assign_impl_ { using __next_t = __fold_right_assign_impl_; - using __rv = decltype(std::declval() = std::declval()); + using __rv = + decltype(std::declval() = std::declval()); MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl(Arg1&& arg, Arg2&& arg2, Args&&... args) noexcept { - return ((Arg1&&)arg) = __next_t::__impl((Arg2&&)arg2, (Args&&)args...); + static constexpr __rv __impl(Arg1 &&arg, Arg2 &&arg2, + Args &&... args) noexcept { + return ((Arg1 &&) arg) = + __next_t::__impl((Arg2 &&) arg2, (Args &&) args...); } }; template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr typename __fold_right_assign_impl_::__rv -__fold_right_assign_impl(Args&&... args) { - return __fold_right_assign_impl_::__impl((Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr + typename __fold_right_assign_impl_::__rv + __fold_right_assign_impl(Args &&... args) { + return __fold_right_assign_impl_::__impl((Args &&) args...); } // end right assign }}}2 @@ -518,34 +479,31 @@ __fold_right_assign_impl(Args&&... args) { //------------------------------------------------------------------------------ // {{{2 -template -struct __fold_left_assign_impl_; -template -struct __fold_left_assign_impl_ { - using __rv = Arg&&; +template struct __fold_left_assign_impl_; +template struct __fold_left_assign_impl_ { + using __rv = Arg &&; MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl(Arg&& arg) noexcept { - return (Arg&&)arg; - } + static constexpr __rv __impl(Arg &&arg) noexcept { return (Arg &&) arg; } }; template struct __fold_left_assign_impl_ { - using __assign_result_t = decltype(std::declval() = std::declval()); + using __assign_result_t = + decltype(std::declval() = std::declval()); using __next_t = __fold_left_assign_impl_<__assign_result_t, Args...>; using __rv = typename __next_t::__rv; MDSPAN_FORCE_INLINE_FUNCTION - static constexpr __rv - __impl(Arg1&& arg, Arg2&& arg2, Args&&... args) noexcept { - return __next_t::__impl(((Arg1&&)arg) = (Arg2&&)arg2, (Args&&)args...); + static constexpr __rv __impl(Arg1 &&arg, Arg2 &&arg2, + Args &&... args) noexcept { + return __next_t::__impl(((Arg1 &&) arg) = (Arg2 &&) arg2, + (Args &&) args...); } }; template -MDSPAN_FORCE_INLINE_FUNCTION -constexpr typename __fold_left_assign_impl_::__rv -__fold_left_assign_impl(Args&&... args) { - return __fold_left_assign_impl_::__impl((Args&&)args...); +MDSPAN_FORCE_INLINE_FUNCTION constexpr + typename __fold_left_assign_impl_::__rv + __fold_left_assign_impl(Args &&... args) { + return __fold_left_assign_impl_::__impl((Args &&) args...); } // end left assign }}}2 @@ -553,27 +511,40 @@ __fold_left_assign_impl(Args&&... args) { #endif - template -constexpr __mdspan_enable_fold_comma __fold_comma_impl(Args&&... args) noexcept { return { }; } +constexpr __mdspan_enable_fold_comma +__fold_comma_impl(Args &&... args) noexcept { + return {}; +} -template -struct __bools; +template struct __bools; -} // __fold_compatibility_impl +} // namespace __fold_compatibility_impl } // end namespace std -# define _MDSPAN_FOLD_AND(...) std::__fold_compatibility_impl::__fold_right_and_impl((__VA_ARGS__)...) -# define _MDSPAN_FOLD_OR(...) std::__fold_compatibility_impl::__fold_right_or_impl((__VA_ARGS__)...) -# define _MDSPAN_FOLD_ASSIGN_LEFT(INIT, ...) std::__fold_compatibility_impl::__fold_left_assign_impl(INIT, (__VA_ARGS__)...) -# define _MDSPAN_FOLD_ASSIGN_RIGHT(PACK, ...) std::__fold_compatibility_impl::__fold_right_assign_impl((PACK)..., __VA_ARGS__) -# define _MDSPAN_FOLD_TIMES_RIGHT(PACK, ...) std::__fold_compatibility_impl::__fold_right_times_impl((PACK)..., __VA_ARGS__) -# define _MDSPAN_FOLD_PLUS_RIGHT(PACK, ...) std::__fold_compatibility_impl::__fold_right_plus_impl((PACK)..., __VA_ARGS__) -# define _MDSPAN_FOLD_COMMA(...) std::__fold_compatibility_impl::__fold_comma_impl((__VA_ARGS__)...) - -# define _MDSPAN_FOLD_AND_TEMPLATE(...) \ - _MDSPAN_TRAIT(std::is_same, __fold_compatibility_impl::__bools<(__VA_ARGS__)..., true>, __fold_compatibility_impl::__bools) +#define _MDSPAN_FOLD_AND(...) \ + std::__fold_compatibility_impl::__fold_right_and_impl((__VA_ARGS__)...) +#define _MDSPAN_FOLD_OR(...) \ + std::__fold_compatibility_impl::__fold_right_or_impl((__VA_ARGS__)...) +#define _MDSPAN_FOLD_ASSIGN_LEFT(INIT, ...) \ + std::__fold_compatibility_impl::__fold_left_assign_impl(INIT, \ + (__VA_ARGS__)...) +#define _MDSPAN_FOLD_ASSIGN_RIGHT(PACK, ...) \ + std::__fold_compatibility_impl::__fold_right_assign_impl((PACK)..., \ + __VA_ARGS__) +#define _MDSPAN_FOLD_TIMES_RIGHT(PACK, ...) \ + std::__fold_compatibility_impl::__fold_right_times_impl((PACK)..., \ + __VA_ARGS__) +#define _MDSPAN_FOLD_PLUS_RIGHT(PACK, ...) \ + std::__fold_compatibility_impl::__fold_right_plus_impl((PACK)..., __VA_ARGS__) +#define _MDSPAN_FOLD_COMMA(...) \ + std::__fold_compatibility_impl::__fold_comma_impl((__VA_ARGS__)...) + +#define _MDSPAN_FOLD_AND_TEMPLATE(...) \ + _MDSPAN_TRAIT(std::is_same, \ + __fold_compatibility_impl::__bools<(__VA_ARGS__)..., true>, \ + __fold_compatibility_impl::__bools) #endif @@ -584,9 +555,9 @@ struct __bools; // {{{1 #if _MDSPAN_USE_VARIABLE_TEMPLATES -# define _MDSPAN_TRAIT(TRAIT, ...) TRAIT##_v<__VA_ARGS__> +#define _MDSPAN_TRAIT(TRAIT, ...) TRAIT##_v<__VA_ARGS__> #else -# define _MDSPAN_TRAIT(TRAIT, ...) TRAIT<__VA_ARGS__>::value +#define _MDSPAN_TRAIT(TRAIT, ...) TRAIT<__VA_ARGS__>::value #endif // end Variable template compatibility }}}1 @@ -596,18 +567,17 @@ struct __bools; // {{{1 #if _MDSPAN_USE_CONSTEXPR_14 -# define _MDSPAN_CONSTEXPR_14 constexpr +#define _MDSPAN_CONSTEXPR_14 constexpr // Workaround for a bug (I think?) in EDG frontends -# ifdef __EDG__ -# define _MDSPAN_CONSTEXPR_14_DEFAULTED -# else -# define _MDSPAN_CONSTEXPR_14_DEFAULTED constexpr -# endif +#ifdef __EDG__ +#define _MDSPAN_CONSTEXPR_14_DEFAULTED #else -# define _MDSPAN_CONSTEXPR_14 -# define _MDSPAN_CONSTEXPR_14_DEFAULTED +#define _MDSPAN_CONSTEXPR_14_DEFAULTED constexpr +#endif +#else +#define _MDSPAN_CONSTEXPR_14 +#define _MDSPAN_CONSTEXPR_14_DEFAULTED #endif // end Pre-C++14 constexpr }}}1 //============================================================================== - diff --git a/src/experimental/__p0009_bits/maybe_static_value.hpp b/src/experimental/__p0009_bits/maybe_static_value.hpp index ffe299dc19..e1a6a95221 100644 --- a/src/experimental/__p0009_bits/maybe_static_value.hpp +++ b/src/experimental/__p0009_bits/maybe_static_value.hpp @@ -57,8 +57,7 @@ namespace experimental { namespace detail { // static case -template struct __maybe_static_value { static constexpr _T __static_value = __v; @@ -66,9 +65,8 @@ struct __maybe_static_value { return __v; } template - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 - __mdspan_enable_fold_comma - __set_value(_U&& __rhs) noexcept { + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 __mdspan_enable_fold_comma + __set_value(_U &&__rhs) noexcept { // Should we assert that the value matches the static value here? return {}; } @@ -78,23 +76,25 @@ struct __maybe_static_value { MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr __maybe_static_value() noexcept = default; MDSPAN_INLINE_FUNCTION_DEFAULTED - constexpr __maybe_static_value(__maybe_static_value const&) noexcept = default; + constexpr __maybe_static_value(__maybe_static_value const &) noexcept = + default; MDSPAN_INLINE_FUNCTION_DEFAULTED - constexpr __maybe_static_value(__maybe_static_value&&) noexcept = default; + constexpr __maybe_static_value(__maybe_static_value &&) noexcept = default; MDSPAN_INLINE_FUNCTION_DEFAULTED - _MDSPAN_CONSTEXPR_14_DEFAULTED __maybe_static_value& operator=(__maybe_static_value const&) noexcept = default; + _MDSPAN_CONSTEXPR_14_DEFAULTED __maybe_static_value & + operator=(__maybe_static_value const &) noexcept = default; MDSPAN_INLINE_FUNCTION_DEFAULTED - _MDSPAN_CONSTEXPR_14_DEFAULTED __maybe_static_value& operator=(__maybe_static_value&&) noexcept = default; + _MDSPAN_CONSTEXPR_14_DEFAULTED __maybe_static_value & + operator=(__maybe_static_value &&) noexcept = default; MDSPAN_INLINE_FUNCTION_DEFAULTED ~__maybe_static_value() noexcept = default; MDSPAN_INLINE_FUNCTION - constexpr explicit __maybe_static_value(_T const&) noexcept { + constexpr explicit __maybe_static_value(_T const &) noexcept { // Should we assert that the value matches the static value here? } //-------------------------------------------------------------------------- - }; // dynamic case @@ -110,9 +110,8 @@ struct __maybe_static_value<_T, __is_dynamic_sentinal, __is_dynamic_sentinal, return this->__no_unique_address_emulation<_T>::__ref(); } template - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 - __mdspan_enable_fold_comma - __set_value(_U&& __rhs) noexcept { + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 __mdspan_enable_fold_comma + __set_value(_U &&__rhs) noexcept { this->__no_unique_address_emulation<_T>::__ref() = __rhs; return {}; } diff --git a/src/experimental/__p0009_bits/no_unique_address.hpp b/src/experimental/__p0009_bits/no_unique_address.hpp index f509cd7990..e8399a9500 100644 --- a/src/experimental/__p0009_bits/no_unique_address.hpp +++ b/src/experimental/__p0009_bits/no_unique_address.hpp @@ -104,9 +104,11 @@ struct __no_unique_address_emulation< // Explicitly make this not a reference so that the copy or move // constructor still gets called. MDSPAN_INLINE_FUNCTION - explicit constexpr __no_unique_address_emulation(_T const& __v) noexcept : _T(__v) {} + explicit constexpr __no_unique_address_emulation(_T const &__v) noexcept + : _T(__v) {} MDSPAN_INLINE_FUNCTION - explicit constexpr __no_unique_address_emulation(_T&& __v) noexcept : _T(::std::move(__v)) {} + explicit constexpr __no_unique_address_emulation(_T &&__v) noexcept + : _T(::std::move(__v)) {} }; //============================================================================== @@ -117,11 +119,15 @@ struct __no_unique_address_emulation< template struct __compressed_pair { _T __t_val; _U __u_val; - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T &__first() noexcept { return __t_val; } + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T &__first() noexcept { + return __t_val; + } MDSPAN_FORCE_INLINE_FUNCTION constexpr _T const &__first() const noexcept { return __t_val; } - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _U &__second() noexcept { return __u_val; } + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _U &__second() noexcept { + return __u_val; + } MDSPAN_FORCE_INLINE_FUNCTION constexpr _U const &__second() const noexcept { return __u_val; } @@ -158,7 +164,9 @@ struct __compressed_pair< MDSPAN_FORCE_INLINE_FUNCTION constexpr _T const &__first() const noexcept { return *static_cast<_T const *>(this); } - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _U &__second() noexcept { return __u_val; } + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _U &__second() noexcept { + return __u_val; + } MDSPAN_FORCE_INLINE_FUNCTION constexpr _U const &__second() const noexcept { return __u_val; } @@ -189,7 +197,9 @@ struct __compressed_pair< enable_if_t<_MDSPAN_TRAIT(is_empty, _U) && !_MDSPAN_TRAIT(is_empty, _T)>> : private _U { _T __t_val; - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T &__first() noexcept { return __t_val; } + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T &__first() noexcept { + return __t_val; + } MDSPAN_FORCE_INLINE_FUNCTION constexpr _T const &__first() const noexcept { return __t_val; } @@ -259,7 +269,8 @@ struct __compressed_pair< MDSPAN_INLINE_FUNCTION_DEFAULTED ~__compressed_pair() noexcept = default; template - MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_TLike &&__t, _ULike &&__u) noexcept + MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_TLike &&__t, + _ULike &&__u) noexcept : __first_base_t(_T((_TLike &&) __t)), __second_base_t(_U((_ULike &&) __u)) {} }; diff --git a/src/experimental/__p0009_bits/standard_layout_static_array.hpp b/src/experimental/__p0009_bits/standard_layout_static_array.hpp index aa9a8be5f0..388abd1f6e 100644 --- a/src/experimental/__p0009_bits/standard_layout_static_array.hpp +++ b/src/experimental/__p0009_bits/standard_layout_static_array.hpp @@ -48,8 +48,8 @@ #include "trait_backports.hpp" // enable_if #include -#include // integer_sequence #include +#include // integer_sequence namespace std { namespace experimental { @@ -101,10 +101,12 @@ struct __standard_layout_psa< __sentinal, integer_sequence>; using __base_t = __no_unique_address_emulation<__next_t>; - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 __next_t &__next() noexcept { + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 __next_t & + __next() noexcept { return this->__base_t::__ref(); } - MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t const &__next() const noexcept { + MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t const &__next() const + noexcept { return this->__base_t::__ref(); } @@ -114,10 +116,10 @@ struct __standard_layout_psa< // class that's private, even though __size_synamic is public in // it's definition. struct __msvc_workaround_tag {}; - using __msvc_workaround_next_t = __standard_layout_psa< - __msvc_workaround_tag, _T, - integer_sequence<_T, __values_or_sentinals...>, __sentinal, - integer_sequence>; + using __msvc_workaround_next_t = + __standard_layout_psa<__msvc_workaround_tag, _T, + integer_sequence<_T, __values_or_sentinals...>, + __sentinal, integer_sequence>; static constexpr auto __size_dynamic = __msvc_workaround_next_t::__size_dynamic; #else @@ -244,10 +246,12 @@ struct __standard_layout_psa< using __value_pair_t = __compressed_pair<_T, __next_t>; __value_pair_t __value_pair; - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 __next_t &__next() noexcept { + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 __next_t & + __next() noexcept { return __value_pair.__second(); } - MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t const &__next() const noexcept { + MDSPAN_FORCE_INLINE_FUNCTION constexpr __next_t const &__next() const + noexcept { return __value_pair.__second(); } @@ -372,12 +376,14 @@ struct __standard_layout_psa<_Tag, _T, integer_sequence<_T>, __sentinal, MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr __standard_layout_psa() noexcept -#if defined(__clang__) || defined(_MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND) +#if defined(__clang__) || \ + defined(_MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND) // As far as I can tell, there appears to be a bug in clang that's causing // this to be non-constexpr when it's defaulted. - { } + { + } #else - = default; + = default; #endif MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr __standard_layout_psa(__standard_layout_psa const &) noexcept = @@ -414,7 +420,8 @@ struct __standard_layout_psa<_Tag, _T, integer_sequence<_T>, __sentinal, template MDSPAN_INLINE_FUNCTION constexpr __standard_layout_psa( - __standard_layout_psa<_UTag, _U, _UValsSeq, __u_sentinal, _UIdxsSeq> const&) noexcept {} + __standard_layout_psa<_UTag, _U, _UValsSeq, __u_sentinal, _UIdxsSeq> const + &) noexcept {} // See comment in the previous partial specialization for why this is // necessary. Or just trust me that it's messy. @@ -443,9 +450,10 @@ struct __partially_static_sizes_tagged MDSPAN_INLINE_FUNCTION constexpr __partially_static_sizes_tagged() noexcept #ifdef _MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND - : __psa_impl_t() { } + : __psa_impl_t() { + } #else - = default; + = default; #endif MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr __partially_static_sizes_tagged( @@ -464,8 +472,9 @@ struct __partially_static_sizes_tagged template MDSPAN_FORCE_INLINE_FUNCTION constexpr explicit __partially_static_sizes_tagged( - __partially_static_sizes_tagged<_UTag, __values_or_sentinals...> const& __vals - ) noexcept : __psa_impl_t(__vals.__enable_psa_conversion()) { } + __partially_static_sizes_tagged<_UTag, __values_or_sentinals...> const + &__vals) noexcept + : __psa_impl_t(__vals.__enable_psa_conversion()) {} }; struct __no_tag {}; @@ -477,20 +486,23 @@ struct __partially_static_sizes __partially_static_sizes_tagged<__no_tag, __values_or_sentinals...>; template MDSPAN_FORCE_INLINE_FUNCTION constexpr __partially_static_sizes( - __partially_static_sizes_tagged<_UTag, __values_or_sentinals...>&& __vals - ) noexcept : __base_t(::std::move(__vals)) { } + __partially_static_sizes_tagged<_UTag, __values_or_sentinals...> + &&__vals) noexcept + : __base_t(::std::move(__vals)) {} + public: using __base_t::__base_t; #ifdef _MDSPAN_DEFAULTED_CONSTRUCTORS_INHERITANCE_WORKAROUND MDSPAN_INLINE_FUNCTION - constexpr __partially_static_sizes() noexcept : __base_t() { } + constexpr __partially_static_sizes() noexcept : __base_t() {} #endif template MDSPAN_FORCE_INLINE_FUNCTION constexpr __partially_static_sizes_tagged< _UTag, __values_or_sentinals...> __with_tag() const noexcept { - return __partially_static_sizes_tagged<_UTag, __values_or_sentinals...>(*this); + return __partially_static_sizes_tagged<_UTag, __values_or_sentinals...>( + *this); } }; diff --git a/src/experimental/__p0009_bits/static_array.hpp b/src/experimental/__p0009_bits/static_array.hpp index 0d3d08a403..dccb1dee0b 100644 --- a/src/experimental/__p0009_bits/static_array.hpp +++ b/src/experimental/__p0009_bits/static_array.hpp @@ -47,14 +47,14 @@ #if !_MDSPAN_PRESERVE_STANDARD_LAYOUT #include "dynamic_extent.hpp" -#include "trait_backports.hpp" #include "maybe_static_value.hpp" #include "standard_layout_static_array.hpp" +#include "trait_backports.hpp" #include "type_list.hpp" +#include #include // ptrdiff_t #include // integer_sequence -#include namespace std { namespace experimental { @@ -64,64 +64,51 @@ namespace detail { template struct __mask_element {}; -template -struct __mask_sequence_assign_op { +template struct __mask_sequence_assign_op { template <_T _V> __mask_sequence_assign_op<_T, _Result..., _V> - operator=(__mask_element<_T, _V, true>&&); + operator=(__mask_element<_T, _V, true> &&); template <_T _V> __mask_sequence_assign_op<_T, _Result...> - operator=(__mask_element<_T, _V, false>&&); + operator=(__mask_element<_T, _V, false> &&); using __result = integer_sequence<_T, _Result...>; }; -template -struct __mask_sequence; +template struct __mask_sequence; template -struct __mask_sequence, integer_sequence> -{ - using type = typename decltype( - _MDSPAN_FOLD_ASSIGN_LEFT( - __mask_sequence_assign_op<_T>{}, /* = ... = */ __mask_element<_T, _Vals, _Masks>{} - ) - )::__result; +struct __mask_sequence, + integer_sequence> { + using type = typename decltype(_MDSPAN_FOLD_ASSIGN_LEFT( + __mask_sequence_assign_op<_T>{}, + /* = ... = */ __mask_element<_T, _Vals, _Masks>{}))::__result; }; //============================================================================== -template +template class __partially_static_array_impl; -template < - class _T, _T... __values_or_sentinals, _T __sentinal, - size_t... _Idxs, - size_t... _IdxsDynamic, - size_t... _IdxsDynamicIdxs -> +template class __partially_static_array_impl< - _T, - integer_sequence<_T, __values_or_sentinals...>, - __sentinal, - integer_sequence, - integer_sequence, - integer_sequence -> + _T, integer_sequence<_T, __values_or_sentinals...>, __sentinal, + integer_sequence, + integer_sequence, + integer_sequence> : private __maybe_static_value<_T, __values_or_sentinals, __sentinal, _Idxs>... { private: - template - using __base_n = typename __type_at<_N, - __type_list<__maybe_static_value<_T, __values_or_sentinals, __sentinal, _Idxs>...> - >::type; + using __base_n = typename __type_at< + _N, __type_list<__maybe_static_value<_T, __values_or_sentinals, + __sentinal, _Idxs>...>>::type; public: - static constexpr auto __size = sizeof...(_Idxs); - static constexpr auto __size_dynamic = - _MDSPAN_FOLD_PLUS_RIGHT(static_cast((__values_or_sentinals == __sentinal)), /* + ... + */ 0); + static constexpr auto __size_dynamic = _MDSPAN_FOLD_PLUS_RIGHT( + static_cast((__values_or_sentinals == __sentinal)), /* + ... + */ 0); //-------------------------------------------------------------------------- @@ -159,10 +146,10 @@ class __partially_static_array_impl< : __base_n<_IdxsDynamic>(__base_n<_IdxsDynamic>{{__vals}})... {} MDSPAN_INLINE_FUNCTION constexpr explicit __partially_static_array_impl( - array<_T, sizeof...(_Idxs)> const& __vals) noexcept - : __partially_static_array_impl( - __construct_partially_static_array_from_sizes_tag, - ::std::get<_Idxs>(__vals)...) {} + array<_T, sizeof...(_Idxs)> const &__vals) noexcept + : __partially_static_array_impl( + __construct_partially_static_array_from_sizes_tag, + ::std::get<_Idxs>(__vals)...) {} // clang-format off MDSPAN_FUNCTION_REQUIRES( @@ -180,12 +167,12 @@ class __partially_static_array_impl< template MDSPAN_INLINE_FUNCTION constexpr __partially_static_array_impl( - __partially_static_array_impl< - _U, _UValsSeq, __u_sentinal, _UIdxsSeq, - _UIdxsDynamicSeq, _UIdxsDynamicIdxsSeq> const &__rhs) noexcept - : __partially_static_array_impl( - __construct_partially_static_array_from_sizes_tag, - __rhs.template __get_n<_Idxs>()...) {} + __partially_static_array_impl<_U, _UValsSeq, __u_sentinal, _UIdxsSeq, + _UIdxsDynamicSeq, + _UIdxsDynamicIdxsSeq> const &__rhs) noexcept + : __partially_static_array_impl( + __construct_partially_static_array_from_sizes_tag, + __rhs.template __get_n<_Idxs>()...) {} //-------------------------------------------------------------------------- @@ -193,67 +180,62 @@ class __partially_static_array_impl< // necessary. Or just trust me that it's messy. MDSPAN_FORCE_INLINE_FUNCTION constexpr __partially_static_array_impl const &__enable_psa_conversion() const - noexcept { - return *this; + noexcept { + return *this; } template MDSPAN_FORCE_INLINE_FUNCTION constexpr _T __get_n() const noexcept { - return static_cast<__base_n<_I> const*>(this)->__value(); + return static_cast<__base_n<_I> const *>(this)->__value(); } template - MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 void __set_n(_U&& __rhs) noexcept { - static_cast<__base_n<_I>*>(this)->__set_value((_U&&)__rhs); + MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 void + __set_n(_U &&__rhs) noexcept { + static_cast<__base_n<_I> *>(this)->__set_value((_U &&) __rhs); } template - MDSPAN_FORCE_INLINE_FUNCTION static constexpr _T - __get_static_n() noexcept { - return __base_n<_I>::__static_value == __sentinal ? - __default : __base_n<_I>::__static_value; + MDSPAN_FORCE_INLINE_FUNCTION static constexpr _T __get_static_n() noexcept { + return __base_n<_I>::__static_value == __sentinal + ? __default + : __base_n<_I>::__static_value; } - MDSPAN_FORCE_INLINE_FUNCTION constexpr _T - __get(size_t __n) const noexcept { - return _MDSPAN_FOLD_PLUS_RIGHT( - (_T(_Idxs == __n) * __get_n<_Idxs>()), /* + ... + */ _T(0) - ); + MDSPAN_FORCE_INLINE_FUNCTION constexpr _T __get(size_t __n) const noexcept { + return _MDSPAN_FOLD_PLUS_RIGHT((_T(_Idxs == __n) * __get_n<_Idxs>()), + /* + ... + */ _T(0)); } - }; //============================================================================== -template > +template > struct __partially_static_array_impl_maker; -template < - class _T, _T... _Vals, _T __sentinal, size_t... _Idxs -> -struct __partially_static_array_impl_maker< - _T, integer_sequence<_T, _Vals...>, __sentinal, integer_sequence -> -{ +template +struct __partially_static_array_impl_maker<_T, integer_sequence<_T, _Vals...>, + __sentinal, + integer_sequence> { using __dynamic_idxs = typename __mask_sequence< - integer_sequence, - integer_sequence - >::type; - using __impl_base = - __partially_static_array_impl<_T, - integer_sequence<_T, _Vals...>, - __sentinal, integer_sequence, - __dynamic_idxs, - make_index_sequence<__dynamic_idxs::size()> - >; + integer_sequence, + integer_sequence>::type; + using __impl_base = __partially_static_array_impl< + _T, integer_sequence<_T, _Vals...>, __sentinal, + integer_sequence, __dynamic_idxs, + make_index_sequence<__dynamic_idxs::size()>>; }; template class __partially_static_array_with_sentinal - : public __partially_static_array_impl_maker<_T, _ValsSeq, __sentinal>::__impl_base -{ + : public __partially_static_array_impl_maker<_T, _ValsSeq, + __sentinal>::__impl_base { private: - using __base_t = typename __partially_static_array_impl_maker<_T, _ValsSeq, __sentinal>::__impl_base; + using __base_t = + typename __partially_static_array_impl_maker<_T, _ValsSeq, + __sentinal>::__impl_base; + public: using __base_t::__base_t; }; @@ -261,17 +243,19 @@ class __partially_static_array_with_sentinal //============================================================================== template -struct __partially_static_sizes : - __partially_static_array_with_sentinal< - ptrdiff_t, ::std::integer_sequence> -{ +struct __partially_static_sizes + : __partially_static_array_with_sentinal< + ptrdiff_t, + ::std::integer_sequence> { private: using __base_t = __partially_static_array_with_sentinal< - ptrdiff_t, ::std::integer_sequence>; + ptrdiff_t, ::std::integer_sequence>; + public: using __base_t::__base_t; template - MDSPAN_FORCE_INLINE_FUNCTION constexpr __partially_static_sizes<__values_or_sentinals...> + MDSPAN_FORCE_INLINE_FUNCTION constexpr __partially_static_sizes< + __values_or_sentinals...> __with_tag() const noexcept { return *this; } @@ -279,7 +263,8 @@ struct __partially_static_sizes : // Tags are needed for the standard layout version, but not here template -using __partially_static_sizes_tagged = __partially_static_sizes<__values_or_sentinals...>; +using __partially_static_sizes_tagged = + __partially_static_sizes<__values_or_sentinals...>; } // namespace detail } // end namespace experimental diff --git a/src/experimental/__p0009_bits/subspan.hpp b/src/experimental/__p0009_bits/subspan.hpp index dc0a6f334a..c0742d72e9 100644 --- a/src/experimental/__p0009_bits/subspan.hpp +++ b/src/experimental/__p0009_bits/subspan.hpp @@ -41,11 +41,10 @@ //@HEADER */ - #pragma once -#include "basic_mdspan.hpp" #include "all_type.hpp" +#include "basic_mdspan.hpp" #include "dynamic_extent.hpp" #include "layout_left.hpp" #include "layout_right.hpp" @@ -53,7 +52,7 @@ #include "macros.hpp" #include "trait_backports.hpp" -#include // std::apply +#include // std::apply #include // std::pair namespace std { @@ -71,96 +70,83 @@ struct _slice_wrap { //-------------------------------------------------------------------------------- template -MDSPAN_INLINE_FUNCTION constexpr -_slice_wrap -_wrap_slice(ptrdiff_t val, ptrdiff_t ext, ptrdiff_t stride) { return { val, ext, stride }; } +MDSPAN_INLINE_FUNCTION constexpr _slice_wrap +_wrap_slice(ptrdiff_t val, ptrdiff_t ext, ptrdiff_t stride) { + return {val, ext, stride}; +} template -MDSPAN_INLINE_FUNCTION constexpr -_slice_wrap -_wrap_slice(all_type val, ptrdiff_t ext, ptrdiff_t stride) { return { val, ext, stride }; } +MDSPAN_INLINE_FUNCTION constexpr _slice_wrap +_wrap_slice(all_type val, ptrdiff_t ext, ptrdiff_t stride) { + return {val, ext, stride}; +} // TODO generalize this to anything that works with std::get<0> and std::get<1> template -MDSPAN_INLINE_FUNCTION constexpr -_slice_wrap> -_wrap_slice(std::pair const& val, ptrdiff_t ext, ptrdiff_t stride) -{ - return { val, ext, stride }; +MDSPAN_INLINE_FUNCTION constexpr _slice_wrap> +_wrap_slice(std::pair const &val, ptrdiff_t ext, + ptrdiff_t stride) { + return {val, ext, stride}; } //-------------------------------------------------------------------------------- - -template < - bool result=true, - bool encountered_first_all=false, - bool encountered_first_pair=false -> +template struct preserve_layout_right_analysis : integral_constant { using layout_type_if_preserved = layout_right; using encounter_pair = preserve_layout_right_analysis< - // If the pair isn't the right-most slice (i.e., if there was a previous pair), - // we can't preserve any contiguous layout. Nothing else should matter - (encountered_first_pair ? false : result), - // Whether or not we've encountered the first all doesn't change, though it - // doesn't really matter, since anything to the right of this leads to a false - // result - encountered_first_all, - // This is a pair, so we've encountered at least one - true - >; + // If the pair isn't the right-most slice (i.e., if there was a previous pair), + // we can't preserve any contiguous layout. Nothing else should matter + (encountered_first_pair ? false : result), + // Whether or not we've encountered the first all doesn't change, though it + // doesn't really matter, since anything to the right of this leads to a false + // result + encountered_first_all, + // This is a pair, so we've encountered at least one + true>; using encounter_all = preserve_layout_right_analysis< - // encountering an all changes nothing unless we've already encountered a pair - (encountered_first_pair ? false : result), - // This is an all, so we've encountered at least one - true, - // nothing changes about this last one - encountered_first_pair - >; + // encountering an all changes nothing unless we've already encountered a pair + (encountered_first_pair ? false : result), + // This is an all, so we've encountered at least one + true, + // nothing changes about this last one + encountered_first_pair>; using encounter_scalar = preserve_layout_right_analysis< - // if there's a scalar to the right of any non-scalar slice, we can't preserve - // any contiguous layout: - (encountered_first_all || encountered_first_pair) ? false : result, - // nothing else changes (though if they're true, it doesn't matter) - encountered_first_all, - encountered_first_pair - >; + // if there's a scalar to the right of any non-scalar slice, we can't preserve + // any contiguous layout: + (encountered_first_all || encountered_first_pair) ? false : result, + // nothing else changes (though if they're true, it doesn't matter) + encountered_first_all, encountered_first_pair>; }; -template < - bool result=true, - bool encountered_first_scalar=false, - bool encountered_first_all=false, - bool encountered_first_pair=false -> +template struct preserve_layout_left_analysis : integral_constant { using layout_type_if_preserved = layout_left; using encounter_pair = preserve_layout_left_analysis< - // Only the left-most slice can be a pair. If we've encountered anything else, - // we can't preserve any contiguous layout - (encountered_first_scalar || encountered_first_all || encountered_first_pair) ? false : result, - // These change in the expected ways - encountered_first_scalar, - encountered_first_all, - true - >; + // Only the left-most slice can be a pair. If we've encountered anything else, + // we can't preserve any contiguous layout + (encountered_first_scalar || encountered_first_all || + encountered_first_pair) + ? false + : result, + // These change in the expected ways + encountered_first_scalar, encountered_first_all, true>; using encounter_all = preserve_layout_left_analysis< - // If there's a scalar to the left of us, we can't preserve contiguous - encountered_first_scalar ? false : result, - // These change in the expected ways - encountered_first_scalar, - true, - encountered_first_pair - >; + // If there's a scalar to the left of us, we can't preserve contiguous + encountered_first_scalar ? false : result, + // These change in the expected ways + encountered_first_scalar, true, encountered_first_pair>; using encounter_scalar = preserve_layout_left_analysis< - // If there's a scalar to the left of us, we can't preserve contiguous - result, - // These change in the expected ways - true, - encountered_first_all, - encountered_first_pair - >; + // If there's a scalar to the left of us, we can't preserve contiguous + result, + // These change in the expected ways + true, encountered_first_all, encountered_first_pair>; }; struct ignore_layout_preservation : std::integral_constant { @@ -171,55 +157,42 @@ struct ignore_layout_preservation : std::integral_constant { }; template -struct preserve_layout_analysis - : ignore_layout_preservation { }; +struct preserve_layout_analysis : ignore_layout_preservation {}; template <> struct preserve_layout_analysis - : preserve_layout_right_analysis<> { }; + : preserve_layout_right_analysis<> {}; template <> -struct preserve_layout_analysis - : preserve_layout_left_analysis<> { }; +struct preserve_layout_analysis : preserve_layout_left_analysis<> { +}; //-------------------------------------------------------------------------------- -template < - class _PreserveLayoutAnalysis, - class _OffsetsArray=__partially_static_sizes<>, - class _ExtsArray=__partially_static_sizes<>, - class _StridesArray=__partially_static_sizes<>, - class=make_index_sequence<_OffsetsArray::__size>, - class=make_index_sequence<_ExtsArray::__size>, - class=make_index_sequence<_StridesArray::__size> -> +template , + class _ExtsArray = __partially_static_sizes<>, + class _StridesArray = __partially_static_sizes<>, + class = make_index_sequence<_OffsetsArray::__size>, + class = make_index_sequence<_ExtsArray::__size>, + class = make_index_sequence<_StridesArray::__size>> struct __assign_op_slice_handler; /* clang-format: off */ -template < - class _PreserveLayoutAnalysis, - ptrdiff_t... _Offsets, - ptrdiff_t... _Exts, - ptrdiff_t... _Strides, - size_t... _OffsetIdxs, - size_t... _ExtIdxs, - size_t... _StrideIdxs> +template struct __assign_op_slice_handler< - _PreserveLayoutAnalysis, - __partially_static_sizes<_Offsets...>, - __partially_static_sizes<_Exts...>, - __partially_static_sizes<_Strides...>, - integer_sequence, - integer_sequence, - integer_sequence> -{ + _PreserveLayoutAnalysis, __partially_static_sizes<_Offsets...>, + __partially_static_sizes<_Exts...>, __partially_static_sizes<_Strides...>, + integer_sequence, + integer_sequence, + integer_sequence> { // TODO remove this for better compiler performance - static_assert( - _MDSPAN_FOLD_AND((_Strides == dynamic_extent || _Strides > 0) /* && ... */), - " " - ); - static_assert( - _MDSPAN_FOLD_AND((_Offsets == dynamic_extent || _Offsets >= 0) /* && ... */), - " " - ); + static_assert(_MDSPAN_FOLD_AND((_Strides == dynamic_extent || + _Strides > 0) /* && ... */), + " "); + static_assert(_MDSPAN_FOLD_AND((_Offsets == dynamic_extent || + _Offsets >= 0) /* && ... */), + " "); using __offsets_storage_t = __partially_static_sizes<_Offsets...>; using __extents_storage_t = __partially_static_sizes<_Exts...>; @@ -229,16 +202,16 @@ struct __assign_op_slice_handler< __strides_storage_t __strides; #if __INTEL_COMPILER <= 1800 - MDSPAN_INLINE_FUNCTION constexpr __assign_op_slice_handler(__assign_op_slice_handler&& __other) noexcept - : __offsets(::std::move(__other.__offsets)), __exts(::std::move(__other.__exts)), __strides(::std::move(__other.__strides)) - { } MDSPAN_INLINE_FUNCTION constexpr __assign_op_slice_handler( - __offsets_storage_t&& __o, - __extents_storage_t&& __e, - __strides_storage_t&& __s - ) noexcept - : __offsets(::std::move(__o)), __exts(::std::move(__e)), __strides(::std::move(__s)) - { } + __assign_op_slice_handler &&__other) noexcept + : __offsets(::std::move(__other.__offsets)), + __exts(::std::move(__other.__exts)), + __strides(::std::move(__other.__strides)) {} + MDSPAN_INLINE_FUNCTION constexpr __assign_op_slice_handler( + __offsets_storage_t &&__o, __extents_storage_t &&__e, + __strides_storage_t &&__s) noexcept + : __offsets(::std::move(__o)), __exts(::std::move(__e)), + __strides(::std::move(__s)) {} #endif // Don't define this unless we need it; they have a cost to compile @@ -249,171 +222,157 @@ struct __assign_op_slice_handler< // For ptrdiff_t slice, skip the extent and stride, but add an offset corresponding to the value template MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) - _MDSPAN_CONSTEXPR_14 auto - operator=(_slice_wrap<_OldStaticExtent, _OldStaticStride, ptrdiff_t>&& __slice) noexcept - -> __assign_op_slice_handler< - typename _PreserveLayoutAnalysis::encounter_scalar, - __partially_static_sizes<_Offsets..., dynamic_extent>, - __partially_static_sizes<_Exts...>, - __partially_static_sizes<_Strides...>/* intentional space here to work around ICC bug*/> { - return { - __partially_static_sizes<_Offsets..., dynamic_extent>( - __construct_partially_static_array_from_sizes_tag, - __offsets.template __get_n<_OffsetIdxs>()..., __slice.slice), - ::std::move(__exts), - ::std::move(__strides) - }; + _MDSPAN_CONSTEXPR_14 auto + operator=(_slice_wrap<_OldStaticExtent, _OldStaticStride, ptrdiff_t> + &&__slice) noexcept + -> __assign_op_slice_handler< + typename _PreserveLayoutAnalysis::encounter_scalar, + __partially_static_sizes<_Offsets..., dynamic_extent>, + __partially_static_sizes<_Exts...>, + __partially_static_sizes< + _Strides...> /* intentional space here to work around ICC bug*/> { + return {__partially_static_sizes<_Offsets..., dynamic_extent>( + __construct_partially_static_array_from_sizes_tag, + __offsets.template __get_n<_OffsetIdxs>()..., __slice.slice), + ::std::move(__exts), ::std::move(__strides)}; } // For a std::all, offset 0 and old extent template MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) - _MDSPAN_CONSTEXPR_14 auto - operator=(_slice_wrap<_OldStaticExtent, _OldStaticStride, all_type>&& __slice) noexcept - -> __assign_op_slice_handler< - typename _PreserveLayoutAnalysis::encounter_all, - __partially_static_sizes<_Offsets..., 0>, - __partially_static_sizes<_Exts..., _OldStaticExtent>, - __partially_static_sizes<_Strides..., _OldStaticStride>/* intentional space here to work around ICC bug*/> { - return { - __partially_static_sizes<_Offsets..., 0>( - __construct_partially_static_array_from_sizes_tag, - __offsets.template __get_n<_OffsetIdxs>()..., ptrdiff_t(0)), - __partially_static_sizes<_Exts..., _OldStaticExtent>( - __construct_partially_static_array_from_sizes_tag, - __exts.template __get_n<_ExtIdxs>()..., __slice.old_extent), - __partially_static_sizes<_Strides..., _OldStaticStride>( - __construct_partially_static_array_from_sizes_tag, - __strides.template __get_n<_StrideIdxs>()..., __slice.old_stride) - }; + _MDSPAN_CONSTEXPR_14 auto + operator=(_slice_wrap<_OldStaticExtent, _OldStaticStride, all_type> + &&__slice) noexcept + -> __assign_op_slice_handler< + typename _PreserveLayoutAnalysis::encounter_all, + __partially_static_sizes<_Offsets..., 0>, + __partially_static_sizes<_Exts..., _OldStaticExtent>, + __partially_static_sizes< + _Strides..., + _OldStaticStride> /* intentional space here to work around ICC bug*/> { + return {__partially_static_sizes<_Offsets..., 0>( + __construct_partially_static_array_from_sizes_tag, + __offsets.template __get_n<_OffsetIdxs>()..., ptrdiff_t(0)), + __partially_static_sizes<_Exts..., _OldStaticExtent>( + __construct_partially_static_array_from_sizes_tag, + __exts.template __get_n<_ExtIdxs>()..., __slice.old_extent), + __partially_static_sizes<_Strides..., _OldStaticStride>( + __construct_partially_static_array_from_sizes_tag, + __strides.template __get_n<_StrideIdxs>()..., + __slice.old_stride)}; } // For a std::pair, add an offset and add a new dynamic extent (strides still preserved) template MDSPAN_FORCE_INLINE_FUNCTION // NOLINT (misc-unconventional-assign-operator) - _MDSPAN_CONSTEXPR_14 auto - operator=(_slice_wrap<_OldStaticExtent, _OldStaticStride, pair>&& __slice) noexcept - -> __assign_op_slice_handler< - typename _PreserveLayoutAnalysis::encounter_pair, - __partially_static_sizes<_Offsets..., dynamic_extent>, - __partially_static_sizes<_Exts..., dynamic_extent>, - __partially_static_sizes<_Strides..., _OldStaticStride>/* intentional space here to work around ICC bug*/> { - return { - __partially_static_sizes<_Offsets..., dynamic_extent>( - __construct_partially_static_array_from_sizes_tag, - __offsets.template __get_n<_OffsetIdxs>()..., ::std::get<0>(__slice.slice)), - __partially_static_sizes<_Exts..., dynamic_extent>( - __construct_partially_static_array_from_sizes_tag, - __exts.template __get_n<_ExtIdxs>()..., ::std::get<1>(__slice.slice) - ::std::get<0>(__slice.slice)), - __partially_static_sizes<_Strides..., _OldStaticStride>( - __construct_partially_static_array_from_sizes_tag, - __strides.template __get_n<_StrideIdxs>()..., __slice.old_stride) - }; + _MDSPAN_CONSTEXPR_14 auto + operator=(_slice_wrap<_OldStaticExtent, _OldStaticStride, + pair> &&__slice) noexcept + -> __assign_op_slice_handler< + typename _PreserveLayoutAnalysis::encounter_pair, + __partially_static_sizes<_Offsets..., dynamic_extent>, + __partially_static_sizes<_Exts..., dynamic_extent>, + __partially_static_sizes< + _Strides..., + _OldStaticStride> /* intentional space here to work around ICC bug*/> { + return {__partially_static_sizes<_Offsets..., dynamic_extent>( + __construct_partially_static_array_from_sizes_tag, + __offsets.template __get_n<_OffsetIdxs>()..., + ::std::get<0>(__slice.slice)), + __partially_static_sizes<_Exts..., dynamic_extent>( + __construct_partially_static_array_from_sizes_tag, + __exts.template __get_n<_ExtIdxs>()..., + ::std::get<1>(__slice.slice) - ::std::get<0>(__slice.slice)), + __partially_static_sizes<_Strides..., _OldStaticStride>( + __construct_partially_static_array_from_sizes_tag, + __strides.template __get_n<_StrideIdxs>()..., + __slice.old_stride)}; } - // TODO defer instantiation of this? + // TODO defer instantiation of this? using layout_type = typename conditional< - _PreserveLayoutAnalysis::value, - typename _PreserveLayoutAnalysis::layout_type_if_preserved, - layout_stride<_Strides...> - >::type; + _PreserveLayoutAnalysis::value, + typename _PreserveLayoutAnalysis::layout_type_if_preserved, + layout_stride<_Strides...>>::type; // TODO noexcept specification template - MDSPAN_INLINE_FUNCTION - _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( - ( - _MDSPAN_CONSTEXPR_14 /* auto */ - _make_layout_mapping_impl(NewLayout) noexcept - ), - ( - /* not layout stride, so don't pass dynamic_strides */ - /* return */ typename NewLayout::template mapping<::std::experimental::extents<_Exts...>>( - experimental::extents<_Exts...>::__make_extents_impl(::std::move(__exts)) - ) /* ; */ - ) - ) - - MDSPAN_INLINE_FUNCTION - _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( - ( - _MDSPAN_CONSTEXPR_14 /* auto */ - _make_layout_mapping_impl(layout_stride<_Strides...>) noexcept - ), - ( - /* return */ layout_stride<_Strides...>::template mapping<::std::experimental::extents<_Exts...>> - ::__make_layout_stride_impl(::std::move(__exts), ::std::move(__strides)) /* ; */ - ) - ) - - template // mostly for deferred instantiation, but maybe we'll use this in the future - MDSPAN_INLINE_FUNCTION - _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( - ( - _MDSPAN_CONSTEXPR_14 /* auto */ - make_layout_mapping(OldLayoutMapping const&) noexcept - ), - ( - /* return */ this->_make_layout_mapping_impl(layout_type{}) /* ; */ - ) - ) + MDSPAN_INLINE_FUNCTION _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( + (_MDSPAN_CONSTEXPR_14 /* auto */ + _make_layout_mapping_impl(NewLayout) noexcept), + ( + /* not layout stride, so don't pass dynamic_strides */ + /* return */ typename NewLayout::template mapping< + ::std::experimental::extents<_Exts...>>( + experimental::extents<_Exts...>::__make_extents_impl( + ::std::move(__exts))) /* ; */ + )) + + MDSPAN_INLINE_FUNCTION _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( + (_MDSPAN_CONSTEXPR_14 /* auto */ + _make_layout_mapping_impl(layout_stride<_Strides...>) noexcept), + ( + /* return */ layout_stride<_Strides...>::template mapping< + ::std::experimental::extents<_Exts...>>:: + __make_layout_stride_impl(::std::move(__exts), + ::std::move(__strides)) /* ; */ + )) + + template < + class + OldLayoutMapping> // mostly for deferred instantiation, but maybe we'll use this in the future + MDSPAN_INLINE_FUNCTION _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( + (_MDSPAN_CONSTEXPR_14 /* auto */ + make_layout_mapping(OldLayoutMapping const &) noexcept), + ( + /* return */ this->_make_layout_mapping_impl( + layout_type{}) /* ; */ + )) }; //============================================================================== #if _MDSPAN_USE_RETURN_TYPE_DEDUCTION // Forking this because the C++11 version will be *completely* unreadable -template -MDSPAN_INLINE_FUNCTION -constexpr auto _subspan_impl( - integer_sequence, - basic_mdspan, LP, AP> const& src, - SliceSpecs&&... slices -) noexcept -{ - auto _handled = - _MDSPAN_FOLD_ASSIGN_LEFT( - ( - detail::__assign_op_slice_handler< - detail::preserve_layout_analysis - >{ - __partially_static_sizes<>{}, - __partially_static_sizes<>{}, - __partially_static_sizes<>{} - } - ), - /* = ... = */ +template +MDSPAN_INLINE_FUNCTION constexpr auto _subspan_impl( + integer_sequence, + basic_mdspan, LP, AP> const &src, + SliceSpecs &&... slices) noexcept { + auto _handled = _MDSPAN_FOLD_ASSIGN_LEFT( + (detail::__assign_op_slice_handler>{ + __partially_static_sizes<>{}, __partially_static_sizes<>{}, + __partially_static_sizes<>{}}), + /* = ... = */ detail::_wrap_slice< - Exts, decltype(src.mapping())::template __static_stride_workaround::value - >( - slices, src.extents().template __extent(), - src.mapping().template __stride() - ) - ); - - ptrdiff_t offset_size = src.mapping()(_handled.__offsets.template __get_n()...); + Exts, decltype(src.mapping())::template __static_stride_workaround< + Idxs>::value>(slices, + src.extents().template __extent(), + src.mapping().template __stride())); + + ptrdiff_t offset_size = + src.mapping()(_handled.__offsets.template __get_n()...); auto offset_ptr = src.accessor().offset(src.data(), offset_size); auto map = _handled.make_layout_mapping(src.mapping()); auto acc_pol = typename AP::offset_policy(src.accessor()); - return basic_mdspan< - ET, decltype(map.extents()), typename decltype(_handled)::layout_type, decltype(acc_pol) - >( - std::move(offset_ptr), std::move(map), std::move(acc_pol) - ); + return basic_mdspan(std::move(offset_ptr), std::move(map), + std::move(acc_pol)); } #else template -auto _subspan_impl_helper(Src&& src, Handled&& h, std::integer_sequence) - -> basic_mdspan< - ET, typename Handled::__extents_type, typename Handled::layout_type, typename AP::offset_policy - > -{ +auto _subspan_impl_helper(Src &&src, Handled &&h, + std::integer_sequence) + -> basic_mdspan { return { - src.accessor().offset(src.data(), src.mapping()(h.__offsets.template __get_n()...)), - h.make_layout_mapping(src.mapping()), - typename AP::offset_policy(src.accessor()) - }; + src.accessor().offset( + src.data(), src.mapping()(h.__offsets.template __get_n()...)), + h.make_layout_mapping(src.mapping()), + typename AP::offset_policy(src.accessor())}; } template @@ -453,11 +412,9 @@ _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( #endif -template struct _is_layout_stride : std::false_type { }; -template struct _is_layout_stride< - layout_stride -> : std::true_type -{ }; +template struct _is_layout_stride : std::false_type {}; +template +struct _is_layout_stride> : std::true_type {}; } // namespace detail @@ -465,33 +422,27 @@ template struct _is_layout_stride< // TODO @proposal-bug sizeof...(SliceSpecs) == sizeof...(Exts) should be a constraint, not a requirement MDSPAN_TEMPLATE_REQUIRES( - class ET, ptrdiff_t... Exts, class LP, class AP, class... SliceSpecs, - /* requires */ ( - ( - _MDSPAN_TRAIT(is_same, LP, layout_left) - || _MDSPAN_TRAIT(is_same, LP, layout_right) - || detail::_is_layout_stride::value - ) && - _MDSPAN_FOLD_AND(( - _MDSPAN_TRAIT(is_convertible, SliceSpecs, ptrdiff_t) - || _MDSPAN_TRAIT(is_convertible, SliceSpecs, pair) - || _MDSPAN_TRAIT(is_convertible, SliceSpecs, all_type) - ) /* && ... */) && - sizeof...(SliceSpecs) == sizeof...(Exts) - ) -) + class ET, ptrdiff_t... Exts, class LP, class AP, class... SliceSpecs, + /* requires */ + ((_MDSPAN_TRAIT(is_same, LP, layout_left) || + _MDSPAN_TRAIT(is_same, LP, layout_right) || + detail::_is_layout_stride::value) && + _MDSPAN_FOLD_AND((_MDSPAN_TRAIT(is_convertible, SliceSpecs, ptrdiff_t) || + _MDSPAN_TRAIT(is_convertible, SliceSpecs, + pair) || + _MDSPAN_TRAIT(is_convertible, SliceSpecs, + all_type)) /* && ... */) && + sizeof...(SliceSpecs) == sizeof...(Exts))) MDSPAN_INLINE_FUNCTION _MDSPAN_DEDUCE_RETURN_TYPE_SINGLE_LINE( - ( - constexpr subspan( - basic_mdspan, LP, AP> const& src, SliceSpecs... slices - ) noexcept - ), - ( - /* return */ - detail::_subspan_impl(std::make_index_sequence{}, src, slices...) /*;*/ - ) -) + (constexpr subspan(basic_mdspan, LP, + AP> const &src, + SliceSpecs... slices) noexcept), + ( + /* return */ + detail::_subspan_impl(std::make_index_sequence{}, + src, slices...) /*;*/ + )) /* clang-format: on */ } // end namespace experimental diff --git a/src/experimental/__p0009_bits/trait_backports.hpp b/src/experimental/__p0009_bits/trait_backports.hpp index 4a8ec0fe8e..30e28b3067 100644 --- a/src/experimental/__p0009_bits/trait_backports.hpp +++ b/src/experimental/__p0009_bits/trait_backports.hpp @@ -44,8 +44,8 @@ #ifndef MDSPAN_INCLUDE_EXPERIMENTAL_BITS_TRAIT_BACKPORTS_HPP_ #define MDSPAN_INCLUDE_EXPERIMENTAL_BITS_TRAIT_BACKPORTS_HPP_ -#include "macros.hpp" #include "config.hpp" +#include "macros.hpp" #include #include // integer_sequence @@ -58,8 +58,9 @@ #if _MDSPAN_USE_VARIABLE_TEMPLATES namespace std { -#define _MDSPAN_BACKPORT_TRAIT(TRAIT) \ - template _MDSPAN_INLINE_VARIABLE constexpr auto TRAIT##_v = TRAIT::value; +#define _MDSPAN_BACKPORT_TRAIT(TRAIT) \ + template \ + _MDSPAN_INLINE_VARIABLE constexpr auto TRAIT##_v = TRAIT::value; _MDSPAN_BACKPORT_TRAIT(is_assignable) _MDSPAN_BACKPORT_TRAIT(is_constructible) @@ -88,8 +89,7 @@ _MDSPAN_BACKPORT_TRAIT(is_void) namespace std { -template -struct integer_sequence { +template struct integer_sequence { static constexpr std::size_t size() noexcept { return sizeof...(Vals); } using value_type = T; }; @@ -99,28 +99,27 @@ using index_sequence = std::integer_sequence; namespace __detail { -template -struct __make_int_seq_impl; +template struct __make_int_seq_impl; template -struct __make_int_seq_impl> -{ +struct __make_int_seq_impl> { using type = integer_sequence; }; template -struct __make_int_seq_impl< - T, N, I, integer_sequence -> : __make_int_seq_impl> -{ }; +struct __make_int_seq_impl> + : __make_int_seq_impl> {}; } // end namespace __detail template -using make_integer_sequence = typename __detail::__make_int_seq_impl>::type; +using make_integer_sequence = + typename __detail::__make_int_seq_impl>::type; template -using make_index_sequence = typename __detail::__make_int_seq_impl>::type; +using make_index_sequence = + typename __detail::__make_int_seq_impl>::type; template using index_sequence_for = make_index_sequence; @@ -135,17 +134,18 @@ using index_sequence_for = make_index_sequence; //============================================================================== // {{{1 -#if !defined(_MDSPAN_USE_STANDARD_TRAIT_ALIASES) || !_MDSPAN_USE_STANDARD_TRAIT_ALIASES +#if !defined(_MDSPAN_USE_STANDARD_TRAIT_ALIASES) || \ + !_MDSPAN_USE_STANDARD_TRAIT_ALIASES namespace std { -#define _MDSPAN_BACKPORT_TRAIT_ALIAS(TRAIT) \ +#define _MDSPAN_BACKPORT_TRAIT_ALIAS(TRAIT) \ template using TRAIT##_t = typename TRAIT::type; _MDSPAN_BACKPORT_TRAIT_ALIAS(remove_cv) _MDSPAN_BACKPORT_TRAIT_ALIAS(remove_reference) -template +template using enable_if_t = typename enable_if<_B, _T>::type; #undef _MDSPAN_BACKPORT_TRAIT_ALIAS diff --git a/src/experimental/__p0009_bits/type_list.hpp b/src/experimental/__p0009_bits/type_list.hpp index 6683a22bf9..9c642ec40e 100644 --- a/src/experimental/__p0009_bits/type_list.hpp +++ b/src/experimental/__p0009_bits/type_list.hpp @@ -52,40 +52,39 @@ namespace experimental { namespace detail { -template struct __type_list { static constexpr auto __size = sizeof...(_Ts); }; +template struct __type_list { + static constexpr auto __size = sizeof...(_Ts); +}; // Implementation of type_list at() that's heavily optimized for small typelists template struct __type_at; -template > struct __type_at_large_impl; +template > +struct __type_at_large_impl; -template -struct __type_at_entry { }; +template struct __type_at_entry {}; -template -struct __type_at_assign_op_ignore_rest { - template - __type_at_assign_op_ignore_rest<_Result> operator=(_T&&); +template struct __type_at_assign_op_ignore_rest { + template __type_at_assign_op_ignore_rest<_Result> operator=(_T &&); using type = _Result; }; struct __type_at_assign_op_impl { template - __type_at_assign_op_impl operator=(__type_at_entry<_I, _Idx, _T>&&); + __type_at_assign_op_impl operator=(__type_at_entry<_I, _Idx, _T> &&); template - __type_at_assign_op_ignore_rest<_T> operator=(__type_at_entry<_I, _I, _T>&&); + __type_at_assign_op_ignore_rest<_T> operator=(__type_at_entry<_I, _I, _T> &&); }; template -struct __type_at_large_impl<_I, __type_list<_Ts...>, integer_sequence> - : decltype( - _MDSPAN_FOLD_ASSIGN_LEFT(__type_at_assign_op_impl{}, /* = ... = */ __type_at_entry<_I, _Idxs, _Ts>{}) - ) -{ }; +struct __type_at_large_impl<_I, __type_list<_Ts...>, + integer_sequence> + : decltype(_MDSPAN_FOLD_ASSIGN_LEFT( + __type_at_assign_op_impl{}, + /* = ... = */ __type_at_entry<_I, _Idxs, _Ts>{})) {}; template struct __type_at<_I, __type_list<_Ts...>> - : __type_at_large_impl<_I, __type_list<_Ts...>> -{ }; + : __type_at_large_impl<_I, __type_list<_Ts...>> {}; template struct __type_at<0, __type_list<_T0, _Ts...>> { @@ -107,7 +106,6 @@ struct __type_at<3, __type_list<_T0, _T1, _T2, _T3, _Ts...>> { using type = _T3; }; - } // namespace detail //============================================================================== diff --git a/src/experimental/mdspan b/src/experimental/mdspan index 557f607921..ab16a5f38b 100644 --- a/src/experimental/mdspan +++ b/src/experimental/mdspan @@ -42,6 +42,23 @@ */ #pragma once +#ifdef _MSC_FULL_VER +// - 4348: redefinition of default parameter +#pragma warning(push) +#pragma warning(disable : 4348) +#endif + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" +#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" +#pragma clang diagnostic ignored "-Wreserved-id-macro" +#endif + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Werror=undef" +#endif #include "__p0009_bits/accessor_basic.hpp" #include "__p0009_bits/all_type.hpp" @@ -54,4 +71,17 @@ #include "__p0009_bits/layout_stride.hpp" #include "__p0009_bits/macros.hpp" #include "__p0009_bits/static_array.hpp" -#include "__p0009_bits/subspan.hpp" \ No newline at end of file +#include "__p0009_bits/subspan.hpp" + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + +#ifdef __clang__ +// Restore clang diagnostics to previous state. +#pragma clang diagnostic pop +#endif + +#ifdef _MSC_FULL_VER +#pragma warning(pop) +#endif