I\'m writing a custom iterator that, when dereferenced returns a tuple of references. Since the tuple itself is ephemeral, I don\'t think I can return a reference from oper
The answer I came up with was to write a tuple wrapper class:
template
struct tupleWrapper{
std::tuple data;
tupleWrapper(std::tuple _data) : data{_data}
{}
operator std::tuple () {return data;}
std::tuple& asTuple() {return data;}
};
template
void swap(tupleWrapper t1, tupleWrapper t2){
std::swap(t1.data, t2.data);
}
And a get function that can be found with ADL, since the conversion operator doesn't get called when doing TAD for std::get.
template
auto get(tupleWrapper tw)->decltype(std::get(tw.data)){
return std::get(tw.data);
}
It's not ideal, but I think it will work well enough.