Visual C++ mdspan

418 Views Asked by At

I have been waiting breathlessly for Microsoft to release their implementation of C++23 std::mdspan. It came out today in V19 Preview 1. I'm attempting to try it, but it doesn't seem to work. Here's my code:

    std::vector<double> Bdat(dfcts.ndf * vbs.nvb);     // allocate the space
    using Dext = std::dextents<size_t, 2>;
    std::mdspan<double, Dext> B{ Bdat.data(), dfcts.ndf, vbs.nvb};    // create the mdspan
    B[0, 0] = 1.0;

The last line gives an error: "no operator "[]" matches these operands. Please tell me I'm making an obvious syntatical error. I really don't want to hear that I can create an mdspan but not use it.

1

There are 1 best solutions below

5
On BEST ANSWER

MSVC does not currently support the multidimensional operator[] language feature, you may need to use another overload that accepts an array or span before this happens

B[std::array{0, 0}] = 1.0;