#include <type_traits>
#include <tuple>
template<int... Is>
struct seq { };
template<int N, int... Is>
struct gen_seq : gen_seq<N - 1, N - 1, Is...> { };
template<int... Is>
struct gen_seq<0, Is...> : seq<Is...> { };
template<typename... Args, int... Is>
auto make_pointer_tuple(std::tuple<Args...>& t, seq<Is...>)
-> std::tuple<typename std::add_pointer<Args>::type...>
{
return std::forward_as_tuple(&std::get<Is>(t)...);
}
template<typename... Args>
auto make_pointer_tuple(std::tuple<Args...>& t)
-> std::tuple<typename std::add_pointer<Args>::type...>
{
return make_pointer_tuple(t, gen_seq<sizeof...(Args)>());
}
#include <string>
#include <iostream>
int main()
{
std::tuple<int, bool, std::string> myFavoriteTuple{0, false, ""};
int* pInt = nullptr;
bool* pBool = nullptr;
std::string* pString = nullptr;
tie(pInt, pBool, pString) = make_pointer_tuple(myFavoriteTuple);
*pInt = 42;
*pBool = true;
*pString = "Hello, World!";
std::cout << std::get<0>(myFavoriteTuple) << std::endl;
std::cout << std::get<1>(myFavoriteTuple) << std::endl;
std::cout << std::get<2>(myFavoriteTuple) << std::endl;
}
ICAgICNpbmNsdWRlIDx0eXBlX3RyYWl0cz4KICAgICNpbmNsdWRlIDx0dXBsZT4KCiAgICB0ZW1wbGF0ZTxpbnQuLi4gSXM+CiAgICBzdHJ1Y3Qgc2VxIHsgfTsKCiAgICB0ZW1wbGF0ZTxpbnQgTiwgaW50Li4uIElzPgogICAgc3RydWN0IGdlbl9zZXEgOiBnZW5fc2VxPE4gLSAxLCBOIC0gMSwgSXMuLi4+IHsgfTsKCiAgICB0ZW1wbGF0ZTxpbnQuLi4gSXM+CiAgICBzdHJ1Y3QgZ2VuX3NlcTwwLCBJcy4uLj4gOiBzZXE8SXMuLi4+IHsgfTsKCiAgICB0ZW1wbGF0ZTx0eXBlbmFtZS4uLiBBcmdzLCBpbnQuLi4gSXM+CiAgICBhdXRvIG1ha2VfcG9pbnRlcl90dXBsZShzdGQ6OnR1cGxlPEFyZ3MuLi4+JiB0LCBzZXE8SXMu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