Skip to content

breaking: injected dependencies are not allowed to be const lvalue references anymore #711

@dornbirndevelops

Description

@dornbirndevelops

hello,

the following minimal reproducible example fails to compile since fb7e081 (according to git bisect):

#include <boost/sml.hpp>

struct Dependency { bool ok{}; };
struct Event {};
struct State {};
struct Guard { bool operator()(const Event&, const Dependency& d) const { return d.ok; } };

struct SM {
    auto operator()() const noexcept
    {
        using namespace boost::sml;

        constexpr auto guard = Guard{};

        return make_transition_table(
          * state<State> + event<Event> [guard] = X
        );
    }
};

void lValueScenario()
{
    auto d = Dependency{
        .ok = true,
    };
    auto sm = boost::sml::sm<SM>(d);
    sm.process_event(Event{});
}

void constLValueScenario()
{
    // expectation:
    // - const lvalue references are allowed in case all guards/actions are accessing the dependency via const lvalue reference
    // actual:
    // - does not compile anymore, user is forced to use non-const lvalue references
    const auto d = Dependency{
        .ok = true,
    };
    auto sm = boost::sml::sm<SM>(d);
    sm.process_event(Event{});
}

i understand that the change fixes the issue of decoupled state data, but it also breaks the existing API.

would it be an option to perform the normalization const U& → U& only if at least one action uses the non-const reference?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions