fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. enum types
  7. {
  8. INT,
  9. DOUBLE,
  10. CHAR,
  11. STRING
  12. };
  13.  
  14. struct multitype
  15. {
  16. types type;
  17.  
  18. union
  19. {
  20. int i;
  21. double d;
  22. char c;
  23. const char *s;
  24. } val;
  25.  
  26. multitype(int i)
  27. : type(INT)
  28. {
  29. val.i = i;
  30. }
  31.  
  32. multitype(double d)
  33. : type(DOUBLE)
  34. {
  35. val.d = d;
  36. }
  37.  
  38. multitype(char c)
  39. : type(CHAR)
  40. {
  41. val.c = c;
  42. }
  43.  
  44. multitype(const char *s)
  45. : type(STRING)
  46. {
  47. val.s = s;
  48. }
  49. };
  50.  
  51. struct helper
  52. {
  53. vector<multitype> arr;
  54.  
  55. template<typename T>
  56. helper& operator ,(T x)
  57. {
  58. arr.push_back(multitype(x));
  59. return *this;
  60. }
  61. };
  62.  
  63. void print(const helper& h)
  64. {
  65. for (int i = 0; i < h.arr.size(); i++)
  66. {
  67. const multitype& x = h.arr[i];
  68.  
  69. switch (x.type)
  70. {
  71. case INT:
  72. cout << x.val.i << endl;
  73. break;
  74. case DOUBLE:
  75. cout << x.val.d << endl;
  76. break;
  77. case CHAR:
  78. cout << x.val.c << endl;
  79. break;
  80. case STRING:
  81. cout << x.val.s << endl;
  82. break;
  83. }
  84. }
  85. }
  86.  
  87. #define PRINT(...) print((helper(), __VA_ARGS__))
  88.  
  89. int main()
  90. {
  91. PRINT(2, 4.2, 'a', "Hello");
  92. }
Success #stdin #stdout 0.01s 2816KB
stdin
Standard input is empty
stdout
2
4.2
a
Hello