EXPECT_EQ(*x, testNumber_);
}
-} // namespace
+TEST(MultiDimArrayToMdSpanTest, convertsToMdSpan)
+{
+ MultiDimArray < std::array<int, 4>, extents < 2, 2>> arr = {{0, 1, 2, 3}};
+ basic_mdspan < int, extents < 2, 2>> span(arr);
+
+ // test copy correctness
+ EXPECT_EQ(span(1, 1), 3);
+
+ // test that span operates on same data as array
+ span(0, 1) = -5;
+ EXPECT_EQ(arr(0, 1), -5);
+}
+
+TEST(MultiDimArrayToMdSpanTest, constArrayToMdSpan)
+{
+ const MultiDimArray < std::array<int, 4>, extents < 2, 2>> constArr = {{0, 1, 2, 3}};
+ basic_mdspan < const int, extents < 2, 2>> span(constArr);
+ EXPECT_EQ(span(0, 1), 1);
+}
+TEST(MultiDimArrayToMdSpanTest, nonConstArrayToConstMdSpan)
+{
+ MultiDimArray < std::array<int, 4>, extents < 2, 2>> arr = {{0, 1, 2, 3}};
+ basic_mdspan < const int, extents < 2, 2>> span(arr);
+ EXPECT_EQ(span(0, 1), 1);
+}
+
+TEST(MultiDimArrayToMdSpanTest, implicitConversionToMdSpan)
+{
+ auto testFunc = [](basic_mdspan < const int, extents < 2, 2>> a){
+ return a(0, 0);
+ };
+ MultiDimArray < std::array<int, 4>, extents < 2, 2>> arr = {{0, 1, 2, 3}};
+ EXPECT_EQ(testFunc(arr), 0);
+}
+
+} // namespace
} // namespace test
} // namespace gmx
*/
constexpr basic_mdspan( pointer ptr, const mapping_type &m, const accessor_type &a ) noexcept
: acc_(a), map_( m ), ptr_(ptr) {}
-
- /*! \brief Brace operator to access multidimenisonal array element.
+ /*! \brief Construct mdspan from multidimensional arrays implemented with mdspan
+ *
+ * Requires the container to have a view_type describing the mdspan, which is
+ * accessible through an asView() call
+ *
+ * This allows functions to declare mdspans as arguments, but take e.g. multidimensional
+ * arrays implicitly during the function call
+ * \tparam U container type
+ * \param[in] other mdspan-implementing container
+ */
+ template<typename U,
+ typename = typename std::enable_if<
+ std::is_same<typename std::remove_reference<U>::type::view_type::element_type,
+ ElementType>::value>::type>
+ constexpr basic_mdspan(U &&other) : basic_mdspan(other.asView()) {}
+ /*! \brief Construct mdspan of const Elements from multidimensional arrays implemented with mdspan
+ *
+ * Requires the container to have a const_view_type describing the mdspan, which is
+ * accessible through an asConstView() call
+ *
+ * This allows functions to declare mdspans as arguments, but take e.g. multidimensional
+ * arrays implicitly during the function call
+ * \tparam U container type
+ * \param[in] other mdspan-implementing container
+ */
+ template<typename U,
+ typename = typename std::enable_if<
+ std::is_same<typename std::remove_reference<U>::type::const_view_type::element_type,
+ ElementType>::value>::type>
+ constexpr basic_mdspan(const U &other) : basic_mdspan(other.asConstView()) {}
+ /*! \brief Brace operator to access multidimensional array element.
* \param[in] indices The multidimensional indices of the object.
* Requires rank() == sizeof...(IndexType). Slicing is implemented via sub_span.
* \returns reference to element at indices.