Skip to content

Instantly share code, notes, and snippets.

@underdoeg
Created April 14, 2017 16:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save underdoeg/ea5f05728a1598b0eee54b14f9a7a505 to your computer and use it in GitHub Desktop.
Save underdoeg/ea5f05728a1598b0eee54b14f9a7a505 to your computer and use it in GitHub Desktop.
Convert a tuple of pointers to a tuple of references
#include <tuple>
#include <iostream>
template<typename ...T, size_t... I>
auto makeReferencesHelper(std::tuple<T...>& t , std::index_sequence<I...>)
{ return std::tie(*std::get<I>(t)...) ;}
template<typename ...T>
auto makeReferences( std::tuple<T...>& t ){
return makeReferencesHelper<T...>(t, std::make_index_sequence<sizeof...(T)>{});
}
int main(){
auto pointers = std::make_tuple(new int(5), new float(15.f), new double(25.));
auto ref = makeReferences(pointers);
std::get<0>(ref) = 999;
std::cout << *std::get<0>(pointers) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment