language: C++11 (gcc-4.7.2)
date: 633 days 14 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <vector>
 
struct any {
  any(int   e) { INT    = e; }
  any(float e) { FLOAT  = e; }
  any(char* e) { STRING = e; }
 
  int   INT;
  float FLOAT;
  char *STRING;
};
 
template<typename T> struct get        { T     operator()(const any& a) { return T();      }};
template<>           struct get<int>   { int   operator()(const any& a) { return a.INT;    }};
template<>           struct get<float> { float operator()(const any& a) { return a.FLOAT;  }};
template<>           struct get<char*> { char* operator()(const any& a) { return a.STRING; }};
 
#define def(name)                                 \
  template <typename... A>                        \
  std::vector<any> name##_imp(A... args) {        \
    std::vector<any> vec = {args...};             \
    return vec;                                   \
  }                                               \
  template<typename... P>                         \
  void name (P... rgs) {                          \
    std::vector<any> args=name##_imp(any(rgs)...);
  
 
#define get(T,I) get<T>()(args[I])
#define end }
 
///// TEST /////
def (test)
   int   i = get(int  ,0);
   float f = get(float,1);
   char *s = get(char*,2);
 
   std::cout << "I: " << i << std::endl;
   std::cout << "F: " << f << std::endl;
   std::cout << "S: " << s << std::endl;
end
  
int main()
{
    char s[] = "Hello";
    test(1, 3.4f, s);
}