diff --git a/libcxx/test/std/containers/views/mdspan/foo_customizations.hpp b/libcxx/test/std/containers/views/mdspan/foo_customizations.hpp new file mode 100644 index 0000000000..f359b46d2a --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/foo_customizations.hpp @@ -0,0 +1,228 @@ +#ifndef _FOO_CUSTOMIZATIONS_HPP +#define _FOO_CUSTOMIZATIONS_HPP + +// Taken from the reference implementation repo + +namespace Foo { + template + struct foo_ptr { + T* data; + __MDSPAN_HOST_DEVICE + constexpr foo_ptr(T* ptr):data(ptr) {} + }; + + template + struct foo_accessor { + using offset_policy = foo_accessor; + using element_type = T; + using reference = T&; + using data_handle_type = foo_ptr; + + __MDSPAN_INLINE_FUNCTION + constexpr foo_accessor(int* ptr = nullptr) noexcept { flag = ptr; } + + template + __MDSPAN_INLINE_FUNCTION + constexpr foo_accessor(std::default_accessor) noexcept { flag = nullptr; } + + template + __MDSPAN_INLINE_FUNCTION + constexpr foo_accessor(foo_accessor other) noexcept { flag = other.flag; } + + + constexpr reference access(data_handle_type p, size_t i) const noexcept { + return p.data[i]; + } + + constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept { + return data_handle_type(p.data+i); + } + int* flag; + + friend constexpr void swap(foo_accessor& x, foo_accessor& y) { + x.flag[0] = 99; + y.flag[0] = 77; + std::swap(x.flag, y.flag); + } + }; + +struct layout_foo { + template + class mapping; +}; + +template +class layout_foo::mapping { + public: + using extents_type = Extents; + using index_type = typename extents_type::index_type; + using size_type = typename extents_type::size_type; + using rank_type = typename extents_type::rank_type; + using layout_type = layout_foo; + private: + + static_assert(std::detail::__is_extents_v, + "layout_foo::mapping must be instantiated with a specialization of std::extents."); + static_assert(extents_type::rank() < 3, "layout_foo only supports 0D, 1D and 2D"); + + template + friend class mapping; + + public: + + //-------------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping() noexcept = default; + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr mapping(mapping const&) noexcept = default; + + __MDSPAN_HOST_DEVICE + constexpr mapping(extents_type const& __exts) noexcept + :__extents(__exts) + { } + + __MDSPAN_TEMPLATE_REQUIRES( + class OtherExtents, + /* requires */ ( + __MDSPAN_TRAIT(std::is_constructible, extents_type, OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!std::is_convertible::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(mapping const& other) noexcept // NOLINT(google-explicit-constructor) + :__extents(other.extents()) + { + /* + * TODO: check precondition + * other.required_span_size() is a representable value of type index_type + */ + } + + __MDSPAN_TEMPLATE_REQUIRES( + class OtherExtents, + /* requires */ ( + __MDSPAN_TRAIT(std::is_constructible, extents_type, OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!std::is_convertible::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(std::layout_right::mapping const& other) noexcept // NOLINT(google-explicit-constructor) + :__extents(other.extents()) + {} + + __MDSPAN_TEMPLATE_REQUIRES( + class OtherExtents, + /* requires */ ( + __MDSPAN_TRAIT(std::is_constructible, extents_type, OtherExtents) && + (extents_type::rank() <= 1) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((!std::is_convertible::value)) // needs two () due to comma + __MDSPAN_INLINE_FUNCTION constexpr + mapping(std::layout_left::mapping const& other) noexcept // NOLINT(google-explicit-constructor) + :__extents(other.extents()) + {} + + __MDSPAN_TEMPLATE_REQUIRES( + class OtherExtents, + /* requires */ ( + __MDSPAN_TRAIT(std::is_constructible, extents_type, OtherExtents) + ) + ) + __MDSPAN_CONDITIONAL_EXPLICIT((extents_type::rank() > 0)) + __MDSPAN_INLINE_FUNCTION constexpr + mapping(std::layout_stride::mapping const& other) // NOLINT(google-explicit-constructor) + :__extents(other.extents()) + { + /* + * TODO: check precondition + * other.required_span_size() is a representable value of type index_type + */ + #ifndef __CUDA_ARCH__ + size_t stride = 1; + for(rank_type r=__extents.rank(); r>0; r--) { + assert(stride == other.stride(r-1)); + //if(stride != other.stride(r-1)) + // throw std::runtime_error("Assigning layout_stride to layout_foo with invalid strides."); + stride *= __extents.extent(r-1); + } + #endif + } + + __MDSPAN_INLINE_FUNCTION_DEFAULTED constexpr_DEFAULTED mapping& operator=(mapping const&) noexcept = default; + + __MDSPAN_INLINE_FUNCTION + constexpr const extents_type& extents() const noexcept { + return __extents; + } + + __MDSPAN_INLINE_FUNCTION + constexpr index_type required_span_size() const noexcept { + index_type value = 1; + for(rank_type r=0; r != extents_type::rank(); ++r) value*=__extents.extent(r); + return value; + } + + //-------------------------------------------------------------------------------- + + __MDSPAN_INLINE_FUNCTION + constexpr index_type operator() () const noexcept { return index_type(0); } + + template + __MDSPAN_INLINE_FUNCTION + constexpr index_type operator()(Indx0 idx0) const noexcept { + return static_cast(idx0); + } + + template + __MDSPAN_INLINE_FUNCTION + constexpr index_type operator()(Indx0 idx0, Indx1 idx1) const noexcept { + return static_cast(idx0 * __extents.extent(0) + idx1); + } + + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_unique() noexcept { return true; } + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_exhaustive() noexcept { return true; } + __MDSPAN_INLINE_FUNCTION static constexpr bool is_always_strided() noexcept { return true; } + __MDSPAN_INLINE_FUNCTION constexpr bool is_unique() const noexcept { return true; } + __MDSPAN_INLINE_FUNCTION constexpr bool is_exhaustive() const noexcept { return true; } + __MDSPAN_INLINE_FUNCTION constexpr bool is_strided() const noexcept { return true; } + + __MDSPAN_INLINE_FUNCTION + constexpr index_type stride(rank_type i) const noexcept { + index_type value = 1; + for(rank_type r=extents_type::rank()-1; r>i; r--) value*=__extents.extent(r); + return value; + } + + template + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator==(mapping const& lhs, mapping const& rhs) noexcept { + return lhs.extents() == rhs.extents(); + } + + // In C++ 20 the not equal exists if equal is found +#if !(__MDSPAN_HAS_CXX_20) + template + __MDSPAN_INLINE_FUNCTION + friend constexpr bool operator!=(mapping const& lhs, mapping const& rhs) noexcept { + return lhs.extents() != rhs.extents(); + } +#endif + + // Not really public, but currently needed to implement fully constexpr useable submdspan: + template + constexpr index_type __get_stride(std::extents, std::integer_sequence) const { + return __MDSPAN_FOLD_TIMES_RIGHT((Idx>N? __extents.template __extent():1),1); + } + template + constexpr index_type __stride() const noexcept { + return __get_stride(__extents, std::make_index_sequence()); + } + +private: + __MDSPAN_NO_UNIQUE_ADDRESS extents_type __extents{}; + +}; + +} +#endif + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp new file mode 100644 index 0000000000..aa8afc285c --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/access.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + { + using element_t = int; + std::array d{42,43}; + std::default_accessor a; + + assert( a.access( d.data(), 0 ) == 42 ); + assert( a.access( d.data(), 1 ) == 43 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp new file mode 100644 index 0000000000..240f66c920 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/copy.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + { + using element_t = int; + std::array d{42,43}; + std::default_accessor a0; + std::default_accessor a(a0); + + assert( a.access( d.data(), 0 ) == 42 ); + assert( a.access( d.data(), 1 ) == 43 ); + assert( a.offset( d.data(), 0 ) == d.data() ); + assert( a.offset( d.data(), 1 ) == d.data() + 1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp new file mode 100644 index 0000000000..5a1679b8e7 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.accessor.default.members/offset.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + { + using element_t = int; + std::array d{42,43}; + std::default_accessor a; + + assert( a.offset( d.data(), 0 ) == d.data() ); + assert( a.offset( d.data(), 1 ) == d.data() + 1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp new file mode 100644 index 0000000000..4341f78690 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cmp/compare.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + using index_t = size_t; + + std::extents< index_t, 10 > e0; + std::extents< index_t, 10 > e1; + + assert( e0 == e1 ); + } + + { + using index_t = size_t; + + std::extents< index_t, 10 > e0; + std::extents< index_t, dyn > e1{ 10 }; + + assert( e0 == e1 ); + } + + { + using index_t = size_t; + + std::extents< index_t, 10 > e0; + std::extents< index_t, 10, 10 > e1; + + assert( e0 != e1 ); + } + + { + using index0_t = size_t; + using index1_t = uint8_t; + + std::extents< index0_t, 10 > e0; + std::extents< index1_t, 10 > e1; + + assert( e0 == e1 ); + } + + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp new file mode 100644 index 0000000000..6f3805aed3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/array.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" +#include "../my_int.hpp" + +// TYPED_TEST(TestExtents, array_ctor) +template +void test_array_con() +{ + using TestFixture = TestExtents; + TestFixture t; + + auto e = typename TestFixture::extents_type(t.dyn_sizes); + assert(e == t.exts); +} + +template< class T, class IndexType, size_t N, class = void > +struct is_array_cons_avail : std::false_type {}; + +template< class T, class IndexType, size_t N > +struct is_array_cons_avail< T + , IndexType + , N + , std::enable_if_t< std::is_same< decltype( T{ std::declval>() } ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class IndexType, size_t N > +constexpr bool is_array_cons_avail_v = is_array_cons_avail< T, IndexType, N >::value; + +int main(int, char**) +{ + test_array_con< std::tuple_element_t< 0, extents_test_types > >(); + test_array_con< std::tuple_element_t< 1, extents_test_types > >(); + test_array_con< std::tuple_element_t< 2, extents_test_types > >(); + test_array_con< std::tuple_element_t< 3, extents_test_types > >(); + test_array_con< std::tuple_element_t< 4, extents_test_types > >(); + test_array_con< std::tuple_element_t< 5, extents_test_types > >(); + + static_assert( is_array_cons_avail_v< std::dextents< int,2>, int , 2 > == true , "" ); + + static_assert( is_array_cons_avail_v< std::dextents< int,2>, my_int, 2 > == true , "" ); + + // Constraint: rank consistency + static_assert( is_array_cons_avail_v< std::dextents< int,1>, int , 2 > == false, "" ); + + // Constraint: convertibility + static_assert( is_array_cons_avail_v< std::dextents, my_int_non_convertible , 1 > == false, "" ); + + // Constraint: nonthrow-constructibility + static_assert( is_array_cons_avail_v< std::dextents< int,1>, my_int_non_nothrow_constructible, 1 > == false, "" ); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp new file mode 100644 index 0000000000..9ec1e4d443 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/convertible_to_size_t.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +void check( std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +int main(int, char**) +{ + // TEST(TestExtentsCtorStdArrayConvertibleToSizeT, test_extents_ctor_std_array_convertible_to_size_t) + { + std::array i{2, 2}; + std::dextents e{i}; + + check( e ); + } + + // TEST(TestExtentsCtorStdArrayConvertibleToSizeT, test_extents_ctor_std_span_convertible_to_size_t) + { + std::array i{2, 2}; + std::span s(i.data(),2); + std::dextents e{s}; + + check( e ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp new file mode 100644 index 0000000000..526b2d219a --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/copy.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +// TYPED_TEST(TestExtents, copy_ctor) +template +void test_copy_con() +{ + using TestFixture = TestExtents; + TestFixture t; + + typename TestFixture::extents_type e { t.exts }; + assert(e == t.exts); +} + +template< class T1, class T2, class = void > +struct is_copy_cons_avail : std::false_type {}; + +template< class T1, class T2 > +struct is_copy_cons_avail< T1 + , T2 + , std::enable_if_t< std::is_same< decltype( T1{ std::declval() } ) + , T1 + >::value + > + > : std::true_type {}; + +template< class T1, class T2 > +constexpr bool is_copy_cons_avail_v = is_copy_cons_avail< T1, T2 >::value; + +int main(int, char**) +{ + test_copy_con< std::tuple_element_t< 0, extents_test_types > >(); + test_copy_con< std::tuple_element_t< 1, extents_test_types > >(); + test_copy_con< std::tuple_element_t< 2, extents_test_types > >(); + test_copy_con< std::tuple_element_t< 3, extents_test_types > >(); + test_copy_con< std::tuple_element_t< 4, extents_test_types > >(); + test_copy_con< std::tuple_element_t< 5, extents_test_types > >(); + + static_assert( is_copy_cons_avail_v< std::extents, std::extents > == true , "" ); + + // Constraint: rank consistency + static_assert( is_copy_cons_avail_v< std::extents, std::extents > == false, "" ); + + // Constraint: extents consistency + static_assert( is_copy_cons_avail_v< std::extents, std::extents > == false, "" ); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp new file mode 100644 index 0000000000..13fc88c141 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/default.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +// TYPED_TEST(TestExtents, default_ctor) +template +void test_default_con() +{ + using TestFixture = TestExtents; + + auto e = typename TestFixture::extents_type(); + auto e2 = typename TestFixture::extents_type{}; + assert( e == e2 ); + + for (size_t r = 0; r < e.rank(); ++r) + { + bool is_dynamic = (e.static_extent(r) == std::dynamic_extent); + assert( e.extent(r) == ( is_dynamic ? 0 : e.static_extent(r) ) ); + } +} + +int main(int, char**) +{ + test_default_con< std::tuple_element_t< 0, extents_test_types > >(); + test_default_con< std::tuple_element_t< 1, extents_test_types > >(); + test_default_con< std::tuple_element_t< 2, extents_test_types > >(); + test_default_con< std::tuple_element_t< 3, extents_test_types > >(); + test_default_con< std::tuple_element_t< 4, extents_test_types > >(); + test_default_con< std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp new file mode 100644 index 0000000000..9d900619e3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/param_pack.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../my_int.hpp" + +void check( std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +template< class, class T, class... IndexTypes > +struct is_param_pack_cons_avail : std::false_type {}; + +template< class T, class... IndexTypes > +struct is_param_pack_cons_avail< std::enable_if_t< std::is_same< decltype( T{ std::declval()... } ) + , T + >::value + > + , T + , IndexTypes... + > : std::true_type {}; + +template< class T, class... IndexTypes > +constexpr bool is_param_pack_cons_avail_v = is_param_pack_cons_avail< void, T, IndexTypes... >::value; + +int main(int, char**) +{ + { + std::dextents e{2, 2}; + + check( e ); + } + + { + std::dextents e(2, 2); + + check( e ); + } + +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + { + std::extents e{2, 2}; + + check( e ); + } + + { + std::extents e(2, 2); + + check( e ); + } +#endif + + { + std::dextents e{2, 2}; + + check( e ); + } + + static_assert( is_param_pack_cons_avail_v< std::dextents, int , int > == true , "" ); + + static_assert( is_param_pack_cons_avail_v< std::dextents, my_int, my_int > == true , "" ); + + // Constraint: rank consistency + static_assert( is_param_pack_cons_avail_v< std::dextents, int , int > == false, "" ); + + // Constraint: convertibility + static_assert( is_param_pack_cons_avail_v< std::dextents, my_int_non_convertible > == false, "" ); + + // Constraint: nonthrow-constructibility + static_assert( is_param_pack_cons_avail_v< std::dextents, my_int_non_nothrow_constructible > == false, "" ); + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp new file mode 100644 index 0000000000..cbe0b4f0b0 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.cons/span.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" +#include "../my_int.hpp" + +// TYPED_TEST(TestExtents, array_ctor) +template +void test_span_con() +{ + using TestFixture = TestExtents; + TestFixture t; + + auto s = std::span( t.dyn_sizes ); + auto e = typename TestFixture::extents_type(s); + assert(e == t.exts); +} + +template< class T, class IndexType, size_t N, class = void > +struct is_span_cons_avail : std::false_type {}; + +template< class T, class IndexType, size_t N > +struct is_span_cons_avail< T + , IndexType + , N + , std::enable_if_t< std::is_same< decltype( T{ std::declval>() } ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class IndexType, size_t N > +constexpr bool is_span_cons_avail_v = is_span_cons_avail< T, IndexType, N >::value; + +int main(int, char**) +{ + test_span_con< std::tuple_element_t< 0, extents_test_types > >(); + test_span_con< std::tuple_element_t< 1, extents_test_types > >(); + test_span_con< std::tuple_element_t< 2, extents_test_types > >(); + test_span_con< std::tuple_element_t< 3, extents_test_types > >(); + test_span_con< std::tuple_element_t< 4, extents_test_types > >(); + test_span_con< std::tuple_element_t< 5, extents_test_types > >(); + + static_assert( is_span_cons_avail_v< std::dextents, int , 2 > == true , "" ); + + static_assert( is_span_cons_avail_v< std::dextents, my_int, 2 > == true , "" ); + + // Constraint: rank consistency + static_assert( is_span_cons_avail_v< std::dextents, int , 2 > == false, "" ); + + // Constraint: convertibility + static_assert( is_span_cons_avail_v< std::dextents, my_int_non_convertible , 1 > == false, "" ); + + // Constraint: nonthrow-constructibility + static_assert( is_span_cons_avail_v< std::dextents, my_int_non_nothrow_constructible, 1 > == false, "" ); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp new file mode 100644 index 0000000000..e0d7bba343 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/extent.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +template struct TestExtentsExtent; +template +struct TestExtentsExtent< TEST_TYPE > +: public TestExtents< TEST_TYPE > +{ + using base = TestExtents; + using extents_type = typename TestExtents::extents_type; + + void test_extent() + { + size_t result[extents_type::rank()]; + + extents_type _exts(DynamicSizes...); + for(size_t r=0; r<_exts.rank(); r++ ) + { + result[r] = _exts.extent(r); + } + + int dyn_count = 0; + for(size_t r=0; r +void test_extent() +{ + TestExtentsExtent test; + + test.test_extent(); +} + +int main(int, char**) +{ + test_extent< std::tuple_element_t< 0, extents_test_types > >(); + test_extent< std::tuple_element_t< 1, extents_test_types > >(); + test_extent< std::tuple_element_t< 2, extents_test_types > >(); + test_extent< std::tuple_element_t< 3, extents_test_types > >(); + test_extent< std::tuple_element_t< 4, extents_test_types > >(); + test_extent< std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp new file mode 100644 index 0000000000..de02ff117d --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/rank.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +template struct TestExtentsRank; +template +struct TestExtentsRank< TEST_TYPE > +: public TestExtents< TEST_TYPE > +{ + using base = TestExtents; + using extents_type = typename TestExtents::extents_type; + + void test_rank() + { + size_t result[2]; + + extents_type _exts(DynamicSizes...); + // Silencing an unused warning in nvc++ the condition will never be true + size_t dyn_val = _exts.rank()>0?static_cast(_exts.extent(0)):1; + result[0] = dyn_val > 1e9 ? dyn_val : _exts.rank(); + result[1] = _exts.rank_dynamic(); + + assert( result[0] == base::static_sizes.size() ); + assert( result[1] == base:: dyn_sizes.size() ); + + // Makes sure that `rank()` returns a constexpr + std::array a; + } +}; + +// TYPED_TEST(TestExtents, rank) +template +void test_rank() +{ + TestExtentsRank test; + + test.test_rank(); +} + +int main(int, char**) +{ + test_rank< std::tuple_element_t< 0, extents_test_types > >(); + test_rank< std::tuple_element_t< 1, extents_test_types > >(); + test_rank< std::tuple_element_t< 2, extents_test_types > >(); + test_rank< std::tuple_element_t< 3, extents_test_types > >(); + test_rank< std::tuple_element_t< 4, extents_test_types > >(); + test_rank< std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp new file mode 100644 index 0000000000..ed942b540e --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.obs/static_extent.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.extents.util/extents_util.hpp" + +template struct TestExtentsStaticExtent; +template +struct TestExtentsStaticExtent< TEST_TYPE > +: public TestExtents< TEST_TYPE > +{ + using base = TestExtents; + using extents_type = typename TestExtents::extents_type; + + void test_static_extent() + { + size_t result[extents_type::rank()]; + + extents_type _exts(DynamicSizes...); + for(size_t r=0; r<_exts.rank(); r++) + { + // Silencing an unused warning in nvc++ the condition will never be true + size_t dyn_val = static_cast(_exts.extent(r)); + result[r] = dyn_val > 1e9 ? dyn_val : _exts.static_extent(r); + } + + for(size_t r=0; r +void test_static_extent() +{ + TestExtentsStaticExtent test; + + test.test_static_extent(); +} + +int main(int, char**) +{ + test_static_extent< std::tuple_element_t< 0, extents_test_types > >(); + test_static_extent< std::tuple_element_t< 1, extents_test_types > >(); + test_static_extent< std::tuple_element_t< 2, extents_test_types > >(); + test_static_extent< std::tuple_element_t< 3, extents_test_types > >(); + test_static_extent< std::tuple_element_t< 4, extents_test_types > >(); + test_static_extent< std::tuple_element_t< 5, extents_test_types > >(); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp new file mode 100644 index 0000000000..990ff6f136 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/extents_element.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +void check( std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +struct dummy {}; + +int main(int, char**) +{ + { + std::dextents e{2 , 2}; + + check( e ); + } + + // Mandate: each element of Extents is either equal to dynamic_extent, or is representable as a value of type IndexType + { + + std::dextents e{dummy{}, 2}; + + check( e ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp new file mode 100644 index 0000000000..019081d9eb --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.overview/index_type.fail.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +void check( std::dextents e ) +{ + static_assert( e.rank () == 2, "" ); + static_assert( e.rank_dynamic() == 2, "" ); + + assert( e.extent(0) == 2 ); + assert( e.extent(1) == 2 ); +} + +struct dummy {}; + +int main(int, char**) +{ + { + std::dextents e{2, 2}; + + check( e ); + } + + // Mandate: IndexType is a signed or unsigned integer type + { + + std::dextents e{2, 2}; + + check( e ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp b/libcxx/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp new file mode 100644 index 0000000000..b076ddb620 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.extents.util/extents_util.hpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include + +#define TEST_TYPE \ + std::tuple < \ + std::extents, \ + std::integer_sequence \ + > + + +template struct TestExtents; +template +struct TestExtents< + std::tuple< + std::extents, + std::integer_sequence + > +> +{ + using extents_type = std::extents; + // Double Braces here to make it work with GCC 5 + // Otherwise: "error: array must be initialized with a brace-enclosed initializer" + const std::array static_sizes {{ Extents... }}; + const std::array dyn_sizes {{ DynamicSizes... }}; + extents_type exts { DynamicSizes... }; +}; + +template +using _sizes = std::integer_sequence; +template +using _exts = std::extents; + +constexpr auto dyn = std::dynamic_extent; + +using extents_test_types = std::tuple< + std::tuple< _exts< 10 >, _sizes< > > + , std::tuple< _exts, _sizes<10 > > + , std::tuple< _exts< 10, 3>, _sizes< > > + , std::tuple< _exts, _sizes<10 > > + , std::tuple< _exts< 10, dyn>, _sizes< 3 > > + , std::tuple< _exts, _sizes<10, 3> > +>; diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp new file mode 100644 index 0000000000..7f9a6425f5 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/copy.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + + std::layout_left::mapping> m0{std::dextents{16,32}}; + std::layout_left::mapping> m {m0}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_left::mapping>; + using mapping1_t = std::layout_left::mapping>; + using mappingd_t = std::layout_left::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/ctad.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/ctad.pass.cpp new file mode 100644 index 0000000000..cd862d2fb9 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/ctad.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_left::mapping m{std::extents{16, 32}}; + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp new file mode 100644 index 0000000000..68abb6dba0 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_right_init.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_right::mapping> m_right{std::dextents{16}}; + std::layout_left ::mapping> m( m_right ); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 1 ); + assert( m.extents().rank_dynamic() == 1 ); + assert( m.extents().extent(0) == 16 ); + assert( m.stride(0) == 1 ); + } + + // Constraint: extents_type::rank() <= 1 is true + { + using mapping0_t = std::layout_right::mapping>; + using mapping1_t = std::layout_left ::mapping>; + + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_right::mapping>; + using mapping1_t = std::layout_left ::mapping>; + using mappingd_t = std::layout_left ::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp new file mode 100644 index 0000000000..7b73b354fd --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/layout_stride_init.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::array a{1,16}; + std::layout_stride::mapping> m_stride{std::dextents{16, 32}, a}; + std::layout_left ::mapping> m( m_stride ); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_stride::mapping>; + using mapping1_t = std::layout_left ::mapping>; + using mappingd_t = std::layout_left::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp new file mode 100644 index 0000000000..4b5be506f5 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.cons/list_init.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template +using test_left_type = std::tuple< + typename std::layout_left::template mapping, + std::integer_sequence +>; + +void typed_test_default_ctor_left() +{ + typed_test_default_ctor< test_left_type< std::extents > >(); + typed_test_default_ctor< test_left_type< std::extents, 10 > >(); + typed_test_default_ctor< test_left_type< std::extents, 5 > >(); + typed_test_default_ctor< test_left_type< std::extents, 10 > >(); + typed_test_default_ctor< test_left_type< std::extents > >(); +} + +void typed_test_compatible_left() +{ + typed_test_compatible< test_left_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_default_ctor_left(); + + typed_test_compatible_left(); + + // TEST(TestLayoutLeftListInitialization, test_layout_left_extent_initialization) + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_left::mapping> m{std::dextents{16, 32}}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp new file mode 100644 index 0000000000..b4ecdce7e8 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.fail.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = std::extents< index_t, 64, 128 >; + using ext3d_t = std::extents< index_t, 64, 128, 2 >; + + // Constraint: rank consistency + // This constraint is implemented in a different way in the reference implementation. There will be an overload function + // match but it will return false if the ranks are not consistent + { + constexpr ext2d_t e0; + constexpr ext3d_t e1; + constexpr std::layout_left::mapping m0{ e0 }; + constexpr std::layout_left::mapping m1{ e1 }; + + static_assert( m0 == m1, "" ); // expected-error + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp new file mode 100644 index 0000000000..6c996f4aef --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/compare.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +void typed_test_compare_left() +{ + typed_test_compare< test_left_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compare< test_left_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_left_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_compare_left(); + + using index_t = size_t; + using ext1d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{64, 128}; + std::layout_left::mapping m0{ e }; + std::layout_left::mapping m { m0 }; + + assert( m == m0 ); + } + + { + ext2d_t e0{64, 128}; + ext2d_t e1{16, 32}; + std::layout_left::mapping m0{ e0 }; + std::layout_left::mapping m1{ e1 }; + + assert( m0 != m1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp new file mode 100644 index 0000000000..9eb8ebe9f0 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/extents.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext1d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{16, 32}; + std::layout_left::mapping m{e}; + + assert( m.extents() == e ); + } + + { + ext1d_t e{16}; + std::layout_right::mapping m_right{e}; + std::layout_left ::mapping m{m_right}; + + assert( m.extents() == e ); + } + + { + ext2d_t e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping m_stride{e, a}; + std::layout_left ::mapping m{m_stride}; + + assert( m.extents() == e ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..951ed1c3c5 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_exhaustive.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_left::mapping> m; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + + { + std::extents e{16, 32}; + std::layout_left::mapping> m{ e }; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp new file mode 100644 index 0000000000..4bb5564c3b --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_strided.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::extents e{64, 128}; + std::layout_left::mapping> m{ e }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp new file mode 100644 index 0000000000..6af01adda0 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/is_unique.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_left::mapping> m; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + + { + std::extents e{16, 32}; + std::layout_left::mapping> m{ e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp new file mode 100644 index 0000000000..1166a3a224 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/paren_op.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../my_int.hpp" +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + std::extents e; + std::layout_left::mapping> m{e}; + + assert( m(5) == 5 ); + } + + { + std::extents e{16, 32}; + std::layout_left::mapping> m{e}; + + assert( m(2,1) == 2*1 + 1*16 ); + } + + { + std::extents e{16, 32, 8}; + std::layout_left::mapping> m{e}; + + assert( m(2,1,3) == 2*1 + 1*16 + 3*16*32 ); + } + + // Indices are of a type implicitly convertible to index_type + { + std::extents e{16, 32}; + std::layout_left::mapping> m{e}; + + assert( m(my_int(2),my_int(1)) == 2*1 + 1*16 ); + } + + // Constraints + { + std::extents e; + std::layout_left::mapping> m{e}; + + unused( m ); + + static_assert( is_paren_op_avail_v< decltype(m), index_t > == true, "" ); + + // rank consistency + static_assert( is_paren_op_avail_v< decltype(m), index_t, index_t > == false, "" ); + + // convertibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_convertible > == false, "" ); + + // nothrow-constructibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_nothrow_constructible > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp new file mode 100644 index 0000000000..6d29525aa7 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/required_span_size.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = std::extents; + + { + std::extents e; + std::layout_left::mapping> m{e}; + + assert( m.required_span_size() == 16 ); + } + + { + ext2d_t e{16, 32}; + std::layout_left::mapping m{e}; + + assert( m.required_span_size() == 16*32 ); + } + + { + ext2d_t e{16, 0}; + std::layout_left::mapping m{e}; + + assert( m.required_span_size() == 0 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp new file mode 100644 index 0000000000..6c3e19a5e7 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.left.obs/stride.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext0d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{64, 128}; + std::layout_left::mapping m{ e }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 64 ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == true , "" ); + } + + { + ext2d_t e{1, 128}; + std::layout_left::mapping m{ e }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 1 ); + } + + // constraint: extents_­type?::?rank() > 0 + { + ext0d_t e{}; + std::layout_left::mapping m{ e }; + + unused( m ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp new file mode 100644 index 0000000000..adb4252475 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/copy.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + + std::layout_right::mapping> m0{std::dextents{16,32}}; + std::layout_right::mapping> m {m0}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_right::mapping>; + using mapping1_t = std::layout_right::mapping>; + using mappingd_t = std::layout_right::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/ctad.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/ctad.pass.cpp new file mode 100644 index 0000000000..169f1ac71f --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/ctad.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_right::mapping m{std::extents{16, 32}}; + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp new file mode 100644 index 0000000000..e71b4de4bc --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_left_init.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_left ::mapping> m_right{std::dextents{16}}; + std::layout_right::mapping> m( m_right); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 1 ); + assert( m.extents().rank_dynamic() == 1 ); + assert( m.extents().extent(0) == 16 ); + assert( m.stride(0) == 1 ); + } + + // Constraint: extents_type::rank() <= 1 is true + { + using mapping0_t = std::layout_left::mapping>; + using mapping1_t = std::layout_right::mapping>; + + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_left::mapping>; + using mapping1_t = std::layout_right::mapping>; + using mappingd_t = std::layout_right::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp new file mode 100644 index 0000000000..c41a169b1f --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/layout_stride_init.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::array a{32,1}; + std::layout_stride::mapping> m_stride{std::dextents{16, 32}, a}; + std::layout_right ::mapping> m( m_stride ); + + static_assert( m.is_exhaustive() == true, "" ); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + // Constraint: is_constructible_v is true + { + using mapping0_t = std::layout_stride::mapping>; + using mapping1_t = std::layout_right ::mapping>; + using mappingd_t = std::layout_right ::mapping>; + + static_assert( is_cons_avail_v< mappingd_t, mapping0_t > == true , "" ); + static_assert( is_cons_avail_v< mapping1_t, mapping0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp new file mode 100644 index 0000000000..718147daf9 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.cons/list_init.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template +using test_right_type = std::tuple< + typename std::layout_right::template mapping, + std::integer_sequence +>; + +void typed_test_default_ctor_right() +{ + typed_test_default_ctor< test_right_type< std::extents > >(); + typed_test_default_ctor< test_right_type< std::extents, 10 > >(); + typed_test_default_ctor< test_right_type< std::extents, 5 > >(); + typed_test_default_ctor< test_right_type< std::extents, 10 > >(); + typed_test_default_ctor< test_right_type< std::extents > >(); +} + +void typed_test_compatible_right() +{ + typed_test_compatible< test_right_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compatible< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compatible< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_default_ctor_right(); + + typed_test_compatible_right(); + + // TEST(TestLayoutRightListInitialization, test_layout_right_extent_initialization) + { + std::layout_right::mapping> m{std::dextents{16, 32}}; + + static_assert( m.is_exhaustive() == true, "" ); + static_assert( m.extents().rank() == 2 , "" ); + static_assert( m.extents().rank_dynamic() == 2 , "" ); + + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp new file mode 100644 index 0000000000..6dbbd4ce7d --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.fail.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = std::extents< index_t, 64, 128 >; + using ext3d_t = std::extents< index_t, 64, 128, 2 >; + + // Constraint: rank consistency + // This constraint is implemented in a different way in the reference implementation. There will be an overload function + // match but it will return false if the ranks are not consistent + { + constexpr ext2d_t e0; + constexpr ext3d_t e1; + constexpr std::layout_right::mapping m0{ e0 }; + constexpr std::layout_right::mapping m1{ e1 }; + + static_assert( m0 == m1, "" ); // expected-error + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp new file mode 100644 index 0000000000..a4514dd652 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/compare.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +void typed_test_compare_right() +{ + typed_test_compare< test_right_type_pair<_exts, _sizes<10 >, _exts< 10 >, _sizes< >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5 >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts, _sizes< 5 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, 10 >, _sizes< >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts< 5, dyn >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10 >, _sizes< >, _exts, _sizes< 5 >> >(); + typed_test_compare< test_right_type_pair<_exts, _sizes< 5, 10>, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts< 5, dyn, 15 >, _sizes<10 >> >(); + typed_test_compare< test_right_type_pair<_exts< 5, 10, 15>, _sizes< >, _exts, _sizes< 5, 10, 15>> >(); +} + +int main(int, char**) +{ + typed_test_compare_right(); + + using index_t = size_t; + using ext1d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{64, 128}; + std::layout_right::mapping m0{ e }; + std::layout_right::mapping m { m0 }; + + assert( m == m0 ); + } + + { + ext2d_t e0{64, 128}; + ext2d_t e1{16, 32}; + std::layout_right::mapping m0{ e0 }; + std::layout_right::mapping m1{ e1 }; + + assert( m0 != m1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp new file mode 100644 index 0000000000..05ea13ef35 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/extents.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext1d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{16, 32}; + std::layout_right::mapping m{e}; + + assert( m.extents() == e ); + } + + { + ext1d_t e{16}; + std::layout_left ::mapping m_left{e}; + std::layout_right::mapping m( m_left ); + + assert( m.extents() == e ); + } + + { + ext2d_t e{16, 32}; + std::array a{32,1}; + std::layout_stride::mapping m_stride{e, a}; + std::layout_right ::mapping m( m_stride ); + + assert( m.extents() == e ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..072860754c --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_exhaustive.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_right::mapping> m; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + + { + std::extents e{16, 32}; + std::layout_right::mapping> m{ e }; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp new file mode 100644 index 0000000000..8c2e2d79fb --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_strided.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::extents e{64, 128}; + std::layout_right::mapping> m{ e }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp new file mode 100644 index 0000000000..f7483cfdbc --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/is_unique.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + + { + std::layout_right::mapping> m; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + + { + std::extents e{16, 32}; + std::layout_right::mapping> m{ e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp new file mode 100644 index 0000000000..67ba37ff11 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/paren_op.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../my_int.hpp" +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + std::extents e; + std::layout_right::mapping> m{e}; + + assert( m(5) == 5 ); + } + + { + std::extents e{16, 32}; + std::layout_right::mapping> m{e}; + + assert( m(2,1) == 2*32 + 1*1 ); + } + + { + std::extents e{16, 32, 8}; + std::layout_right::mapping> m{e}; + + assert( m(2,1,3) == 2*32*8 + 1*8 + 3*1 ); + } + + // Indices are of a type implicitly convertible to index_type + { + std::extents e{16, 32}; + std::layout_right::mapping> m{e}; + + assert( m(my_int(2),my_int(1)) == 2*32 + 1*1 ); + } + + // Constraints + { + std::extents e; + std::layout_right::mapping> m{e}; + + unused( m ); + + static_assert( is_paren_op_avail_v< decltype(m), index_t > == true, "" ); + + // rank consistency + static_assert( is_paren_op_avail_v< decltype(m), index_t, index_t > == false, "" ); + + // convertibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_convertible > == false, "" ); + + // nothrow-constructibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_nothrow_constructible > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp new file mode 100644 index 0000000000..ff49b9ddde --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/required_span_size.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = std::extents; + + { + std::extents e; + std::layout_right::mapping> m{e}; + + assert( m.required_span_size() == 16 ); + } + + { + ext2d_t e{16, 32}; + std::layout_right::mapping m{e}; + + assert( m.required_span_size() == 16*32 ); + } + + { + ext2d_t e{16, 0}; + std::layout_right::mapping m{e}; + + assert( m.required_span_size() == 0 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp new file mode 100644 index 0000000000..fa37757e0e --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.right.obs/stride.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext0d_t = std::extents; + using ext2d_t = std::extents; + + { + ext2d_t e{64, 128}; + std::layout_right::mapping m{ e }; + + assert( m.stride(0) == 128 ); + assert( m.stride(1) == 1 ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == true , "" ); + } + + { + ext2d_t e{64, 1}; + std::layout_right::mapping m{ e }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 1 ); + } + + // constraint: extents_type::rank() > 0 + { + ext0d_t e{}; + std::layout_right::mapping m{ e }; + + unused( m ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/ctad.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/ctad.pass.cpp new file mode 100644 index 0000000000..5836dbecef --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/ctad.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_stride::mapping m{std::dextents{16, 32}, std::array{1, 128}}; + + assert( m.is_exhaustive() == false); + + assert( m.extents().rank() == 2 ); + assert( m.extents().rank_dynamic() == 2 ); + assert( m.extents().extent(0) == 16 ); + assert( m.extents().extent(1) == 32 ); + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp new file mode 100644 index 0000000000..6a5cdf80bd --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.cons/list_init.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +#define CHECK_MAPPING(m) \ + assert( m.is_exhaustive() == false); \ + assert( m.extents().rank() == 2 ); \ + assert( m.extents().rank_dynamic() == 2 ); \ + assert( m.extents().extent(0) == 16 ); \ + assert( m.extents().extent(1) == 32 ); \ + assert( m.stride(0) == 1 ); \ + assert( m.stride(1) == 128 ); \ + assert( m.strides()[0] == 1 ); \ + assert( m.strides()[1] == 128 ) + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + // From a span + { + typedef int data_t ; + typedef size_t index_t; + + using my_ext = typename std::extents; + + std::array a{1, 128}; + std::span s(a.data(), 2); + std::layout_stride::mapping> m{std::dextents{16, 32}, s}; + + CHECK_MAPPING(m); + } + + // TEST(TestLayoutStrideListInitialization, test_list_initialization) + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_stride::mapping> m{std::dextents{16, 32}, std::array{1, 128}}; + + CHECK_MAPPING(m); + } + + // From another mapping + { + typedef int data_t ; + typedef size_t index_t; + + std::layout_stride::mapping> m0{std::dextents{16, 32}, std::array{1, 128}}; + std::layout_stride::mapping> m{m0}; + + CHECK_MAPPING(m); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp new file mode 100644 index 0000000000..d7b456ad64 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.fail.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = std::extents< index_t, 64, 128 >; + using ext3d_t = std::extents< index_t, 64, 128, 2 >; + + // Constraint: rank consistency + { + constexpr ext2d_t e0; + constexpr ext3d_t e1; + constexpr std::array a0{1,64}; + constexpr std::array a1{1,64,64*128}; + constexpr std::layout_stride::mapping m0{ e0, a0 }; + constexpr std::layout_stride::mapping m1{ e1, a1 }; + + static_assert( m0 == m1, "" ); // expected-error + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp new file mode 100644 index 0000000000..8f0f42e164 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/compare.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext1d_t = std::extents; + using ext2d_t = std::extents; + + { + std::extents e; + std::array a{1,16}; + std::layout_stride::mapping m0{e, a}; + std::layout_stride::mapping m {m0}; + + assert( m0 == m ); + } + + { + using index2_t = int32_t; + + std::extents e; + std::array a{1,16}; + std::extents e2; + std::array a2{1,16}; + std::layout_stride::mapping m1{e , a }; + std::layout_stride::mapping m2{e2, a2}; + + assert( m1 == m2 ); + } + + { + std::extents e; + std::array a0{1,16}; + std::array a1{1,32}; + std::layout_stride::mapping m0{e, a0}; + std::layout_stride::mapping m1{e, a1}; + + assert( m0 != m1 ); + } + + { + std::extents e; + std::array a{1,16}; + std::layout_stride::mapping m{e, a}; + std::layout_left ::mapping m_left{e}; + + assert( m == m_left ); + } + + { + std::extents e; + std::array a{32,1}; + std::layout_stride::mapping m{e, a}; + std::layout_right ::mapping m_right{e}; + + assert( m == m_right ); + } + + { + std::extents e0; + std::extents e1; + std::array a{1,16}; + std::layout_stride::mapping m0{e0, a}; + std::layout_stride::mapping m1{e1, a}; + + assert( m0 != m1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp new file mode 100644 index 0000000000..597d21bc58 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/extents.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = std::extents; + + { + ext2d_t e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping m{e, a}; + + assert( m.extents() == e ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..2ccdc28f51 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_exhaustive.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + std::extents e; + std::array a{1}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + std::extents e; + std::array a{2}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + { + std::extents e; + std::array a{1,16}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + std::extents e{16, 32}; + std::array a{1,128}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + { + std::extents e{16, 32, 4}; + std::array a{1,16*4,16}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + std::extents e{16, 32, 4}; + std::array a{1,16*4+1,16}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp new file mode 100644 index 0000000000..06c0043388 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_strided.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + { + using dexts = std::dextents; + std::array a{1, 128}; + + std::layout_stride::mapping m{dexts{16, 32}, a}; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp new file mode 100644 index 0000000000..a1c19b5b1a --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/is_unique.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + std::extents e; + std::array a{1}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + { + std::extents e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping> m{e, a}; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp new file mode 100644 index 0000000000..7f440dc4c3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/paren_op.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../my_int.hpp" +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + + { + std::extents e; + std::array a{1}; + std::layout_stride::mapping> m{e, a}; + + assert( m(8) == 8 ); + } + + { + std::extents e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping> m{e, a}; + + assert( m(8,16) == 8*1 + 16*16 ); + } + + { + std::extents e{32}; + std::array a{1,24}; + std::layout_stride::mapping> m{e, a}; + + assert( m(8,16) == 8*1 + 16*24 ); + } + + { + std::extents e{32}; + std::array a{48,1}; + std::layout_stride::mapping> m{e, a}; + + assert( m(8,16) == 8*48 + 16*1 ); + } + + // Indices are of a type implicitly convertible to index_type + { + std::extents e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping> m{e, a}; + + assert( m(my_int(8),my_int(16)) == 8*1 + 16*16 ); + } + + // Constraints + { + std::extents e; + std::array a{1}; + std::layout_stride::mapping> m{e, a}; + + static_assert( is_paren_op_avail_v< decltype(m), index_t > == true, "" ); + + // rank consistency + static_assert( is_paren_op_avail_v< decltype(m), index_t, index_t > == false, "" ); + + // convertibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_convertible > == false, "" ); + + // nothrow-constructibility + static_assert( is_paren_op_avail_v< decltype(m), my_int_non_nothrow_constructible > == false, "" ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp new file mode 100644 index 0000000000..9972901a0e --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/required_span_size.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = int; + using ext2d_t = std::extents; + + { + std::extents e; + std::array a{1}; + std::layout_stride::mapping> m{e, a}; + + assert( m.required_span_size() == 16 ); + } + + { + ext2d_t e{16, 32}; + std::array a{1,16}; + std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 16*32 ); + } + + { + ext2d_t e{16, 0}; + std::array a{1,1}; + std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 0 ); + } + + { + std::extents e{32}; + std::array a{1,24}; + std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 32*24 - (24-16) ); + } + + { + std::extents e{32}; + std::array a{48,1}; + std::layout_stride::mapping m{e, a}; + + assert( m.required_span_size() == 16*48 - (48-32) ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp new file mode 100644 index 0000000000..508a1a8d5b --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/stride.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.layout.util/layout_util.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext0d_t = std::extents; + using ext2d_t = std::extents; + + auto e = std::dextents{16, 32}; + auto s_arr = std::array {1, 128}; + + // From a span + { + std::span s(s_arr.data(), 2); + std::layout_stride::mapping m{e, s}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == true , "" ); + } + + // From an array + { + std::layout_stride::mapping m{e, s_arr}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + } + + // From another mapping + { + std::layout_stride::mapping m0{e, s_arr}; + std::layout_stride::mapping m{m0}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + } + + // constraint: extents_­type?::?rank() > 0 + { + ext0d_t e{}; + std::layout_stride::mapping m{ e, std::array{} }; + + unused( m ); + + static_assert( is_stride_avail_v< decltype(m), index_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp new file mode 100644 index 0000000000..260a3e5aa9 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.stride.obs/strides.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using index_t = size_t; + using ext2d_t = std::extents; + + auto e = std::dextents{16, 32}; + auto s_arr = std::array {1, 128}; + + // From a span + { + std::span s(s_arr.data(), 2); + std::layout_stride::mapping m{e, s}; + + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } + + // From an array + { + std::layout_stride::mapping m{e, s_arr}; + + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } + + // From another mapping + { + std::layout_stride::mapping m0{e, s_arr}; + std::layout_stride::mapping m{m0}; + + assert( m.strides()[0] == 1 ); + assert( m.strides()[1] == 128 ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp b/libcxx/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp new file mode 100644 index 0000000000..93f6310b14 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.layout.util/layout_util.hpp @@ -0,0 +1,168 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include + +template struct TestLayoutCtors; +template +struct TestLayoutCtors +>> +{ + using mapping_type = Mapping; + using extents_type = typename mapping_type::extents_type; + Mapping map = { extents_type{ DynamicSizes... } }; +}; + +template void typed_test_default_ctor() +// TYPED_TEST( TestLayoutCtors, default_ctor ) +{ + // Default constructor ensures extents() == Extents() is true. + using TestFixture = TestLayoutCtors; + auto m = typename TestFixture::mapping_type(); + assert( m .extents() == typename TestFixture::extents_type() ); + auto m2 = typename TestFixture::mapping_type{}; + assert( m2.extents() == typename TestFixture::extents_type{} ); + assert( m == m2 ); +} + +template struct TestLayoutCompatCtors; +template +struct TestLayoutCompatCtors, + Mapping2, + std::integer_sequence +>> { + using mapping_type1 = Mapping; + using mapping_type2 = Mapping2; + using extents_type1 = std::remove_reference_t().extents())>; + using extents_type2 = std::remove_reference_t().extents())>; + Mapping map1 = { extents_type1{ DynamicSizes... } }; + Mapping2 map2 = { extents_type2{ DynamicSizes2... } }; +}; + +template void typed_test_compatible() +//TYPED_TEST(TestLayout{Left|Right}CompatCtors, compatible_construct_{1|2}) { +//TYPED_TEST(TestLayout{Left|Right}CompatCtors, compatible_assign_{1|2}) { +{ + using TestFixture = TestLayoutCompatCtors; + + // Construct + { + TestFixture t; + + auto m1 = typename TestFixture::mapping_type1(t.map2); + assert( m1.extents() == t.map2.extents() ); + + auto m2 = typename TestFixture::mapping_type2(t.map1); + assert( m2.extents() == t.map1.extents() ); + } + + // Assign + { + TestFixture t; + +#if __MDSPAN_HAS_CXX_17 + if constexpr ( std::is_convertible::value ) + { + t.map1 = t.map2; + } + else + { + t.map1 = typename TestFixture::mapping_type1( t.map2 ); + } +#else + t.map1 = typename TestFixture::mapping_type1( t.map2 ); +#endif + + assert( t.map1.extents() == t.map2.extents() ); + } +} + +template void typed_test_compare() +{ + using TestFixture = TestLayoutCompatCtors; + + { + TestFixture t; + + auto m1 = typename TestFixture::mapping_type1(t.map2); + assert( m1 == t.map2 ); + + auto m2 = typename TestFixture::mapping_type2(t.map1); + assert( m2 == t.map1 ); + } +} + +template +using _sizes = std::integer_sequence; +template +using _exts = std::extents; + +template +using test_left_type_pair = std::tuple< + typename std::layout_left::template mapping, S1, + typename std::layout_left::template mapping, S2 +>; + +template +using test_right_type_pair = std::tuple< + typename std::layout_right::template mapping, S1, + typename std::layout_right::template mapping, S2 +>; + +template< class T1, class T2, class = void > +struct is_cons_avail : std::false_type {}; + +template< class T1, class T2 > +struct is_cons_avail< T1 + , T2 + , std::enable_if_t< std::is_same< decltype( T1{ std::declval() } ) + , T1 + >::value + > + > : std::true_type {}; + +template< class T1, class T2 > +constexpr bool is_cons_avail_v = is_cons_avail< T1, T2 >::value; + +template< class, class T, class... Indicies > +struct is_paren_op_avail : std::false_type {}; + +template< class T, class... Indicies > +struct is_paren_op_avail< std::enable_if_t< std::is_same< decltype(std::declval()(std::declval()...)) + , typename T::index_type + >::value + > + , T + , Indicies... + > : std::true_type {}; + +template< class T, class... Indicies > +constexpr bool is_paren_op_avail_v = is_paren_op_avail< void, T, Indicies... >::value; + +template< class T, class RankType, class = void > +struct is_stride_avail : std::false_type {}; + +template< class T, class RankType > +struct is_stride_avail< T + , RankType + , std::enable_if_t< std::is_same< decltype( std::declval().stride( std::declval() ) ) + , typename T::index_type + >::value + > + > : std::true_type {}; + +template< class T, class RankType > +constexpr bool is_stride_avail_v = is_stride_avail< T, RankType >::value; + +// Workaround for variables that are only used in static_assert's +template< typename T > +constexpr bool unused( T && ) { return true; } diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp new file mode 100644 index 0000000000..e572c5422f --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/array_init_extents.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class T, class DataHandleT, class SizeType, size_t N, class = void > +struct is_array_cons_avail : std::false_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +struct is_array_cons_avail< T + , DataHandleT + , SizeType + , N + , std::enable_if_t< std::is_same< decltype( T{ std::declval() + , std::declval>() + } + ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +constexpr bool is_array_cons_avail_v = is_array_cons_avail< T, DataHandleT, SizeType, N >::value; + +int main(int, char**) +{ + // extents from std::array + { + std::array d{42}; + std::mdspan> m{ d.data(), std::array{64, 128} }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // data from cptr, extents from std::array + { + using mdspan_t = std::mdspan>; + + std::array d{42}; + const int* const ptr = d.data(); + + static_assert( is_array_cons_avail_v< mdspan_t, decltype(ptr), int, 2 > == true, "" ); + + mdspan_t m{ptr, std::array{64, 128}}; + + static_assert( std::is_same::value, "" ); + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_convertible; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: (is_nothrow_constructible && ...) is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_nothrow_constructible; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: N == rank() || N == rank_dynamic() is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = int; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, int, 1 > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_stride >; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_right, Foo::my_accessor >; + + static_assert( is_array_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp new file mode 100644 index 0000000000..c3a403d0fd --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/copy.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class T1, class T0, class = void > +struct is_copy_cons_avail : std::false_type {}; + +template< class T1, class T0 > +struct is_copy_cons_avail< T1 + , T0 + , std::enable_if_t< std::is_same< decltype( T1{ std::declval() } ), T1 >::value > + > : std::true_type {}; + +template< class T1, class T0 > +constexpr bool is_copy_cons_avail_v = is_copy_cons_avail< T1, T0 >::value; + +int main(int, char**) +{ + // copy constructor + { + using ext_t = std::extents; + using mdspan_t = std::mdspan; + + static_assert( is_copy_cons_avail_v< mdspan_t, mdspan_t > == true, "" ); + + std::array d{42}; + mdspan_t m0{ d.data(), ext_t{64, 128} }; + mdspan_t m { m0 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // copy constructor with conversion + { + std::array d{42}; + std::mdspan> m0{ d.data(), std::extents{} }; + std::mdspan> m { m0 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: is_constructible_v&> is true + { + using mdspan1_t = std::mdspan, std::layout_left >; + using mdspan0_t = std::mdspan, std::layout_right>; + + static_assert( is_copy_cons_avail_v< mdspan1_t, mdspan0_t > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan1_t = std::mdspan, std::layout_right, Foo::my_accessor>; + using mdspan0_t = std::mdspan, std::layout_right>; + + static_assert( is_copy_cons_avail_v< mdspan1_t, mdspan0_t > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp new file mode 100644 index 0000000000..bfad7aedbd --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_c_array.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, ctad_carray) + { + int data[5] = {1,2,3,4,5}; + std::mdspan m(data); + + static_assert(std::is_same::value == true, ""); + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == &data[0]); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 0 ); + assert(m.static_extent(0) == 5 ); + assert(m.extent(0) == 5 ); + assert(__MDSPAN_OP(m, 2) == 3 ); + + std::mdspan m2(data, 3); + + static_assert(std::is_same::value == true, ""); + static_assert(m2.is_exhaustive() == true, ""); + + assert(m2.data_handle() == &data[0]); + assert(m2.rank() == 1 ); + assert(m2.rank_dynamic() == 1 ); + assert(m2.extent(0) == 3 ); + assert(__MDSPAN_OP(m2, 2) == 3 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp new file mode 100644 index 0000000000..2309e21b04 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_const_c_array.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, ctad_const_carray) + { + const int data[5] = {1,2,3,4,5}; + std::mdspan m(data); + + static_assert(std::is_same::value == true, ""); + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == &data[0]); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 0 ); + assert(m.static_extent(0) == 5 ); + assert(m.extent(0) == 5 ); + assert(__MDSPAN_OP(m, 2) == 3 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp new file mode 100644 index 0000000000..2da5193352 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_copy.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + constexpr auto dyn = std::dynamic_extent; + + // copy constructor + { + std::array d{42}; + std::mdspan> m0{ d.data(), std::extents{64, 128} }; + std::mdspan m{ m0 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp new file mode 100644 index 0000000000..93b787d35b --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +#define CHECK_MDSPAN(m,d) \ + static_assert(m.is_exhaustive(), ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.rank() == 2 ); \ + assert(m.rank_dynamic() == 2 ); \ + assert(m.extent(0) == 64 ); \ + assert(m.extent(1) == 128 ) + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, extents_object) + { + std::array d{42}; + std::mdspan m{d.data(), std::extents{64, 128}}; + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, extents_object_move) + { + std::array d{42}; + std::mdspan m{d.data(), std::move(std::extents{64, 128})}; + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, extents_std_array) + { + std::array d{42}; + std::mdspan m{d.data(), std::array{64, 128}}; + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, cptr_extents_std_array) + { + std::array d{42}; + const int* const ptr= d.data(); + std::mdspan m{ptr, std::array{64, 128}}; + + static_assert(std::is_same::value, ""); + + CHECK_MDSPAN(m,d); + } + + // extents from std::span + { + std::array d{42}; + std::array sarr{64, 128}; + std::mdspan m{d.data(), std::span{sarr}}; + + CHECK_MDSPAN(m,d); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp new file mode 100644 index 0000000000..70066ac2ab --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_extents_pack.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, extents_pack) + { + std::array d{42}; + std::mdspan m(d.data(), 64, 128); + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 64 ); + assert(m.extent(1) == 128 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp new file mode 100644 index 0000000000..02c8525bc3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_layouts.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +#define CHECK_MDSPAN(m,d,exhaust,s0,s1) \ + static_assert(m.rank() == 2 , ""); \ + static_assert(m.rank_dynamic() == 2 , ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.extent(0) == 16 ); \ + assert(m.extent(1) == 32 ); \ + assert(m.stride(0) == s0 ); \ + assert(m.stride(1) == s1 ); \ + assert(m.is_exhaustive() == exhaust ) + + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, layout_left) + { + std::array d{42}; + std::mdspan m0{d.data(), std::layout_left::mapping{std::extents{16, 32}}}; + + CHECK_MDSPAN( m0, d, true, 1, 16 ); + } + + // TEST(TestMdspanCTAD, layout_right) + { + std::array d{42}; + std::mdspan m0{d.data(), std::layout_right::mapping{std::extents{16, 32}}}; + + CHECK_MDSPAN( m0, d, true, 32, 1 ); + } + + // TEST(TestMdspanCTAD, layout_stride) + { + std::array d{42}; + std::mdspan m0{d.data(), std::layout_stride::mapping{std::extents{16, 32}, std::array{1, 128}}}; + + CHECK_MDSPAN( m0, d, false, 1, 128 ); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp new file mode 100644 index 0000000000..0b3c2bace1 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_mapping.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + constexpr auto dyn = std::dynamic_extent; + + // mapping + { + using data_t = int; + using index_t = size_t; + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + std::mdspan m{ d.data(), map }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // mapping and accessor + { + using data_t = int; + using index_t = size_t; + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + std::default_accessor a; + std::mdspan m{ d.data(), map, a }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp new file mode 100644 index 0000000000..4de93f64b9 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/ctad_pointer.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +// No CTAD in C++14 or earlier +//UNSUPPORTED: c++14 + +#include +#include + +#define CHECK_MDSPAN(m,d) \ + static_assert(std::is_same::value, ""); \ + static_assert(m.is_exhaustive(), ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.rank() == 0 ); \ + assert(m.rank_dynamic() == 0 ) + +int main(int, char**) +{ +#ifdef __MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + // TEST(TestMdspanCTAD, ctad_pointer) + { + std::array d = {1,2,3,4,5}; + int* ptr = d.data(); + std::mdspan m(ptr); + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, ctad_pointer_tmp) + { + std::array d = {1,2,3,4,5}; + std::mdspan m(d.data()); + + CHECK_MDSPAN(m,d); + } + + // TEST(TestMdspanCTAD, ctad_pointer_move) + { + std::array d = {1,2,3,4,5}; + int* ptr = d.data(); + std::mdspan m(std::move(ptr)); + + CHECK_MDSPAN(m,d); + } +#endif + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp new file mode 100644 index 0000000000..1ecf269e72 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_accessor.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../foo_customizations.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + using data_t = int; + using acc_t = Foo::foo_accessor; + using index_t = size_t; + + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + acc_t a; + std::mdspan, std::layout_left, acc_t> m{ d.data(), map, a }; + + static_assert(m.is_exhaustive(), ""); + //assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 64 ); + assert(m.extent(1) == 128 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp new file mode 100644 index 0000000000..c07d554ead --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/custom_layout.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../foo_customizations.hpp" + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + using map_t = Foo::layout_foo::template mapping>; + + { + using data_t = int; + using lay_t = Foo::layout_foo; + using index_t = size_t; + + std::array d{42}; + lay_t::mapping> map{std::dextents{64, 128}}; + std::mdspan, lay_t> m{ d.data(), map }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp new file mode 100644 index 0000000000..1eba3cc1f4 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/data_c_array.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + data_t data[1] = {42}; + std::mdspan> m(data); + auto val = m(0); + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == data ); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 0 ); + assert(m.extent(0) == 1 ); + assert(m.static_extent(0) == 1 ); + assert(m.stride(0) == 1 ); + assert(val == 42 ); + assert(m.size() == 1 ); + assert(m.empty() == false); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp new file mode 100644 index 0000000000..1ebc1778f5 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/default.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + std::mdspan> m; + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == nullptr); + assert(m.rank() == 1 ); + assert(m.rank_dynamic() == 1 ); + assert(m.extent(0) == 0 ); + assert(m.static_extent(0) == dyn ); + assert(m.stride(0) == 1 ); + assert(m.size() == 0 ); + assert(m.empty() == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp new file mode 100644 index 0000000000..dc38f72369 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class T, class DataHandleType, class ExtentsType, class = void > +struct is_extents_cons_avail : std::false_type {}; + +template< class T, class DataHandleType, class ExtentsType > +struct is_extents_cons_avail< T + , DataHandleType + , ExtentsType + , std::enable_if_t< std::is_same< decltype( T{ std::declval() + , std::declval() + } + ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class DataHandleType, class ExtentsType > +constexpr bool is_extents_cons_avail_v = is_extents_cons_avail< T, DataHandleType, ExtentsType >::value; + +int main(int, char**) +{ + // extents from extents object + { + using ext_t = std::extents; + std::array d{42}; + std::mdspan m{ d.data(), ext_t{64, 128} }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // extents from extents object move + { + using ext_t = std::extents< int, dyn, dyn >; + using mdspan_t = std::mdspan< int, ext_t >; + + static_assert( is_extents_cons_avail_v< mdspan_t, int *, ext_t > == true, "" ); + + std::array d{42}; + mdspan_t m{ d.data(), std::move(ext_t{64, 128}) }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: is_constructible_v is true + { + using ext_t = std::extents< int, 16, 16 >; + using mdspan_t = std::mdspan< int, ext_t, std::layout_stride >; + + static_assert( is_extents_cons_avail_v< mdspan_t, int *, ext_t > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using ext_t = std::extents< int, 16, 16 >; + using mdspan_t = std::mdspan< int, ext_t, std::layout_right, Foo::my_accessor >; + + static_assert( is_extents_cons_avail_v< mdspan_t, int *, ext_t > == false, "" ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp new file mode 100644 index 0000000000..8b885d471d --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/extents_pack.pass.cpp @@ -0,0 +1,111 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class, class T, class DataHandleT, class... SizeTypes > +struct is_param_pack_cons_avail : std::false_type {}; + +template< class T, class DataHandleT, class... SizeTypes > +struct is_param_pack_cons_avail< std::enable_if_t< std::is_same< decltype( T{ std::declval() + , std::declval()... + } + ) + , T + >::value + > + , T + , DataHandleT + , SizeTypes... + > : std::true_type {}; + +template< class T, class DataHandleT, class... SizeTypes > +constexpr bool is_param_pack_cons_avail_v = is_param_pack_cons_avail< void, T, DataHandleT, SizeTypes... >::value; + +int main(int, char**) +{ + { + using index_t = int; + std::array d{42}; + std::mdspan> m{ d.data(), 64, 128 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + { + using index_t = int; + std::array d{42}; + std::mdspan< int + , std::extents + , std::layout_right + , std::default_accessor + > m{ d.data(), 64, 128 }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = my_int; + + std::array d{42}; + mdspan_t m{ d.data(), other_index_t(64), other_index_t(128) }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + + static_assert( is_param_pack_cons_avail_v< mdspan_t, decltype(d.data()), other_index_t, other_index_t > == true, "" ); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_convertible; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, other_index_t, other_index_t > == false, "" ); + } + + // Constraint: (is_nothrow_constructible && ...) is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + using other_index_t = my_int_non_nothrow_constructible; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, other_index_t, other_index_t > == false, "" ); + } + + // Constraint: N == rank() || N == rank_dynamic() is true + { + using mdspan_t = std::mdspan< int, std::extents< int, dyn, dyn > >; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, int > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_stride >; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, int > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_right, Foo::my_accessor >; + + static_assert( is_param_pack_cons_avail_v< mdspan_t, int *, int > == false, "" ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp new file mode 100644 index 0000000000..cad112e4e2 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_left.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + std::array d{42}; + std::mdspan, std::layout_left> m{d.data(), 16, 32}; + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 16 ); + assert(m.extent(1) == 32 ); + assert(m.stride(0) == 1 ); + assert(m.stride(1) == 16 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp new file mode 100644 index 0000000000..41fce63541 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_right.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + typedef int data_t ; + typedef size_t index_t; + + std::array d{42}; + std::mdspan, std::layout_right> m{d.data(), 16, 32}; + + static_assert(m.is_exhaustive() == true, ""); + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 16 ); + assert(m.extent(1) == 32 ); + assert(m.stride(0) == 32 ); + assert(m.stride(1) == 1 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp new file mode 100644 index 0000000000..144a47e404 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/list_init_layout_stride.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + std::array d{42}; + + std::mdspan< int + , std::extents + , std::layout_stride + > + m { d.data() + , std::layout_stride::template mapping>{std::dextents{16, 32}, std::array{1, 128}} + }; + + assert(m.data_handle() == d.data()); + assert(m.rank() == 2 ); + assert(m.rank_dynamic() == 2 ); + assert(m.extent(0) == 16 ); + assert(m.extent(1) == 32 ); + assert(m.stride(0) == 1 ); + assert(m.stride(1) == 128 ); + assert(m.is_exhaustive() == false ); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp new file mode 100644 index 0000000000..eff2ae0e7c --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/mapping.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class T, class DataHandleType, class MappingType, class = void > +struct is_mapping_cons_avail : std::false_type {}; + +template< class T, class DataHandleType, class MappingType > +struct is_mapping_cons_avail< T + , DataHandleType + , MappingType + , std::enable_if_t< std::is_same< decltype( T{ std::declval() + , std::declval() + } + ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class DataHandleType, class MappingType > +constexpr bool is_mapping_cons_avail_v = is_mapping_cons_avail< T, DataHandleType, MappingType >::value; + +int main(int, char**) +{ + using data_t = int; + using index_t = size_t; + using ext_t = std::extents; + using mapping_t = std::layout_left::mapping; + + // mapping + { + using mdspan_t = std::mdspan; + + static_assert( is_mapping_cons_avail_v< mdspan_t, int *, mapping_t > == true, "" ); + + std::array d{42}; + mapping_t map{std::dextents{64, 128}}; + mdspan_t m{ d.data(), map }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = std::mdspan>; + + static_assert( is_mapping_cons_avail_v< mdspan_t, int *, mapping_t > == false, "" ); + } + + // mapping and accessor + { + + std::array d{42}; + mapping_t map{std::dextents{64, 128}}; + std::default_accessor a; + std::mdspan m{ d.data(), map, a }; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp new file mode 100644 index 0000000000..228cabf87a --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.cons/span_init_extents.pass.cpp @@ -0,0 +1,96 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../mdspan.mdspan.util/mdspan_util.hpp" +#include "../my_int.hpp" +#include "../my_accessor.hpp" + +constexpr auto dyn = std::dynamic_extent; + +template< class T, class DataHandleT, class SizeType, size_t N, class = void > +struct is_span_cons_avail : std::false_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +struct is_span_cons_avail< T + , DataHandleT + , SizeType + , N + , std::enable_if_t< std::is_same< decltype( T{ std::declval() + , std::declval>() + } + ) + , T + >::value + > + > : std::true_type {}; + +template< class T, class DataHandleT, class SizeType, size_t N > +constexpr bool is_span_cons_avail_v = is_span_cons_avail< T, DataHandleT, SizeType, N >::value; + + +int main(int, char**) +{ + // extents from std::span + { + using mdspan_t = std::mdspan>; + using other_index_t = int; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == true, "" ); + + std::array d{42}; + std::array sarr{64, 128}; + + mdspan_t m{d.data(), std::span{sarr}}; + + CHECK_MDSPAN_EXTENT(m,d,64,128); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = std::mdspan>; + using other_index_t = my_int_non_convertible; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: (is_convertible_v && ...) is true + { + using mdspan_t = std::mdspan>; + using other_index_t = my_int_non_convertible; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 2 > == false, "" ); + } + + // Constraint: N == rank() || N == rank_dynamic() is true + { + using mdspan_t = std::mdspan>; + using other_index_t = int; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, other_index_t, 1 > == false, "" ); + } + + // Constraint: is_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_stride >; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + // Constraint: is_default_constructible_v is true + { + using mdspan_t = std::mdspan< int, std::extents< int, 16 >, std::layout_right, Foo::my_accessor >; + + static_assert( is_span_cons_avail_v< mdspan_t, int *, int, 2 > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp new file mode 100644 index 0000000000..983dacc152 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/accessor.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + using data_t = int; + using index_t = size_t; + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + std::default_accessor const a; + std::mdspan, std::layout_left> m{ d.data(), map, a }; + + assert( m.accessor().access( d.data(), 0 ) == a.access( d.data(), 0 ) ); + assert( m.accessor().offset( d.data(), 0 ) == a.offset( d.data(), 0 ) ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp new file mode 100644 index 0000000000..6f7debd231 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/brackets_op.pass.cpp @@ -0,0 +1,161 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include +#include "../my_int.hpp" + +// Will be testing `m[0,0]` when it becomes available +// Alternatively, could use macro `__MDSPAN_OP(m,0,0)` which is turned to either `m[0,0]` or `m(0,0)`, +// depending on if `__cpp_multidimensional_subscript` is defined or not + +constexpr auto dyn = std::dynamic_extent; + +template< class, class T, class... OtherIndexTypes > +struct is_bracket_op_avail : std::false_type {}; + +template< class T, class... OtherIndexTypes > +struct is_bracket_op_avail< std::enable_if_t< std::is_same< decltype( std::declval()(std::declval()...) ) + , typename T::accessor_type::reference + >::value + > + , T + , OtherIndexTypes... + > : std::true_type {}; + +template< class T, class... OtherIndexTypes > +constexpr bool is_bracket_op_avail_v = is_bracket_op_avail< void, T, OtherIndexTypes... >::value; + +template< class T, class OtherIndexType, size_t N, class = void > +struct is_bracket_op_array_avail : std::false_type {}; + +template< class T, class OtherIndexType, size_t N > +struct is_bracket_op_array_avail< T + , OtherIndexType + , N + , std::enable_if_t< std::is_same< decltype( std::declval()(std::declval>()) ) + , typename T::accessor_type::reference + >::value + > + > : std::true_type {}; + +template< class T, class OtherIndexType, size_t N > +constexpr bool is_bracket_op_array_avail_v = is_bracket_op_array_avail< T, OtherIndexType, N >::value; + +template< class T, class OtherIndexType, size_t N, class = void > +struct is_bracket_op_span_avail : std::false_type {}; + +template< class T, class OtherIndexType, size_t N > +struct is_bracket_op_span_avail< T + , OtherIndexType + , N + , std::enable_if_t< std::is_same< decltype( std::declval()(std::declval>()) ) + , typename T::accessor_type::reference + >::value + > + > : std::true_type {}; + +template< class T, class OtherIndexType, size_t N > +constexpr bool is_bracket_op_span_avail_v = is_bracket_op_span_avail< T, OtherIndexType, N >::value; + + +int main(int, char**) +{ + { + using element_t = int; + using index_t = int; + using ext_t = std::extents; + using mdspan_t = std::mdspan; + + std::array d{42,43,44,45}; + mdspan_t m{d.data(), ext_t{2, 2}}; + + static_assert( is_bracket_op_avail_v< decltype(m), int, int > == true, "" ); + + // param pack + assert( m(0,0) == 42 ); + assert( m(0,1) == 43 ); + assert( m(1,0) == 44 ); + assert( m(1,1) == 45 ); + + // array of indices + assert( m(std::array{0,0}) == 42 ); + assert( m(std::array{0,1}) == 43 ); + assert( m(std::array{1,0}) == 44 ); + assert( m(std::array{1,1}) == 45 ); + + static_assert( is_bracket_op_array_avail_v< decltype(m), int, 2 > == true, "" ); + + // span of indices + assert( m(std::span{std::array{0,0}}) == 42 ); + assert( m(std::span{std::array{0,1}}) == 43 ); + assert( m(std::span{std::array{1,0}}) == 44 ); + assert( m(std::span{std::array{1,1}}) == 45 ); + + static_assert( is_bracket_op_span_avail_v< decltype(m), int, 2 > == true, "" ); + } + + // Param pack of indices in a type implicitly convertible to index_type + { + using element_t = int; + using index_t = int; + using ext_t = std::extents; + using mdspan_t = std::mdspan; + + std::array d{42,43,44,45}; + mdspan_t m{d.data(), ext_t{2, 2}}; + + assert( m(my_int(0),my_int(0)) == 42 ); + assert( m(my_int(0),my_int(1)) == 43 ); + assert( m(my_int(1),my_int(0)) == 44 ); + assert( m(my_int(1),my_int(1)) == 45 ); + } + + // Constraint: rank consistency + { + using element_t = int; + using index_t = int; + using mdspan_t = std::mdspan>; + + static_assert( is_bracket_op_avail_v< mdspan_t, index_t, index_t > == false, "" ); + + static_assert( is_bracket_op_array_avail_v< mdspan_t, index_t, 2 > == false, "" ); + + static_assert( is_bracket_op_span_avail_v < mdspan_t, index_t, 2 > == false, "" ); + } + + // Constraint: convertibility + { + using element_t = int; + using index_t = int; + using mdspan_t = std::mdspan>; + + static_assert( is_bracket_op_avail_v< mdspan_t, my_int_non_convertible > == false, "" ); + + static_assert( is_bracket_op_array_avail_v< mdspan_t, my_int_non_convertible, 1 > == false, "" ); + + static_assert( is_bracket_op_span_avail_v < mdspan_t, my_int_non_convertible, 1 > == false, "" ); + } + + // Constraint: nonthrow-constructibility + { + using element_t = int; + using index_t = int; + using mdspan_t = std::mdspan>; + + static_assert( is_bracket_op_avail_v< mdspan_t, my_int_non_nothrow_constructible > == false, "" ); + + static_assert( is_bracket_op_array_avail_v< mdspan_t, my_int_non_nothrow_constructible, 1 > == false, "" ); + + static_assert( is_bracket_op_span_avail_v < mdspan_t, my_int_non_nothrow_constructible, 1 > == false, "" ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp new file mode 100644 index 0000000000..cdce9fc189 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/data_handle.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + // C array + { + const int d[5] = {1,2,3,4,5}; +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + std::mdspan m(d); +#else + std::mdspan> m(d); +#endif + + assert( m.data_handle() == d ); + } + + // std array + { + std::array d = {1,2,3,4,5}; +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + std::mdspan m(d.data()); +#else + std::mdspan> m(d.data()); +#endif + + assert( m.data_handle() == d.data() ); + } + + // C pointer + { + std::array d = {1,2,3,4,5}; + int* ptr = d.data(); +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + std::mdspan m(ptr); +#else + std::mdspan> m(ptr); +#endif + + assert( m.data_handle() == ptr ); + } + + // Copy constructor + { + std::array d = {1,2,3,4,5}; +#if defined (__cpp_deduction_guides) && defined(__MDSPAN_USE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION) + std::mdspan m0(d.data()); + std::mdspan m (m0); +#else + std::mdspan> m0(d.data()); + std::mdspan> m (m0); +#endif + + assert( m.data_handle() == m0.data_handle() ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp new file mode 100644 index 0000000000..a689a53cfe --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/empty.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + std::array storage{1}; + + { + std::mdspan> m; + + assert( m.empty() == true ); + } + + { + std::mdspan> m{ storage.data(), 0 }; + + assert( m.empty() == true ); + } + + { + std::mdspan> m{ storage.data(), 2 }; + + assert( m.empty() == false ); + } + + { + std::mdspan> m{ storage.data(), 2, 0 }; + + assert( m.empty() == true ); + } + + { + std::mdspan> m{ storage.data(), 2, 2 }; + + assert( m.empty() == false ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp new file mode 100644 index 0000000000..d5bb06e207 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extent.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + typedef int data_t ; + typedef size_t index_t; + + std::array d{42}; + + { + std::mdspan> m; + + assert( m.extent(0) == 0 ); + assert( m.extent(1) == 0 ); + } + + { + std::mdspan> m{d.data()}; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + { + std::mdspan> m{d.data(), 16, 32}; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + { + std::array d{42}; + std::mdspan, std::layout_left> m{d.data(), 16, 32}; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + { + using dexts = std::dextents; + + std::mdspan< int, std::extents, std::layout_stride > + m { d.data() + , std::layout_stride::template mapping{dexts{16, 32}, std::array{1, 128}} + }; + + assert( m.extent(0) == 16 ); + assert( m.extent(1) == 32 ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp new file mode 100644 index 0000000000..0e84e1d3b3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/extents.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::array d{42}; + std::extents e{64, 128}; + std::mdspan> m{ d.data(), e }; + + assert( &m.extents() == &m.mapping().extents() ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp new file mode 100644 index 0000000000..d85a8f449c --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_exhaustive.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::mdspan> m; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + std::array d{42}; + std::extents e{64, 128}; + + { + std::mdspan, std::layout_left> m{ d.data(), e }; + + static_assert( m.is_always_exhaustive() == true, "" ); + assert ( m.is_exhaustive () == true ); + } + + { + using dexts = std::dextents; + + std::mdspan< int, std::extents, std::layout_stride > + m { d.data() + , std::layout_stride::template mapping{dexts{16, 32}, std::array{1, 128}} + }; + + static_assert( m.is_always_exhaustive() == false, "" ); + assert ( m.is_exhaustive () == false ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp new file mode 100644 index 0000000000..29478a8d31 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_strided.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::mdspan> m; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + std::array d{42}; + std::extents e{64, 128}; + + { + std::mdspan, std::layout_left> m{ d.data(), e }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + { + using dexts = std::dextents; + + std::mdspan< int, std::extents, std::layout_stride > + m { d.data() + , std::layout_stride::template mapping{dexts{16, 32}, std::array{1, 128}} + }; + + static_assert( m.is_always_strided() == true, "" ); + assert ( m.is_strided () == true ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp new file mode 100644 index 0000000000..a3918e420b --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/is_unique.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + { + std::mdspan> m; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + std::array d{42}; + std::extents e{64, 128}; + + { + std::mdspan> m{ d.data(), e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + { + std::mdspan, std::layout_left> m{ d.data(), e }; + + static_assert( m.is_always_unique() == true, "" ); + assert ( m.is_unique () == true ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp new file mode 100644 index 0000000000..1861fb42dc --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/mapping.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + // mapping + { + using data_t = int; + using index_t = size_t; + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + std::mdspan, std::layout_left> m{ d.data(), map }; + + assert( m.mapping() == map ); + } + + // mapping and accessor + { + using data_t = int; + using index_t = size_t; + std::array d{42}; + std::layout_left::mapping> map{std::dextents{64, 128}}; + std::default_accessor a; + std::mdspan, std::layout_left> m{ d.data(), map, a }; + + assert( m.mapping() == map ); + } + + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp new file mode 100644 index 0000000000..4dd3337814 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/rank.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + typedef int data_t ; + typedef size_t index_t; + + std::array d{42}; + + { + std::mdspan> m; + + static_assert( m.rank () == 1, "" ); + assert ( m.rank_dynamic() == 1 ); + } + + { + std::mdspan> m{d.data()}; + + static_assert( m.rank () == 1, "" ); + assert ( m.rank_dynamic() == 0 ); + } + + { + std::mdspan> m{d.data(), 16, 32}; + + static_assert( m.rank () == 2, "" ); + assert ( m.rank_dynamic() == 2 ); + } + + { + std::mdspan> m{d.data(), 16, 32}; + + static_assert( m.rank () == 3, "" ); + assert ( m.rank_dynamic() == 2 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp new file mode 100644 index 0000000000..300b77ee97 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/size.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +template +void test_mdspan_size(std::array& storage, Extents&& e) +{ + using extents_type = std::remove_cv_t>; + std::mdspan m(storage.data(), std::forward(e)); + + static_assert(std::is_same::value, + "The return type of mdspan::size() must be size_t."); + + // m.size() must not overflow, as long as the product of extents + // is representable as a value of type size_t. + assert( m.size() == N ); +} + + +int main(int, char**) +{ + // TEST(TestMdspan, MdspanSizeReturnTypeAndPrecondition) + { + std::array storage; + + static_assert(std::numeric_limits::max() == 127, "max int8_t != 127"); + test_mdspan_size(storage, std::extents{}); // 12 * 11 == 132 + } + + { + std::array storage; + + static_assert(std::numeric_limits::max() == 255, "max uint8_t != 255"); + test_mdspan_size(storage, std::extents{}); // 16 * 17 == 272 + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp new file mode 100644 index 0000000000..6017cfa7b6 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/stride.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +int main(int, char**) +{ + typedef int data_t ; + typedef size_t index_t; + + std::array d{42}; + + { + std::mdspan> m; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 1 ); + } + + { + std::mdspan> m{d.data(), 16, 32}; + + assert( m.stride(0) == 32 ); + assert( m.stride(1) == 1 ); + } + + { + std::array d{42}; + std::mdspan, std::layout_left> m{d.data(), 16, 32}; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 16 ); + } + + { + using dexts = std::dextents; + + std::mdspan< int, std::extents, std::layout_stride > + m { d.data() + , std::layout_stride::template mapping{dexts{16, 32}, std::array{1, 128}} + }; + + assert( m.stride(0) == 1 ); + assert( m.stride(1) == 128 ); + } + + return 0; +} + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp new file mode 100644 index 0000000000..dcf5ef1d28 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.members/swap.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +void test_std_swap_static_extents() +{ + int data1[12] = {1,2,3,4,5,6,7,8,9,10,11,12}; + int data2[12] = {21,22,23,24,25,26,27,28,29,30,31,32}; + + std::mdspan> m1(data1); + std::mdspan> m2(data2); + std::extents exts1; + std::layout_right::mapping> map1(exts1); + std::extents exts2; + std::layout_right::mapping> map2(exts2); + + assert(m1.data_handle() == data1); + assert(m1.mapping() == map1); + auto val1 = m1(0,0); + assert(val1 == 1); + assert(m2.data_handle() == data2); + assert(m2.mapping() == map2); + auto val2 = m2(0,0); + assert(val2 == 21); + + std::swap(m1,m2); + assert(m1.data_handle() == data2); + assert(m1.mapping() == map2); + val1 = m1(0,0); + assert(val1 == 21); + assert(m2.data_handle() == data1); + assert(m2.mapping() == map1); + val2 = m2(0,0); + assert(val2 == 1); +} + +void test_std_swap_dynamic_extents() +{ + int data1[12] = {1,2,3,4,5,6,7,8,9,10,11,12}; + int data2[12] = {21,22,23,24,25,26,27,28,29,30,31,32}; + + std::mdspan> m1(data1,3,4); + std::mdspan> m2(data2,4,3); + std::dextents exts1(3,4); + std::layout_right::mapping> map1(exts1); + std::dextents exts2(4,3); + std::layout_right::mapping> map2(exts2); + + assert(m1.data_handle() == data1); + assert(m1.mapping() == map1); + auto val1 = m1(0,0); + assert(val1 == 1); + assert(m2.data_handle() == data2); + assert(m2.mapping() == map2); + auto val2 = m2(0,0); + assert(val2 == 21); + + std::swap(m1,m2); + assert(m1.data_handle() == data2); + assert(m1.mapping() == map2); + val1 = m1(0,0); + assert(val1 == 21); + assert(m2.data_handle() == data1); + assert(m2.mapping() == map1); + val2 = m2(0,0); + assert(val2 == 1); +} + +int main(int, char**) +{ + test_std_swap_static_extents(); + + test_std_swap_dynamic_extents(); + + //TODO port tests for customized layout and accessor + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp new file mode 100644 index 0000000000..96dc6bab24 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.mdspan.util/mdspan_util.hpp @@ -0,0 +1,15 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#define CHECK_MDSPAN_EXTENT(m,d,e0,e1) \ + static_assert(m.is_exhaustive(), ""); \ + assert(m.data_handle() == d.data()); \ + assert(m.rank() == 2 ); \ + assert(m.rank_dynamic() == 2 ); \ + assert(m.extent(0) == e0 ); \ + assert(m.extent(1) == e1 ) diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp new file mode 100644 index 0000000000..39fb787c4b --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/dim_reduction.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + // TEST(TestSubmdspanLayoutRightStaticSizedRankReducing3Dto1D, test_submdspan_layout_right_static_sized_rank_reducing_3d_to_1d) + { + std::array d; + std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = std::submdspan(m, 1, 1, std::full_extent); + + static_assert(decltype(sub0)::rank()==1,"unexpected submdspan rank"); + static_assert(sub0.rank() == 1, ""); + static_assert(sub0.rank_dynamic() == 0, ""); + assert(sub0.extent(0) == 4); + assert(sub0(1) == 42); + } + + // TEST(TestSubmdspanLayoutLeftStaticSizedRankReducing3Dto1D, test_submdspan_layout_left_static_sized_rank_reducing_3d_to_1d) + { + std::array d; + std::mdspan, std::layout_left> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = std::submdspan(m, 1, 1, std::full_extent); + + static_assert(sub0.rank() == 1, ""); + static_assert(sub0.rank_dynamic() == 0, ""); + assert(sub0.extent(0) == 4); + assert(sub0(1) == 42); + } + + // TEST(TestSubmdspanLayoutRightStaticSizedRankReducingNested3Dto0D, test_submdspan_layout_right_static_sized_rank_reducing_nested_3d_to_0d) + { + std::array d; + std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = std::submdspan(m, 1, std::full_extent, std::full_extent); + + static_assert(sub0.rank() == 2, ""); + static_assert(sub0.rank_dynamic() == 0, ""); + assert(sub0.extent(0) == 3); + assert(sub0.extent(1) == 4); + assert(sub0(1, 1) == 42); + + auto sub1 = std::submdspan(sub0, 1, std::full_extent); + static_assert(sub1.rank() == 1, ""); + static_assert(sub1.rank_dynamic() == 0, ""); + assert(sub1.extent(0) == 4); + assert(sub1(1) == 42); + + auto sub2 = std::submdspan(sub1, 1); + static_assert(sub2.rank() == 0, ""); + static_assert(sub2.rank_dynamic() == 0, ""); + assert(sub2() == 42); + } + + return 0; +} + + + + diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp new file mode 100644 index 0000000000..08f5b3f155 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/pair_init.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + // TEST(TestSubmdspanLayoutRightStaticSizedPairs, test_submdspan_layout_right_static_sized_pairs) + { + std::array d; + std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = std::submdspan(m, std::pair{1, 2}, std::pair{1, 3}, std::pair{1, 4}); + + static_assert( sub0.rank() == 3, "" ); + static_assert( sub0.rank_dynamic() == 3, "" ); + assert( sub0.extent(0) == 1 ); + assert( sub0.extent(1) == 2 ); + assert( sub0.extent(2) == 3 ); + assert( sub0(0, 0, 0) == 42 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp new file mode 100644 index 0000000000..fcf91cb6c3 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/return_type.pass.cpp @@ -0,0 +1,140 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +constexpr auto dyn = std::dynamic_extent; + +//template + +using submdspan_test_types = std::tuple< + // LayoutLeft to LayoutLeft + std::tuple,std::dextents, std::full_extent_t> + , std::tuple,std::dextents, std::pair> + , std::tuple,std::dextents, int> + , std::tuple,std::dextents, std::full_extent_t, std::full_extent_t> + , std::tuple,std::dextents, std::full_extent_t, std::pair> + , std::tuple,std::dextents, std::full_extent_t, int> + , std::tuple,std::dextents, std::full_extent_t, std::full_extent_t, std::pair> + , std::tuple,std::dextents, std::full_extent_t, std::pair, int> + , std::tuple,std::dextents, std::full_extent_t, int, int> + , std::tuple,std::dextents, std::pair, int, int> + , std::tuple,std::dextents, std::full_extent_t, std::full_extent_t, std::pair, int, int, int> + , std::tuple,std::dextents, std::full_extent_t, std::pair, int, int, int, int> + , std::tuple,std::dextents, std::full_extent_t, int, int, int ,int, int> + , std::tuple,std::dextents, std::pair, int, int, int, int, int> + // LayoutRight to LayoutRight + , std::tuple,std::dextents, std::full_extent_t> + , std::tuple,std::dextents, std::pair> + , std::tuple,std::dextents, int> + , std::tuple,std::dextents, std::full_extent_t, std::full_extent_t> + , std::tuple,std::dextents, std::pair, std::full_extent_t> + , std::tuple,std::dextents, int, std::full_extent_t> + , std::tuple,std::dextents, std::pair, std::full_extent_t, std::full_extent_t> + , std::tuple,std::dextents, int, std::pair, std::full_extent_t> + , std::tuple,std::dextents, int, int, std::full_extent_t> + , std::tuple,std::dextents, int, int, int, std::pair, std::full_extent_t, std::full_extent_t> + , std::tuple,std::dextents, int, int, int, int, std::pair, std::full_extent_t> + , std::tuple,std::dextents, int, int, int, int, int, std::full_extent_t> + // LayoutRight to LayoutRight Check Extents Preservation + , std::tuple,std::extents, std::full_extent_t> + , std::tuple,std::extents, std::pair> + , std::tuple,std::extents, int> + , std::tuple,std::extents, std::full_extent_t, std::full_extent_t> + , std::tuple,std::extents, std::pair, std::full_extent_t> + , std::tuple,std::extents, int, std::full_extent_t> + , std::tuple,std::extents, std::pair, std::full_extent_t, std::full_extent_t> + , std::tuple,std::extents, int, std::pair, std::full_extent_t> + , std::tuple,std::extents, int, int, std::full_extent_t> + , std::tuple,std::extents, int, int, int, std::pair, std::full_extent_t, std::full_extent_t> + , std::tuple,std::extents, int, int, int, int, std::pair, std::full_extent_t> + , std::tuple,std::extents, int, int, int, int, int, std::full_extent_t> + + , std::tuple,std::extents, std::full_extent_t, int, std::pair, int, int, std::full_extent_t> + , std::tuple,std::extents, int, std::full_extent_t, std::pair, int, std::full_extent_t, int> + >; + +template struct TestSubMDSpan; + +template +struct TestSubMDSpan< + std::tuple> +{ + using mds_org_t = std::mdspan; + using mds_sub_t = std::mdspan; + using map_t = typename mds_org_t::mapping_type; + + using mds_sub_deduced_t = decltype(std::submdspan(mds_org_t(nullptr, map_t()), SubArgs()...)); + using sub_args_t = std::tuple; +}; + +// TYPED_TEST(TestSubMDSpan, submdspan_return_type) +template +void test_submdspan() +{ + using TestFixture = TestSubMDSpan; + + static_assert(std::is_same::value, + "SubMDSpan: wrong return type"); +} + +int main(int, char**) +{ + static_assert( std::tuple_size< submdspan_test_types >{} == 40, "" ); + + test_submdspan< std::tuple_element_t< 0, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 1, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 2, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 3, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 4, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 5, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 6, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 7, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 8, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 9, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 10, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 11, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 12, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 13, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 14, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 15, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 16, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 17, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 18, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 19, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 20, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 21, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 22, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 23, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 24, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 25, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 26, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 27, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 28, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 29, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 30, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 31, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 32, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 33, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 34, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 35, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 36, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 37, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 38, submdspan_test_types > >(); + test_submdspan< std::tuple_element_t< 39, submdspan_test_types > >(); + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp new file mode 100644 index 0000000000..73fa839394 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/mdspan.submdspan.submdspan/tuple_init.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +//UNSUPPORTED: c++11 + +#include +#include + +int main(int, char**) +{ + // TEST(TestSubmdspanLayoutRightStaticSizedTuples, test_submdspan_layout_right_static_sized_tuples) + { + std::array d; + std::mdspan> m(d.data()); + m(1, 1, 1) = 42; + auto sub0 = std::submdspan(m, std::tuple{1, 2}, std::tuple{1, 3}, std::tuple{1, 4}); + + static_assert( sub0.rank() == 3, "" ); + static_assert( sub0.rank_dynamic() == 3, "" ); + assert( sub0.extent(0) == 1 ); + assert( sub0.extent(1) == 2 ); + assert( sub0.extent(2) == 3 ); + assert( sub0(0, 0, 0) == 42 ); + } + + return 0; +} diff --git a/libcxx/test/std/containers/views/mdspan/my_accessor.hpp b/libcxx/test/std/containers/views/mdspan/my_accessor.hpp new file mode 100644 index 0000000000..09e9fe4703 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/my_accessor.hpp @@ -0,0 +1,37 @@ +#ifndef _MY_ACCESSOR_HPP +#define _MY_ACCESSOR_HPP + +#include "foo_customizations.hpp" + +namespace Foo +{ + // Same as Foo::foo_accessor but + // 1. Doesn't have a default constructor + // 2. Isn't contructible from the default accessor + template + struct my_accessor { + using offset_policy = my_accessor; + using element_type = T; + using reference = T&; + using data_handle_type = foo_ptr; + + __MDSPAN_INLINE_FUNCTION + constexpr my_accessor(int* ptr) noexcept { flag = ptr; } + + template + __MDSPAN_INLINE_FUNCTION + constexpr my_accessor(my_accessor other) noexcept { flag = other.flag; } + + + constexpr reference access(data_handle_type p, size_t i) const noexcept { + return p.data[i]; + } + + constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept { + return data_handle_type(p.data+i); + } + int* flag; + }; +} + +#endif diff --git a/libcxx/test/std/containers/views/mdspan/my_int.hpp b/libcxx/test/std/containers/views/mdspan/my_int.hpp new file mode 100644 index 0000000000..e2d04966f4 --- /dev/null +++ b/libcxx/test/std/containers/views/mdspan/my_int.hpp @@ -0,0 +1,45 @@ +#ifndef _MY_INT_HPP +#define _MY_INT_HPP + +struct my_int_non_convertible; + +struct my_int +{ + int _val; + + my_int( my_int_non_convertible ) noexcept; + constexpr my_int( int val ) : _val( val ){}; + constexpr operator int() const noexcept { return _val; } +}; + +template <> struct std::is_integral : std::true_type {}; + +// Wrapper type that's not implicitly convertible + +struct my_int_non_convertible +{ + my_int _val; + + my_int_non_convertible(); + my_int_non_convertible( my_int val ) : _val( val ){}; + operator my_int() const noexcept { return _val; } +}; + +my_int::my_int( my_int_non_convertible ) noexcept {} + +template <> struct std::is_integral : std::true_type {}; + +// Wrapper type that's not nothrow-constructible + +struct my_int_non_nothrow_constructible +{ + int _val; + + my_int_non_nothrow_constructible(); + my_int_non_nothrow_constructible( int val ) : _val( val ){}; + operator int() const { return _val; } +}; + +template <> struct std::is_integral : std::true_type {}; + +#endif