title: Simulate generic/templated lambdas on C++11
body: <p>I got a problem on where I have something like this:</p>
  
  <pre><code>#define A_BODY printf("b is %s and c is %d, typeless! :3\n", b, c);
  #define B_BODY return "test";
  #define C_BODY return 42;
  </code></pre>
  
  <p>I need to make a code that would, for example, call a(b(), c()), with their respective types.</p>
  
  <p>On C++14 I can easely do this:</p>
  
  <pre><code>template&lt;typename B, typename C&gt; auto a(B &amp;&amp;b, C &amp;&amp;c) {
    A_BODY
  };
  auto b() {
    B_BODY
  };
  auto c() {
    C_BODY
  };
  
  int main() {
    auto _b = b();
    auto _c = c();
    auto _a = a(_b, _c);
  
    return 0;
  };
  </code></pre>
  
  <p>Achieving the desired result... is there any way to get the same result on C++11? :'(</p>
  
  <p>Also, they can call each other recursively, so a simple ordering here wouldn't help either.</p>
  
  <h1>Edit</h1>
  
  <p>I will try to explain better my situation.</p>
  
  <p>I got an input file like this, for example:</p>
  
  <pre><code>a is b c {
    printf("b is %s and c is %d\n", b, c);
    if(c &gt; 42)
      printf("c is bigger than the truth!\n");
    return strlen(b) + c;
  };
  b is {
    return "test";
  };
  c is {
    return 42;
  };
  </code></pre>
  
  <p>And I need to generate a C++ code that can properly call them. I'm trying to infer the return types without needing to define them on the input file.</p>
  
  <p>From that, I can get the <code>*_BODY</code> specifications, the number of parameters, and the order of calls, but I don't know which type the parameters will be. So I'd need an templated lambda, for example, to do lazy evaluation of the function body.</p>
  
  <p>I can do this with C++14 on GCC and CLang, but this is a commercial project and I need to support Visual Studio 2012 as well. I'm trying to find a workaround, if there is any. :(</p>