title: how do I compose multiple functors using boost bind?
body: <p>I've got a situation where I have a series of member functions which produce simple information on a target object:</p>
  
  <pre><code>double MyDoc::GetX(thing)
  double MyDoc::GetY(thing)
  etc.
  </code></pre>
  
  <p>I've made some "pretty formatting" member functions in the same class:</p>
  
  <pre><code>string MyDoc::PrintOne(thing, std::function&lt;double (THING*)&gt;)
  </code></pre>
  
  <p>You'll notice that the pretty-printer function takes a data-function - i.e. it is composable so that I can create various types of information about a target and produce a "pretty print" string for it.</p>
  
  <p>In direct usage, this technique works beautifully.</p>
  
  <p>However, what I really want for my current application is to compose multiple layers of such entities - i.e. effectively create a functor (function object) for the above composition as a whole, such that I can specify pretty-printer function, and it's data-acquisition function, and call that later.  Pattern is z(x) -> f(x, g(x)):</p>
  
  <pre><code>auto Z = [&amp;] (THING* thing) {
      return boost::bind(
          &amp;MyDoc::PrintOne,
          this,
          _1,
          boost::bind(MyDoc::GetX, this, _1));
  }
  </code></pre>
  
  <p>And here is where I run into problems.  I am going in circles trying to get the syntax right, or maybe I'm getting confused with the boost::bind syntax versus the C++ lambda syntax, or maybe I'm just fundamentally misunderstanding something?</p>
  
  <p>Basically, I want to compose a function Z which takes a THING* and another function X which also takes a THING* and, using logic of its own, produces a string output for a given THING*.</p>
  
  <p>I have variations - some take two data-accessor type functions, or maybe a bool + data accessor.  Doesn't really matter - the bottom line should be the same:</p>
  
  <p><strong>How do I compose Z where Z -> F(x, G(x))?</strong></p>
  
  <p>Thanks for any and all help!</p>