FEniCS/basix

`mdspan` parentheses vs bracket operator

Opened this issue · 0 comments

Currently the Kokkos mdspan implementation is used in its parentheses mode.

After #838 is merged we should, at least in principle, be able to switch to the usage of bracket operators. However, this caused some compile time problems, that were not yet fixed.

For example, the following code does not compile (with gcc version 11.4).

#include "mdspan.hpp"

template <typename T, std::size_t D>
using mdspan_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<T, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, D>>;

template<class...IndexType>
void pass(IndexType... indices)
{
    static_assert(sizeof...(IndexType) == 2);
}

void test()
{
    mdspan_t<double, 2> span;
    static_assert(span.rank() == 2);

    std::array<std::size_t, 2> indices = {0, 0};
    static_assert(indices.size() == 2);
    span[indices];

    pass(0, 0);

    static_assert(std::is_convertible_v<decltype((0,0)), mdspan_t<double, 2>::index_type>);
    static_assert(std::is_nothrow_constructible_v<mdspan_t<double, 2>::index_type, decltype((0,0))>);

    span[0, 0]; // but this fails with (rank() == sizeof...(SizeTypes)) evaluating to False
}

To circumvent this and allow the increase of the C++ standard in use, we explicitly enforce the use of parentheses by setting the flag MDSPAN_USE_PAREN_OPERATOR. This needs to be reverted in after fixing the bracket operator problems.

Note: the necessary syntactical changes from (...) to [...] may be found at schnellerhase#2.