Questions tagged [std-span]

A non-owning lightweight wrapper object referring to a contiguous sequence of elements in memory

60 questions
1
vote
1 answer

What's the best way to pass a r-value/temporary collection to a function taking a std::span?

I've been trying to start using std::span in places where I would have previously used const std::vector&. The only sticking point I have is illustrated in the following: #include #include #include #include…
jwezorek
  • 8,592
  • 1
  • 29
  • 46
1
vote
1 answer

Make Eclipse CDT properly ignores my GSL span header

I use the Guidelines Support Library's gsl::span (from Neil Macintosh's implementation) - with the header located at /usr/local/src/gsl/include. I also use nVIDIA nSight 9.2, i.e. Eclipse CDT version 8.4.0.nvidia-something. I've added the include…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
0 answers

What should I call this unique-pointer-with-size structure?

I'm annoyed by how C++' standard library only offers some functionality via pointers rather than structures which keep both an address and a size. Specifically, suppose I want something like a unique_ptr, but which keeps the associated…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
2 answers

adding member function substr for std::span which imitates the string_view::substr

In my code, I would like to create a new class named Span by extending the std::span class, but the new Span has some extra member functions which does not exist in std::span. One is adding the remove_prefix function to std::span, which is…
ollydbg23
  • 1,124
  • 1
  • 12
  • 38
0
votes
1 answer

Emscripten and C++ 20

It looks like emscripten does not support C++ 20 I try to compile this: #include #include using std::span; int main() { int a[2] = {1, 3}; printf("hello, world!\n"); return 0; } command: ~/emsdk/upstream/emscripten/em++…
Anonymous
  • 255
  • 1
  • 10
0
votes
0 answers

Custom std::vector wrapper with view support

I have a large codebase that uses std::vector as data storage for numbers. However, now I need to add support for raw data views, due to external C library that returns raw array. Due to performance reasons, I dont want to copy data to…
Martin Perry
  • 9,232
  • 8
  • 46
  • 114
0
votes
1 answer

How to pass an empty span object?

Is there a way to pass an empty std::span to a function? I have a function like below: bool func( const std::vector& indices ) { if ( !indices.empty( ) ) { /* do something */ } ... } // when calling it with an…
digito_evo
  • 3,216
  • 2
  • 14
  • 42
0
votes
2 answers

How to use user defined concept as a template type of std::span?

I would like to use my user defined concept as a template type of std::span but template argument deduction does not work as I expected. When I try to pass a "std::array of char" to template function; compiler shows an error "error: no matching…
sakcakoca
  • 9
  • 2
0
votes
0 answers

Should std::ssize() still needed in C++20?

This answer answer that why C++20 introduced the std::ssize(), but according to latest std::span's specification, the size_type of std::span is now unsigned std::size_t, so is there other use case for std::ssize()?
康桓瑋
  • 33,481
  • 5
  • 40
  • 90
0
votes
1 answer

Construct a span> from an array>

I've got an std::array, N>, and I have methods for accessing parts of this buffer as different types, which I would like to use std::span> for. Is there a way to construct a span like this without invoking…
Voidev
  • 15
  • 1
  • 4
0
votes
1 answer

How to convert a std::vector of unique pointers to a std::span of raw pointers?

I have the following function in the interface of some module: void DoSomething(Span objects); , where Span is my simplified implementation of the C++20's std::span template. This function just iterates over a contiguous sequence…
Taras
  • 488
  • 3
  • 15
0
votes
1 answer

Why doesn't libstdc++ have span::span(Container&)?

According to cppreference, in C++20, std::span is supposed to be constructible using container references: template constexpr span(Container& cont); template constexpr span(const Container& cont); but in the…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
2 answers

How to write C++ library to work with any implementation of span?

I'm writing an I/O library where the user needs to supply blocks of memory to be read from or written to. Having my library accept a span seems the most natural fit since: It does not impose a container choice on the user. They can use raw…
marack
  • 2,024
  • 22
  • 31
0
votes
1 answer

How should I represent a contiguous sequence of elements I own?

I have a bunch of typed data in consecutive memory that I got as a T *; and I also know the number of elements (as a std::size_t although it doesn't matter much). I'd like to use some single type or data structure to represent my stretch of typed…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
-1
votes
1 answer

std::conditional with unknown type

I'm currently writing a library which makes use of C++20's std::span. Compiler library support for std::span is at this point rather scarce. Therefore, I have a marco which allows to use a 3rd-party implementation instead (in my case tcb::span). The…
Joel Bodenmann
  • 2,152
  • 2
  • 17
  • 44
1 2 3
4