vector of strings and array_view of string_views conversion conundrum #543
Replies: 1 comment
-
You could possibly modify
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is probably a generic C++ question, but it deals with ETL's hierarchy of classes, so I hope it belongs here.
I want to have a function that accepts a container of string-like objects (vectors of any size of strings of any size and C arrays of C strings). I've created it like this:
func(const etl::array_view<etl::string_view> &arg)
.With this I can call it for fixed arrays like this:
Here a
etl::array_view
is created implicitly from a C-array.Also I can call it for vectors like this:
So there is an owning vector
strings
of strings which is copied to a vectorlines
that only stores views of that strings. The function is called forlines
. I cannot pass avector<string>
directly because it's not actually a subclass ofvector<string_view>
(that can be used to create anarray_view<string_view>
).The question is this: is there a way for me to pass a
vector<string>
directly to my function without creating anothervector<string_view>
? Can I modify function declaration to accept a vector of strings as well as something created from C array of C strings?Beta Was this translation helpful? Give feedback.
All reactions