How do you implement this:
template <class A, class ... T> struct wrapper {
template <int depth>
A<depth>& get(); // returns a reference to the Nth item wrapped in A;
};
e.g.
wrapper<vector, int, double, string> example;
int x=example.get<0>[7]; // return the vector of `int` at position 0 and call operator[]
auto y=example.get<1>.size(); // return the vector of `double` at position 1 and get it's size
This is what I tried:
template<class A, class ... T>
struct wrapper {
using WRAPPED=decl_type(std::apply(
[](auto ...x){
std::make_tuple(A[x], ...);
},
T...));
WRAPPED elems;
template <int depth>
decl_type(std::get<depth>(elems))& get() { return std::get<depth>(elems); }
};
But the compiler was not happy:
<source>:71:23: error: expected type-specifier before 'decl_type'
71 | using WRAPPED=decl_type(std::apply(
| ^~~~~~~~~
<source>:74:14: error: expected unqualified-id before ',' token
74 | },
| ^
<source>:76:9: error: 'WRAPPED' does not name a type
76 | WRAPPED elems;
| ^~~~~~~
<source>:79:24: error: 'std::get' is not a type
79 | decl_type(std::get<depth>(elems))& get() { return std::get<depth>(elems); }
| ^~~~~~~~~~
<source>:79:44: error: expected constructor, destructor, or type conversion before 'get'
79 | decl_type(std::get<depth>(elems))& get() { return std::get<depth>(elems); }
| ^~~
Compiler returned: 1