@@ -678,6 +678,107 @@ test initial_nontrivial_exit = [] {
678678 }
679679};
680680
681+ template <int N>
682+ struct tstate {
683+ auto operator ()() noexcept {
684+ using namespace sml ;
685+ // clang-format off
686+ return make_transition_table (
687+ *idle + sml::on_entry<_> / [](std::string& s) { s+=" ts" + std::to_string (N) + " _en|" ; }
688+ ,idle + sml::on_entry<e1 > / [](std::string& s) { s+=" ts" +std::to_string (N)+" e1en|" ; }
689+ ,idle + sml::on_exit<_> / [](std::string& s) { s+=" ts" +std::to_string (N)+" _ex|" ; }
690+ ,idle + sml::on_exit<e1 > / [](std::string& s) { s+=" ts" +std::to_string (N)+" e1ex|" ; }
691+ );
692+ // clang-format on
693+ }
694+ };
695+ auto t1 = sml::state<tstate<1 >>;
696+ auto t2 = sml::state<tstate<2 >>;
697+ auto t3 = sml::state<tstate<3 >>;
698+ auto t4 = sml::state<tstate<4 >>;
699+
700+ test composite_nontrivial_entry = [] {
701+ struct c {
702+ auto operator ()() noexcept {
703+ using namespace sml ;
704+ // clang-format off
705+ return make_transition_table (
706+ *t1 + sml::on_entry<_> / [](std::string& calls) { calls+=" t1_en|" ; }
707+ ,t1 + sml::on_entry<e2 > / [](std::string& calls) { calls+=" t1e2en|" ; }
708+ );
709+ // clang-format on
710+ }
711+ };
712+
713+ struct d {
714+ auto operator ()() noexcept {
715+ using namespace sml ;
716+ // clang-format off
717+ return make_transition_table (
718+ *idle + event<e2 > = state<c>
719+ , idle + event<e1 > = state<c>
720+ , state<c> + event<e2 > = idle
721+ );
722+ // clang-format on
723+ }
724+ };
725+ {
726+ // Test with a composite sm
727+ std::string s;
728+ sml::sm<d> sm{s};
729+ sm.process_event (e1 {});
730+ expect (" t1_en|ts1e1en|" == s);
731+ s = " " ;
732+ sm.process_event (e2 {});
733+ expect (" ts1_ex|" == s);
734+ s = " " ;
735+ sm.process_event (e2 {});
736+ expect (" t1e2en|ts1_en|" == s);
737+ }
738+ };
739+
740+ test composite_nontrivial_exit = [] {
741+ struct c {
742+ auto operator ()() noexcept {
743+ using namespace sml ;
744+ // clang-format off
745+ return make_transition_table (
746+ *t1 + sml::on_exit<_> / [](std::string& calls) { calls+=" t1_ex|" ; }
747+ ,t1 + sml::on_exit<e2 > / [](std::string& calls) { calls+=" t1e2ex|" ; }
748+ ,t1 + event<e1 > = t2
749+ ,t1 + event<e2 > = t2
750+ ,t2 + sml::on_exit<_> / [](std::string& calls) { calls+=" t2_ex|" ; }
751+ ,t2 + sml::on_exit<e4 > / [](std::string& calls) { calls+=" t2e4ex|" ; }
752+ );
753+ // clang-format on
754+ }
755+ };
756+
757+ struct d {
758+ auto operator ()() noexcept {
759+ using namespace sml ;
760+ // clang-format off
761+ return make_transition_table (
762+ *state<c> + event<e4 > = idle
763+ ,state<c> + sml::on_exit<_> / [](std::string& calls) { calls+=" c_ex|" ; }
764+ );
765+ // clang-format on
766+ }
767+ };
768+ {
769+ // Test with a composite sm
770+ std::string s;
771+ sml::sm<d> sm{s};
772+ expect (" ts1_en|" == s);
773+ s = " " ;
774+ sm.process_event (e1 {});
775+ expect (" ts1e1ex|t1_ex|ts2e1en|" == s);
776+ s = " " ;
777+ sm.process_event (e4 {});
778+ expect (" ts2_ex|t2e4ex|c_ex|" == s);
779+ }
780+ };
781+
681782#if !defined(_MSC_VER)
682783test general_transition_overload = [] {
683784 struct c {
0 commit comments