5

From https://boost-ext.github.io/sml/examples.html#deferprocess

Modified to try and copy the fsm.

#include <boost/sml.hpp> #include <cassert> #include <deque> #include <queue> namespace sml = boost::sml; namespace { struct e1 {}; struct e2 {}; struct e3 {}; struct e4 {}; struct defer_and_process { auto operator()() const noexcept { using namespace sml; return make_transition_table( *"idle"_s + event<e1> / defer , "idle"_s + event<e2> = "s1"_s , "s1"_s + event<e1> / process(e2{}) = "s2"_s , "s2"_s + event<e3> / process(e4{}) , "s2"_s + event<e4> = X ); } }; } // namespace int main() { using namespace sml; boost::sml::sm<defer_and_process, sml::defer_queue<std::deque>, sml::process_queue<std::queue>> sm; /// defer_queue policy to enable deferred events using std::queue boost::sml::sm<defer_and_process, sml::defer_queue<std::deque>, sml::process_queue<std::queue>> secondSm; sm = secondSm; } 

Copies fine without policies. Is there a trick to it?

If not, then how can the fsm ever be put into a class, seeing how it's a c++ library? Pointers? But those are on the heap.

4
  • I apparently cannot. I'm not sure why not. Regardless, it's not a problem to store it in a class at all. The containing class will just not be copyable. unique_ptr<SM> to make it movable or shared_ptr<SM> to make it copyable. Of course, none of that make the SM actually copy. I'd refer to the library devs to find out about whether that's by design Commented Apr 21 at 22:05
  • Then maybe I have asked the wrong question. Cause without a copy then I don't know how to make an instance of the fsm later when all dependencies are finished, give them it, and then overwrite the fsm with that. Commented Apr 21 at 22:45
  • Yes, there's no way, unless there's another documented way to clone. Again, I'd file the issue on github Commented Apr 21 at 22:54
  • I'll get to that, yeah. Maybe ask if it's possible to inject dependencies later, too. I think this library might be for things like firmware and other such things, though, and not really general stuff. Commented Apr 21 at 23:06

1 Answer 1

1

Apparently it is not possible.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.