#include <iostream>
#include <utility>
template <typename T>
struct base_type {};
template <>
struct base_type<int> {
static std::string get_type() {return "int";}
};
template <>
struct base_type<float> {
static std::string get_type() {return "float";}
};
// write more specializations for primitive and pointers and arrays, not important here
struct ubiq_lref {
std::string& out;
std::string dummy;
ubiq_lref(const int&_): out(dummy) {}
ubiq_lref(std::string &x, const int& _): out(x) {}
template <typename T>
operator T () {
out += base_type<T>::get_type() + ", ";
return T();
}
};
template <typename T, int ... ints>
struct reflect {
static std::string get_members() {
std::string s = "{";
T{ubiq_lref(s, ints)...};
s += "}";
return s;
}
};
template <typename T, int ... ints>
auto get_str(int) ->typename std::enable_if<std::is_same<decltype(T{ubiq_lref(ints)...}), T>::value, std::string>::type {
return reflect<T, ints...>::get_members();
}
template <typename T, int a, int...ints>
auto get_str(long) -> std::string {
return get_str<T, ints...>(0);
}
template <typename T, int...ints>
std::string get_members(std::integer_sequence<int, ints...> _) {
return get_str<T, ints...>(0);
}
struct foo {
int x;
float y;
int z;
};
int main() {
// your code goes here
std::cout << get_members<foo>(std::make_integer_sequence<int, (int)sizeof(foo)>()) << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KCgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4Kc3RydWN0IGJhc2VfdHlwZSB7fTsKCnRlbXBsYXRlIDw+CnN0cnVjdCBiYXNlX3R5cGU8aW50PiB7CglzdGF0aWMgc3RkOjpzdHJpbmcgZ2V0X3R5cGUoKSB7cmV0dXJuICJpbnQiO30JCn07Cgp0ZW1wbGF0ZSA8PgpzdHJ1Y3QgYmFzZV90eXBlPGZsb2F0PiB7CglzdGF0aWMgc3RkOjpzdHJpbmcgZ2V0X3R5cGUoKSB7cmV0dXJuICJmbG9hdCI7fQkKfTsKCi8vIHdyaXRlIG1vcmUgc3BlY2lhbGl6YXRpb25zIGZvciBwcmltaXRpdmUgYW5kIHBvaW50ZXJzIGFuZCBhcnJheXMsIG5vdC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