title: Stackful coroutines that support cloning a paused routine
body: <p>I'm implementing a game engine and plan on building an AI on top of it, starting with a simple model with States and Moves, where each distinct game State has a set of Moves, and Moves take you from one State to another, e.g.</p>
  
  <p>Move: State -> State</p>
  
  <p>In order to support AI functionality, I need the ability to <em>copy</em> a State so that I can test each possible Move for it (while leaving the original state <em>intact</em>), in order to implement branching logic.</p>
  
  <p>The problem is that it is difficult to copy the State. A State cannot be simply encapsulated with an instance of a class, because the game State includes information on the <em>current execution context of the program</em>. In programming terminology, the entire program stack is a part of the State. </p>
  
  <p>I notice that coroutines provide most of what I want, in particular, stackful coroutines. They allow the programmer to treat an entire execution stack as an object, which can be paused and resumed, which is exactly what I need. The paused stackful coroutine, <em>along with</em> a class instance, fully captures the game State. However, I also need the ability to clone the paused coroutine, so that I can resume it from where it was left off <em>more than once from the same resume point</em>, with different parameters each time. Each set of parameters corresponds to applying a different Move to the State.</p>
  
  <p>I'm experienced with C++ but new to coroutines. I went through the basic documentation of Boost coroutines and didn't find any mention of the ability to clone a stackful coroutine. Before I dive in and start using this library, I'd need assurance that it supports this. If it doesn't, I will be forced to implement the required logic using homebaked assembly and stack manipulation, but a library that already does this is preferable. Does Boost support this? If not, is there anything else that would work?</p>