fenbf / cppstories-discussions

4 stars 1 forks source link

2023/four-views-in-cpp23/ #130

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Spans, string_view, and Ranges - Four View types (C++17 to C++23) - C++ Stories

In this blog post, we’ll look at several different view/reference types introduced in Modern C++. The first one is string_view added in C++17. C++20 brought std::span and ranges views. The last addition is std::mdspan from C++23. Let’s start. String View (C++17)   The std::string_view type is a non-owning reference to a string.

https://www.cppstories.com/2023/four-views-in-cpp23/

Ukilele commented 1 year ago

I know that it's not the main purpose of this article, but in the function isIdentity you are only checking if the numbers on the main diagonal are 1, but you are not checking that all the other numbers are 0. A correct check would probably look like this:

for (int i = 0; i < rows; ++i)
    for (int j = 0; j < cols; ++j)
        if (matrix[i, j] != (i == j ? 1 : 0))
            return false;
rmerriam commented 1 year ago

The <spanstream> routines are useful, also.

griswaldbrooks commented 1 year ago

mdspan doesn't actually have any constraint on contiguous memory if you customize your accessor policy. I recently gave a lightning talk at CppCon 2023 about this https://github.com/griswaldbrooks/spanny

@dhollman who authored mdspan told me one of their original use cases was actually to access data from the gpu accelerator.

fenbf commented 1 year ago

Thanks @Ukilele ! I've just updated the code and now the example is better... and compiling :) Thanks @griswaldbrooks for the note, I also included this in the text (quoted) Thanks @rmerriam - I didn't know about that header, need to check it out!

griswaldbrooks commented 1 year ago

thanks!