mdspan 运算符 [] 无法在 Visual Studio 中编译

问题描述 投票:0回答:1

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;

错误 C2676:二进制 '[': 'std::mdspan<_Ty,std::extents<_IndexType,18446744073709551615,18446744073709551615>,std::layout_right,std::default_accessor<_Ty>>' 未定义此运算符或转换为预定义运算符可接受的类型

c++ visual-c++ c++23
1个回答
1
投票

MSVC 尚不支持多维下标运算符。请参阅https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-170

C++23 核心语言功能 支持
P2128R6 多维下标运算符

解决方法:使用

ms2[std::array{0, 0}]
代替
ms2[0, 0]

© www.soinside.com 2019 - 2024. All rights reserved.