Commit 7f781560 authored by Dominik Charousset's avatar Dominik Charousset

Fix vector<bool> serialization, close #540

parent 45931267
...@@ -226,6 +226,28 @@ public: ...@@ -226,6 +226,28 @@ public:
return convert_apply(dref(), x, tmp, assign); return convert_apply(dref(), x, tmp, assign);
} }
// no better way around this abomination
error consume_range(std::vector<bool>& xs) {
auto i = xs.begin();
auto e = xs.end();
using proxy_iterator = decltype(i);
struct {
void operator()(proxy_iterator& lhs, bool& rhs) const {
*lhs = rhs;
}
void operator()(bool& lhs, proxy_iterator& rhs) const {
lhs = *rhs;
}
} assign;
bool tmp;
for (; i != e; ++i) {
auto err = convert_apply(dref(), i, tmp, assign);
if (err)
return err;
}
return none;
}
template <class T> template <class T>
error consume_range(T& xs) { error consume_range(T& xs) {
for (auto& x : xs) { for (auto& x : xs) {
......
...@@ -137,7 +137,7 @@ public: ...@@ -137,7 +137,7 @@ public:
&& !has_to_string<T>::value> && !has_to_string<T>::value>
consume(T& xs) { consume(T& xs) {
result_ += '['; result_ += '[';
for (auto& x : xs) { for (auto&& x : xs) {
sep(); sep();
consume(deconst(x)); consume(deconst(x));
} }
......
...@@ -134,6 +134,7 @@ public: ...@@ -134,6 +134,7 @@ public:
add_message_type<raw_struct>("raw_struct"); add_message_type<raw_struct>("raw_struct");
add_message_type<test_array>("test_array"); add_message_type<test_array>("test_array");
add_message_type<test_empty_non_pod>("test_empty_non_pod"); add_message_type<test_empty_non_pod>("test_empty_non_pod");
add_message_type<std::vector<bool>>("bool_vector");
} }
}; };
...@@ -474,4 +475,11 @@ CAF_TEST(long_sequences) { ...@@ -474,4 +475,11 @@ CAF_TEST(long_sequences) {
CAF_CHECK_EQUAL(n, m); CAF_CHECK_EQUAL(n, m);
} }
CAF_TEST(bool_vector) {
std::vector<bool> xs{true, true, false, false, true};
CAF_CHECK_EQUAL(deep_to_string(xs), "[1, 1, 0, 0, 1]");
CAF_CHECK_EQUAL(xs, roundtrip(xs));
CAF_CHECK_EQUAL(xs, msg_roundtrip(xs));
}
CAF_TEST_FIXTURE_SCOPE_END() CAF_TEST_FIXTURE_SCOPE_END()
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