Consider a free function from the library of the third part, which expects the argument std::vector : void foo( std::vector<sometype>& );
Now I am writing a wrapper around this type to add member functions. To be able to use foo() with this type, I add an access function.
class Wrapper { private: std::vector<sometype> _data; public: std::vector<sometype>& data() { return _data; } const std::vector<sometype>& data() const { return _data; } //... other stuff };
That way I can still use foo() :
Wrapper a; foo( a.data() );
But now consider another function that expects a vector of sometype vectors ( edit: and which adds elements to this vector ):
void bar( std::vector<std::vector<sometype>>& );
But the data type I have is std::vector<Wrapper> vec;
Can I use my shell type to call bar() ? I want to do the following:
std::vector<Wrapper> vec; bar( ??? );
What I want to avoid is the first call to bar() with the required type, and then I have to copy the elements one by one into my vector<Wrapper> .
First I would say no, but maybe there is some kind of smart solution?
Edit2 : to give an example, consider the following game game for bar() with the root type int :
void bar( std::vector<std::vector<int>>& vv ) { std::vector<int> v1 = { 1,2,3 }; std::vector<int> v2 = { 4,5,6 }; vv.push_back(v1); vv.push_back(v2); }
c ++ vector stdvector wrapper
kebs
source share