C++23 introduced std::mdspan , a non-owning multidimensional view over existing data. Unlike std::span , it supports multiple dimensions and configurable memory layouts, including row-major and column-major layouts. std::mdspan is part of the published C++23 standard. Consider the following code: #include <cstddef> #include <mdspan> #include <vector> int main() { std::vector<int> data{0, 1, 2, 3, 4, 5}; using Shape = std::extents<std::size_t, 2, 3>; std::mdspan<int, Shape, std::layout_right> rowMajor(data.data()); std::mdspan<int, Shape, std::layout_left> columnMajor(data.data()); // Case A int a = rowMajor[1, 0]; // Case B int b = columnMajor[1, 0]; // Force vector reallocation data.reserve(data.capacity() + 1); // Case C int c = rowMajor[0, 0]; } Question How do the layout policies and ownership semantics of std::mdspan determine the behaviour...
Below are answers to questions in D2: Core Language — if constexpr, std::is_constant_evaluated(), and if consteval . Q1: Assuming the user enters 10, what values will this program print, and why? The program will print 20 in both cases. Despite the temptation to assume that if constexpr will allow to distinguish compile time and runtime execution, that is not really the case. Function constexpr int Calculate(int value) can be called at either compile time or runtime, however condition if constexpr is always evaluated during compile time. constexpr int compileTime = Calculate(10); must be evaluated as a constant expression during compile time because variable compileTime declared as constexpr . All necessary information is available. On the other hand int runtime = Calculate(input); can't be evaluated during compile time, since input is not known then. However, even for a runtime call, the condition if constexpr (std::is_cons...