#include <iostream>
#include <string>
#include <tuple>
template<typename T, T...>
struct integer_sequence { };
template<std::size_t N, std::size_t... I>
struct gen_indices : gen_indices<(N - 1), (N - 1), I...> { };
template<std::size_t... I>
struct gen_indices<0, I...> : integer_sequence<std::size_t, I...> { };
template<typename H>
std::string& to_string_impl(std::string& s, H&& h)
{
using std::to_string;
s += to_string(std::forward<H>(h));
return s;
}
template<typename H, typename... T>
std::string& to_string_impl(std::string& s, H&& h, T&&... t)
{
using std::to_string;
s += to_string(std::forward<H>(h));
return to_string_impl(s, std::forward<T>(t)...);
}
template<typename... T, std::size_t... I>
std::string to_string(const std::tuple<T...>& tup, integer_sequence<std::size_t, I...>)
{
std::string result;
int ctx[] = { (to_string_impl(result, std::get<I>(tup)...), 0), 0 };
(void)ctx;
return result;
}
template<typename... T>
std::string to_string(const std::tuple<T...>& tup)
{
return to_string(tup, gen_indices<sizeof...(T)>{});
}
int main(int argc, char** argv)
{
std::tuple<int, double, float> tup(1, 2.1, 3.2);
std::cout << to_string(tup) << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dHVwbGU+Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBULCBULi4uPgpzdHJ1Y3QgaW50ZWdlcl9zZXF1ZW5jZSB7IH07Cgp0ZW1wbGF0ZTxzdGQ6OnNpemVfdCBOLCBzdGQ6OnNpemVfdC4uLiBJPgpzdHJ1Y3QgZ2VuX2luZGljZXMgOiBnZW5faW5kaWNlczwoTiAtIDEpLCAoTiAtIDEpLCBJLi4uPiB7IH07CnRlbXBsYXRlPHN0ZDo6c2l6ZV90Li4uIEk+CnN0cnVjdCBnZW5faW5kaWNlczwwLCBJLi4uPiA6IGludGVnZXJfc2VxdWVuY2U8c3RkOjpzaXplX3QsIEkuLi4+IHsgfTsKCnRlbXBsYXRlPHR5cGVuYW1lIEg+CnN0ZDo6c3RyaW5nJiB0b19zdHJpbmdfaW1wbChzdGQ6On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