Unverified Commit 04ba5ea6 authored by Dominik Charousset's avatar Dominik Charousset Committed by GitHub

Merge pull request #868

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