Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in dep resolution when requesting a "const T*" #579

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion include/boost/sml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ struct remove_reference<T &&> {
};
template <class T>
using remove_reference_t = typename remove_reference<T>::type;
template <class T>
struct remove_pointer {
using type = T;
};
template <class T>
struct remove_pointer<T *> {
using type = T;
};
template <class T>
using remove_pointer_t = typename remove_pointer<T>::type;
} // namespace aux
namespace aux {
using swallow = int[];
Expand Down Expand Up @@ -401,6 +411,14 @@ template <class T>
constexpr T &try_get(const pool_type<T &> *object) {
return object->value;
}
template <class T>
const T *try_get(const pool_type<const T *> *object) {
return object->value;
}
template <class T>
T *try_get(const pool_type<T *> *object) {
return object->value;
}
template <class T, class TPool>
constexpr T &get(TPool &p) {
return static_cast<pool_type<T> &>(p).value;
Expand All @@ -409,13 +427,22 @@ template <class T, class TPool>
constexpr const T &cget(const TPool &p) {
return static_cast<const pool_type<T> &>(p).value;
}
template <class T, class TPool>
T *get(TPool *p) {
return static_cast<pool_type<T> &>(p).value;
}
template <class T, class TPool>
const T *cget(const TPool *p) {
return static_cast<const pool_type<T> &>(p).value;
}
template <class... Ts>
struct pool : pool_type<Ts>... {
using boost_di_inject__ = type_list<Ts...>;
constexpr pool() = default;
constexpr explicit pool(Ts... ts) : pool_type<Ts>(ts)... {}
template <class... TArgs>
constexpr pool(init, const pool<TArgs...> &p) : pool_type<Ts>(try_get<aux::remove_const_t<aux::remove_reference_t<Ts>>>(&p))... {}
constexpr pool(init, const pool<TArgs...> &p)
: pool_type<Ts>(try_get<aux::remove_const_t<aux::remove_reference_t<aux::remove_pointer_t<Ts>>>>(&p))... {}
template <class... TArgs>
constexpr pool(const pool<TArgs...> &p) : pool_type<Ts>(init{}, p)... {}
};
Expand Down
84 changes: 84 additions & 0 deletions test/ft/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,90 @@ test dependencies_smart_ptrs = [] {
expect(sm.is(sml::X));
};

test dependencies_with_reference = [] {
struct Data {
int m_member { 42 };
};

struct c {
auto operator()() noexcept {
const auto action = [](Data& data) { expect(data.m_member == 42); };

using namespace sml;
return make_transition_table(*idle + event<e1> / action = X);
}
};

Data data;
sml::sm<c> sm{data};
sm.process_event(e1{});
expect(sm.is(sml::X));
};

test dependencies_with_const_reference = [] {
struct Data {
int m_member { 42 };
};

struct c {
auto operator()() noexcept {
const auto action = [](const Data& data) {
expect(data.m_member == 42);
};

using namespace sml;
return make_transition_table(*idle + event<e1> / action = X);
}
};

Data data;
sml::sm<c> sm{data};
sm.process_event(e1{});
expect(sm.is(sml::X));
};

test dependencies_with_pointer = [] {
struct Data {
int m_member { 42 };
};

struct c {
auto operator()() noexcept {
const auto action = [](Data* data) { expect(data->m_member == 42); };

using namespace sml;
return make_transition_table(*idle + event<e1> / action = X);
}
};

Data data;
sml::sm<c> sm{&data};
sm.process_event(e1{});
expect(sm.is(sml::X));
};

test dependencies_with_const_pointer = [] {
struct Data {
int m_member { 42 };
};

struct c {
auto operator()() noexcept {
const auto action = [](const Data* data) {
expect(data->m_member == 42);
};

using namespace sml;
return make_transition_table(*idle + event<e1> / action = X);
}
};

Data data;
sml::sm<c> sm{&data};
sm.process_event(e1{});
expect(sm.is(sml::X));
};

#if (_MSC_VER >= 1910) // MSVC 2017
test dependencies_multiple_subs = [] {
struct update {
Expand Down