The C++ codebase I'm working on calls a C API that returns both a pointer to a list of structs and the length of the list. What would be the idiomatic means of processing this list with ranges? Is there an existing adapter or is creating a custom range_facade
type the best way of handling this?
Asked
Active
Viewed 97 times
0

Tim Clemons
- 6,231
- 4
- 25
- 23
-
3Please post some code to make your question a bit more clear. – R Sahu Jun 08 '17 at 21:18
-
1`view::counted` ? – Jarod42 Jun 08 '17 at 21:19
-
2`ranges::span`. – Casey Jun 08 '17 at 21:19
-
A [wrapper](https://godbolt.org/g/7JId3W) is simple to write. – DeiDei Jun 08 '17 at 21:36
-
[std::mcve](https://stackoverflow.com/help/mcve) should do what you want. – Captain Obvlious Jun 08 '17 at 21:56
-
What kind of processing do you want to do? You already have a pointer, just treat it as if it were an array, and let the compiler do the rest of the work for you. What more do you want? – Remy Lebeau Jun 08 '17 at 23:16
1 Answers
1
You want to use view::counted(ptr, length)
to make a range of length
elements starting at ptr
.

Eric Niebler
- 5,927
- 2
- 29
- 43