Commit 8d1cfa39 authored by Dominik Charousset's avatar Dominik Charousset

fixes an issue with user-defined message types

this patch fixes a compile time error with some user-defined
message types; a minimal example to reproduce the error in 0.8.1 is:

typedef optional_variant<
        std::tuple<int, float>
      , std::tuple<float, int, int>
      > msg_type;

    //                                    here!
    sync_send(self, atom("msg")).then([](msg_type) {});
parent 3f781282
......@@ -35,6 +35,7 @@
#include <cstddef>
#include "cppa/util/type_traits.hpp"
#include "cppa/util/rebindable_reference.hpp"
namespace cppa {
......@@ -90,8 +91,9 @@ inline auto get_ref(std::tuple<Ts...>& tup) -> decltype(std::get<Pos>(tup)) {
* depending on the cv-qualifier of @p tup.
*/
template<size_t Pos, class Tuple>
inline auto get_cv_aware(Tuple& tup) -> decltype(get_ref<Pos>(tup)) {
return get_ref<Pos>(tup);
inline auto get_cv_aware(Tuple& tup)
-> decltype(util::unwrap_ref(get_ref<Pos>(tup))) {
return util::unwrap_ref(get_ref<Pos>(tup));
}
/**
......@@ -99,8 +101,9 @@ inline auto get_cv_aware(Tuple& tup) -> decltype(get_ref<Pos>(tup)) {
* depending on the cv-qualifier of @p tup.
*/
template<size_t Pos, class Tuple>
inline auto get_cv_aware(const Tuple& tup) -> decltype(get<Pos>(tup)) {
return get<Pos>(tup);
inline auto get_cv_aware(const Tuple& tup)
-> decltype(util::unwrap_ref(get<Pos>(tup))) {
return util::unwrap_ref(get<Pos>(tup));
}
} // namespace cppa
......
......@@ -114,6 +114,22 @@ class rebindable_reference {
};
template<typename T>
T& unwrap_ref(T& ref) {
return ref;
}
template<typename T>
T& unwrap_ref(util::rebindable_reference<T>& ref) {
return ref.get();
}
template<typename T>
typename std::add_const<T>::type&
unwrap_ref(const util::rebindable_reference<T>& ref) {
return ref.get();
}
} } // namespace cppa::util
#endif // CPPA_REBINDABLE_REFERENCE_HPP
......@@ -82,7 +82,7 @@ std::uint32_t type_lookup_table::id_of(pointer uti) const {
void type_lookup_table::emplace(std::uint32_t id, pointer instance) {
CPPA_REQUIRE(instance);
CPPA_REQUIRE(instance != nullptr);
value_type kvp{id, instance};
auto i = find(id);
if (i == m_data.end()) m_data.push_back(std::move(kvp));
......
......@@ -160,7 +160,12 @@ struct server : event_based_actor {
};
void compile_time_optional_variant_check() {
typedef optional_variant<std::tuple<int, float>,
std::tuple<float, int, int>>
msg_type;
sync_send(self, atom("msg")).then([](msg_type) {});
}
int main() {
CPPA_TEST(test_sync_send);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment