Commit 3301e1f0 authored by Dominik Charousset's avatar Dominik Charousset

Fix handling of containers with user-defined types

parent 16f48056
...@@ -240,12 +240,10 @@ public: ...@@ -240,12 +240,10 @@ public:
template <class T> template <class T>
error consume_range(T& xs) { error consume_range(T& xs) {
for (auto& x : xs) { for (auto& x : xs) {
using value_type = typename std::remove_const< using value_type = typename std::remove_reference<decltype(x)>::type;
typename std::remove_reference<decltype(x)>::type using mutable_type = typename std::remove_const<value_type>::type;
>::type; if (auto err = apply_derived(const_cast<mutable_type&>(x)))
auto e = apply(const_cast<value_type&>(x)); return err;
if (e)
return e;
} }
return none; return none;
} }
...@@ -254,9 +252,8 @@ public: ...@@ -254,9 +252,8 @@ public:
template <class U, class T> template <class U, class T>
error consume_range_c(T& xs) { error consume_range_c(T& xs) {
for (U x : xs) { for (U x : xs) {
auto e = apply(x); if (auto err = apply_derived(x))
if (e) return err;
return e;
} }
return none; return none;
} }
...@@ -267,8 +264,7 @@ public: ...@@ -267,8 +264,7 @@ public:
auto insert_iter = std::inserter(xs, xs.end()); auto insert_iter = std::inserter(xs, xs.end());
for (size_t i = 0; i < num_elements; ++i) { for (size_t i = 0; i < num_elements; ++i) {
typename std::remove_const<typename T::value_type>::type x; typename std::remove_const<typename T::value_type>::type x;
auto err = apply(x); if (auto err = apply_derived(x))
if (err)
return err; return err;
*insert_iter++ = std::move(x); *insert_iter++ = std::move(x);
} }
...@@ -282,8 +278,7 @@ public: ...@@ -282,8 +278,7 @@ public:
auto insert_iter = std::inserter(xs, xs.end()); auto insert_iter = std::inserter(xs, xs.end());
for (size_t i = 0; i < num_elements; ++i) { for (size_t i = 0; i < num_elements; ++i) {
U x; U x;
auto err = apply(x); if (auto err = apply_derived(x))
if (err)
return err; return err;
*insert_iter++ = std::move(x); *insert_iter++ = std::move(x);
} }
...@@ -380,8 +375,8 @@ public: ...@@ -380,8 +375,8 @@ public:
using t0 = typename std::remove_const<F>::type; using t0 = typename std::remove_const<F>::type;
// This cast allows the data processor to cope with // This cast allows the data processor to cope with
// `pair<const K, V>` value types used by `std::map`. // `pair<const K, V>` value types used by `std::map`.
return error::eval([&] { return apply(const_cast<t0&>(xs.first)); }, return error::eval([&] { return apply_derived(const_cast<t0&>(xs.first)); },
[&] { return apply(xs.second); }); [&] { return apply_derived(xs.second); });
} }
template <class... Ts> template <class... Ts>
...@@ -522,8 +517,9 @@ public: ...@@ -522,8 +517,9 @@ public:
typename std::remove_reference<T>::type typename std::remove_reference<T>::type
>::value), >::value),
"a loading inspector requires mutable lvalue references"); "a loading inspector requires mutable lvalue references");
auto e = apply(deconst(x)); if (auto err = apply(deconst(x)))
return e ? e : (*this)(std::forward<Ts>(xs)...); return err;
return apply_derived(std::forward<Ts>(xs)...);
} }
protected: protected:
...@@ -565,15 +561,14 @@ private: ...@@ -565,15 +561,14 @@ private:
static typename std::enable_if<D::reads_state, error>::type static typename std::enable_if<D::reads_state, error>::type
convert_apply(D& self, T& x, U& storage, F assign) { convert_apply(D& self, T& x, U& storage, F assign) {
assign(storage, x); assign(storage, x);
return self.apply(storage); return self(storage);
} }
template <class D, class T, class U, class F> template <class D, class T, class U, class F>
static typename std::enable_if<!D::reads_state, error>::type static typename std::enable_if<!D::reads_state, error>::type
convert_apply(D& self, T& x, U& storage, F assign) { convert_apply(D& self, T& x, U& storage, F assign) {
auto e = self.apply(storage); if (auto err = self(storage))
if (e) return err;
return e;
assign(x, storage); assign(x, storage);
return none; return none;
} }
...@@ -583,8 +578,13 @@ private: ...@@ -583,8 +578,13 @@ private:
return *static_cast<Derived*>(this); return *static_cast<Derived*>(this);
} }
// Applies `xs...` to `dref()`.
template <class... Ts>
error apply_derived(Ts&&... xs) {
return dref()(std::forward<Ts>(xs)...);
}
execution_unit* context_; execution_unit* context_;
}; };
} // namespace caf } // namespace caf
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