Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

mdspan operator [] doesn't compile in visual studio

https://godbolt.org/z/f4dc83fr3

std::vector v{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
auto ms2 = std::mdspan(v.data(), 2, 6);
ms2[0, 0] = 3;

error C2676: binary ‘[‘: ‘std::mdspan<_Ty,std::extents<_IndexType,18446744073709551615,18446744073709551615>,std::layout_right,std::default_accessor<_Ty>>’ does not define this operator or a conversion to a type acceptable to the predefined operator

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

MSVC doesn’t yet support the multidimensional subscript operator. See https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-170:

C++23 Core language features Supported
P2128R6 Multidimensional subscript operator no

Workaround: use ms2[std::array{0, 0}] instead of ms2[0, 0].

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading