Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
utterances-bot opened this issue Oct 16, 2023 · 5 comments
Open

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

utterances-bot opened this issue Oct 16, 2023 · 5 comments

Comments

@utterances-bot
Copy link

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/

Copy link

Ukilele commented Oct 16, 2023

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;

Copy link

The <spanstream> routines are useful, also.

Copy link

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
Copy link
Owner

fenbf commented Nov 6, 2023

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
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants