std-span Questions

4

Solved

I wanted to do this #include <vector> #include <span> struct S { std::vector<int> v; void set(std::span<int> _v) { v = _v; } }; But it does not compile. What are the ...
Ehrman asked 1/9, 2020 at 10:46

3

Solved

std::vector and pretty much all other containers have a very convenient way of bounds checking: at(). std::span doesn't have that apparently. Why? Is there a replacement? Other than rolling out yo...
Shizue asked 2/8, 2020 at 12:6

1

Solved

Title. I am implementing this class: #include <span> #include <vector> class MyClass { public: std::span<int *> numbers(void) { return m_numbers; } std::span<const int *&...
Gans asked 16/10, 2023 at 13:44

3

Solved

In the following C++20 code, passing a std::vector to a templated function with a std::span<T> parameter fails, because obviously the compiler cannot deduce the template parameter. I have tri...
Strychninism asked 1/9, 2023 at 7:48

4

Solved

Recently I've gotten suggestions to use span<T>'s in my code, or have seen some answers here on the site which use span's - supposedly some kind of container. But - I can't find anything like...
Cassondracassoulet asked 16/8, 2017 at 22:15

3

Solved

I am trying to create a std::array<uint8_t,N> from a std::span<uint8_t,N> but I cannot find a way to do so without memcpy, std::copy, or std::ranges::copy which don't protect me against...
Sherrer asked 28/7, 2023 at 18:9

1

Solved

Generally speaking C++ doesn't allow comparing iterators between different containers. For example: int main() { std::vector<int> v = {1, 2, 3}; std::vector<int> w = {4, 5, 6}; std::...
Hierophant asked 26/7, 2023 at 16:32

1

Solved

Over the past year or so I've noticed a few C++-related answers on StackOverflow refer to mdspan's - but I've never actually seen these in C++ code. I tried looking for them in my C++ compiler's st...
Merthiolate asked 18/3, 2023 at 20:44

3

Solved

I know this might overlap with the question What is a “span” and when should I use one?, but I think the answer to this specific part of the question is pretty confusing. On one hand, there are quo...
Vic asked 15/12, 2020 at 19:49

1

Solved

I am using a C library which uses various fixed-sized unsigned char arrays with no null terminator as strings. I've been converting them to std::string using the following function: auto uchar_to_s...
Carcinomatosis asked 22/1, 2022 at 22:24

1

Solved

Put it other way, conversely, are std::span iterators invalidated after the span instance is destroyed? I have a vector I need to iterate over with different layouts. I'm trying to make use of std:...
Molotov asked 11/8, 2021 at 19:38

1

My best guesses are that committee either forgot about this use case or did not want to use concepts/requires to restrict the span type to something that can be safely hashed(POD, no padding), or t...
Comedic asked 21/7, 2021 at 16:36

2

Solved

This example program does not compile, because the transform_view cannot be converted to a std::span: class Foo { private: std::vector<std::string> strings = { "a", "b", ...
Zincate asked 12/5, 2021 at 19:24

3

Solved

C++20 std::span is a very nice interface to program against. But there doesn't seem to be an easy way to have a span of spans. Here's what I am trying to do: #include <iostream> #include <...
Shopper asked 8/5, 2021 at 16:28

1

Solved

Consider a large memory container. In this simple example an std::vector<int>: std::vector v = { 0, 1, 2, 3, 4, 5 }; std::span allows me create a lightweight view over the memory. Now I want...
Enfilade asked 3/10, 2020 at 17:15

1

Solved

Given some function void func(std::span<std::string_view>), how does one feed this function a raw array of C-strings const char** in the most efficient manner? As far as I understood this sho...
Powdery asked 23/9, 2020 at 21:57

2

I have a const z* zs = nullptr; I want to convert zs to std::span When I try to do std::span<const z>(zs) I get an error saying error: no matching function for call to ‘std::span::span(const...
Dysgenic asked 17/9, 2020 at 8:4

1

Solved

Why does std::span only have begin and end methods and not their constant iterator counterparts cbegin and cend? (standard) What I noticed too is that the proposals for span that I could find do ha...
Upmost asked 6/7, 2020 at 14:0

1

Wasn't the std::span designed as a lightweight reference to sub-regions of std::vector/std::array/plain array and alike? Shouldn't it also contain comparison operators in its API, to be consistent ...
Tabethatabib asked 11/3, 2020 at 10:16

2

Solved

I've been updating old code that used my homebrew span class to the one that is more in line with C++20 std::span and I'm getting compile errors because std::span doesn't have size_type and instead...
Gentes asked 17/3, 2019 at 16:27

1

Solved

What's the most efficient way of iterating over one of several known ranges based on some condition? pseudo-code for a binary condition: for element in (condition ? range_a : range_b) // do wo...
Ideation asked 27/8, 2019 at 8:22

1

Solved

I have been playing around with the latest specification for std::span using the clang trunk and libc++ on Godbolt and find some of the constructors confusing. In particular I find the constructor...
Torray asked 10/8, 2019 at 17:17

2

Solved

The standard containers propagate const. That is, their elements are automatically const if the containers themselves are const. For example: const std::vector vec{3, 1, 4, 1, 5, 9, 2, 6}; ranges:...
Syndesmosis asked 4/7, 2019 at 10:56

1

Solved

std::span has been voted into C++20. I assumed that along with std::span, there would be a convenience alias defined like this: template <class T, size_t Extent = dynamic_extent> using cspan...
Distant asked 2/7, 2019 at 5:21

1

It appears that std::span in C++20 is defined similarly to template<class T> class span { T* begin; size_t count; }; And not template<class Iter> class span { Iter begin; Ite...
Simultaneous asked 28/6, 2019 at 18:3

© 2022 - 2025 — McMap. All rights reserved.