document operator, limitation for two raw MFP actions and show wrap() fix (issue #389)#678
Open
PavelGuzenfeld wants to merge 1 commit into
Open
Conversation
…oost-ext#389) Two raw member-function-pointer actions combined with comma, / (&C::a, &C::b) silently run only the last action. Raw MFPs are pointer types, not class types, so the C++ standard requires the built-in comma operator to be selected regardless of any user-defined operator, overloads. This is a language limitation that cannot be fixed in the library. The workaround is to wrap the first MFP with sml::wrap(): / (sml::wrap(&C::a), &C::b) wrap() returns a zero_wrapper class type, enabling the user-defined operator, overload that creates a seq_ action sequence. Subsequent actions (raw MFPs, lambdas, or functors) chain correctly from there. Changes: - Add an explanatory comment above operator, in sml.hpp describing the language constraint and the wrap() workaround. - Update example/actions_guards.cpp: replace the single-MFP action on the s5 transition with (wrap(&self::action4), &self::action5) to demonstrate two-MFP sequencing. - Add regression test member_functions_two_mfp_actions_with_wrap in test/ft/transition_table.cpp that verifies both actions execute.
bedd4eb to
d671f8a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #389.
Root cause
/ (&C::action_a, &C::action_b)uses the C++ built-in comma operator instead of the library's action-sequencingoperator,. Raw member-function pointers are pointer types, not class types. The C++ standard only allows user-definedoperator,to be selected when at least one operand is a class or enum type, so the built-in comma always wins for two raw MFPs — silently discarding the first action.This is a C++ language constraint that cannot be removed at the library level.
Workaround:
sml::wrap()the first MFPsml::wrap()returns azero_wrapper<MFP>, which is a class type. That satisfies the requirement and the user-definedoperator,is selected:Subsequent actions in the list (additional MFPs, lambdas, functors) chain correctly from there without extra
wrap()calls, because eachoperator,already produces a class-typedseq_result.Changes
include/boost/sml.hpp: add a comment above the globaloperator,overload explaining the language constraint and thewrap()workaround.example/actions_guards.cpp: replace the single-MFP action on thes5transition with(wrap(&self::action4), &self::action5)to demonstrate two-MFP sequencing.test/ft/transition_table.cpp: addmember_functions_two_mfp_actions_with_wrap— verifies that both actions run when the first MFP is wrapped.