title: Composing adaptors in Boost::range
body: <p>I started playing with Boost::Range in order to have a <a href="https://stackoverflow.com/questions/13144280/lazy-transform-in-c">pipeline of lazy transforms in C++</a>. My problem now is how to split a pipeline in smaller parts. Suppose I have:</p>
  
  <pre><code>int main(){
    auto map = boost::adaptors::transformed; // shorten the name
    auto sink = generate(1) | map([](int x){ return 2*x; })
                            | map([](int x){ return x+1; })
                            | map([](int x){ return 3*x; });
    for(auto i : sink)
      std::cout &lt;&lt; i &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>And I want to replace the first two maps with a <code>magic_transform</code>, i.e.:</p>
  
  <pre><code>int main(){
    auto map = boost::adaptors::transformed; // shorten the name
    auto sink = generate(1) | magic_transform()
                            | map([](int x){ return 3*x; });
    for(auto i : sink)
      std::cout &lt;&lt; i &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>How would one write <code>magic_transform</code>? I looked up <a href="http://www.boost.org/doc/libs/1_49_0/libs/range/doc/html/range/reference/extending/method_3.html" rel="nofollow noreferrer">Boost::Range's documentation</a>, but I can't get a good grasp of it.</p>
  
  <p><strong>Addendum</strong>: I'm looking to write a class like this:</p>
  
  <pre><code>class magic_transform {
      ... run_pipeline(... input) {
          return input | map([](int x){ return 2*x; })
                       | map([](int x){ return x+1; });
  };
  </code></pre>