Created
April 14, 2017 16:42
-
-
Save underdoeg/ea5f05728a1598b0eee54b14f9a7a505 to your computer and use it in GitHub Desktop.
Convert a tuple of pointers to a tuple of references
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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