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*" #347

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 27 additions & 1 deletion include/boost/sml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ struct remove_reference<T &&> {
};
template <class T>
using remove_reference_t = typename remove_reference<T>::type;
template <class T>
kris-jusiak marked this conversation as resolved.
Show resolved Hide resolved
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 {
using swallow = int[];
Expand Down Expand Up @@ -363,6 +373,14 @@ template <class T>
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>
T &get(TPool &p) {
return static_cast<pool_type<T> &>(p).value;
Expand All @@ -371,13 +389,21 @@ template <class T, class TPool>
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...>;
pool() = default;
explicit pool(Ts... ts) : pool_type<Ts>(ts)... {}
template <class... TArgs>
pool(init, const pool<TArgs...> &p) : pool_type<Ts>(try_get<aux::remove_const_t<aux::remove_reference_t<Ts>>>(&p))... {}
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>
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 @@ -142,6 +142,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