#include <iostream>
#include <cstdarg>
using namespace std;
enum types
{
INT,
DOUBLE,
CHAR,
STRING
};
struct multitype
{
types type;
union
{
int i;
double d;
char c;
const char *s;
} val;
};
multitype mt(int i)
{
multitype res;
res.type = INT;
res.val.i = i;
return res;
}
multitype mt(double d)
{
multitype res;
res.type = DOUBLE;
res.val.d = d;
return res;
}
multitype mt(char c)
{
multitype res;
res.type = CHAR;
res.val.c = c;
return res;
}
multitype mt(const char *s)
{
multitype res;
res.type = STRING;
res.val.s = s;
return res;
}
void print(int n, ...)
{
va_list ap;
va_start(ap, n);
for (int i = 0; i < n; i++)
{
multitype x(va_arg(ap, multitype));
switch (x.type)
{
case INT:
cout << x.val.i << endl;
break;
case DOUBLE:
cout << x.val.d << endl;
break;
case CHAR:
cout << x.val.c << endl;
break;
case STRING:
cout << x.val.s << endl;
break;
}
}
va_end(ap);
}
int main()
{
print(4, mt(2), mt(4.2), mt('a'), mt("Hello"));
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGFyZz4KIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmVudW0gdHlwZXMKewogICAgSU5ULAogICAgRE9VQkxFLAogICAgQ0hBUiwKICAgIFNUUklORwp9OwogCnN0cnVjdCBtdWx0aXR5cGUKewogICAgdHlwZXMgdHlwZTsKIAogICAgdW5pb24KICAgIHsKICAgICAgICBpbnQgICAgICAgICBpOwogICAgICAgIGRvdWJsZSAgICAgIGQ7CiAgICAgICAgY2hhciAgICAgICAgYzsKICAgICAgICBjb25zdCBjaGFyICpzOwogICAgfSB2YWw7CiAKICAgIAp9OwogCm11bHRpdHlwZSBtdChpbnQgaSkKICAgIHsKICAgICAgICBtdWx0aXR5cGUgcmVzOwogICAgICAgIHJlcy50eXBlID0gSU5UOwogICAgICAgIHJlcy52YWwuaSA9IGk7CiAgICAgICAgcmV0dXJuIHJlczsKICAgIH0KIAptdWx0aXR5cGUgbXQoZG91YmxlIGQpCiAgICB7CiAgICAgICAgbXVsdGl0eXBlIHJlczsKICAgICAgICByZXMudHlwZSA9IERPVUJMRTsKICAgICAgICByZXMudmFsLmQgPSBkOwogICAgICAgIHJldHVybiByZXM7CiAgICB9CiAKbXVsdGl0eXBlIG10KGNoYXIgYykKICAgIHsKICAgICAgICBtdWx0aXR5cGUgcmVzOwogICAgICAgIHJlcy50eXBlID0gQ0hBUjsKICAgICAgICByZXMudmFsLmMgPSBjOwogICAgICAgIHJldHVybiByZXM7CiAgICB9CiAKbXVsdGl0eXBlIG10KGNvbnN0IGNoYXIgKnMpCiAgICB7CiAgICAgICAgbXVsdGl0eXBlIHJlczsKICAgICAgICByZXMudHlwZSA9IFNUUklORzsKICAgICAgICByZXMudmFsLnMgPSBzOwogICAgICAgIHJldHVybiByZXM7CiAgICB9CiAKdm9pZCBwcmludChpbnQgbiwgLi4uKQp7CiAgICB2YV9saXN0IGFwOwogCiAgICB2YV9zdGFydChhcCwgbik7CiAKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgewogICAgICAgIG11bHRpdHlwZSB4KHZhX2FyZyhhcCwgbXVsdGl0eXBlKSk7CiAKICAgICAgICBzd2l0Y2ggKHgudHlwZSkKICAgICAgICB7CiAgICAgICAgY2FzZSBJTlQ6CiAgICAgICAgICAgIGNvdXQgPDwgeC52YWwuaSA8PCBlbmRsOwogICAgICAgICAgICBicmVhazsKICAgICAgICBjYXNlIERPVUJMRToKICAgICAgICAgICAgY291dCA8PCB4LnZhbC5kIDw8IGVuZGw7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgQ0hBUjoKICAgICAgICAgICAgY291dCA8PCB4LnZhbC5jIDw8IGVuZGw7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgU1RSSU5HOgogICAgICAgICAgICBjb3V0IDw8IHgudmFsLnMgPDwgZW5kbDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgfQogCiAgICB2YV9lbmQoYXApOwp9CiAKaW50IG1haW4oKQp7CiAgICBwcmludCg0LCBtdCgyKSwgbXQoNC4yKSwgbXQoJ2EnKSwgbXQoIkhlbGxvIikpOwp9