Assume I have a member variable std::vector<std::string>
in a class and I want to return it from a member function as an immutable view using a combination of gsl::array_view
and gsl::cstring_view
. Unfortunately, the following doesn't compile:
class C {
public:
gsl::array_view<const gsl::cstring_view<>> getVectorOfStrings() const
{
return _vectorOfStrings;
}
private:
std::vector<std::string> _vectorOfStrings;
};
The reason for this is that there's no container of cstring_view
that the array_view
can be created from. So my question is: is there a way to use such a construct without explicitly adding something like a member of type std::vector<gsl::cstring_view<>>
, which is clearly undesirable?
Edit
It seems to me that such 'transforming' views might be of more general use. Consider having a vector
of owning pointers, such as std::vector<std::shared_ptr<T>>
, which I'd like to expose to the user of the class as an array_view
of raw pointers: gsl::array_view<const T*>
without exposing my implementation-defined storage approach. Thoughts?