title: Composite function in C++
body: <p>I am a beginner in C++ and want to do simple example of composite function. 
  For example, in MATLAB, I can write</p>
  
  <pre><code>a = @(x) 2*x
  b = @(y) 3*y
  a(b(1))
  </code></pre>
  
  <p>Answer is <code>6</code></p>
  
  <p>I searched following questions. 
  <a href="https://stackoverflow.com/questions/19071268/function-composition-in-c-c11">function composition in C++ / C++11</a> and 
  <a href="https://stackoverflow.com/questions/2841619/function-composition-in-c?noredirect=1&amp;lq=1">Function Composition in C++</a></p>
  
  <p>But they are created using advanced features, such as templates, to which I am not much familiar at this time. Is there a simple and more direct way to achieve this? In above MATLAB code, user does not need to know implementation of function handles. User can just use proper syntax to get result. Is there such way in C++?</p>
  
  <p>** Another Edit:**</p>
  
  <p>In above code, I am putting a value at the end. However, if I want to pass the result to a third function, MATLAB can still consider it as a function. But, how to do this in C++?</p>
  
  <p>For example, in addition to above code, consider this code:</p>
  
  <pre><code>c = @(p,q) a(p)* b(q)  %This results a function
  c(1,2)
  answer=12
  
  d = @(r) a(b(r))
  d(1)
  answer=6
  
  function [ output1 ] = f1( arg1 )
  val = 2.0;
  output1 = feval(arg1,val)
  end
  
  f1(d)
  answer = 12
  </code></pre>
  
  <p>In this code, <code>c</code> takes two functions as input and <code>d</code> is composite function. In the next example, function <code>f1</code> takes a function as argument and use MATLAB builtin function <code>feval</code> to evaluate the function at <code>val</code>.</p>
  
  <p>How can I achieve this in C++?</p>