Avoid using SFINAE inside the materializer

This commit is contained in:
Denis Blank 2018-02-28 17:28:41 +01:00
parent 36257780e0
commit 4a5136427b
3 changed files with 26 additions and 24 deletions

View File

@ -115,7 +115,8 @@ using detail::base::is_continuable;
///
/// \since 1.0.0
template <typename Data, typename Annotation>
class continuable_base {
class continuable_base
: detail::composition::materializer<continuable_base<Data, Annotation>> {
/// \cond false
template <typename, typename>
@ -625,28 +626,8 @@ private:
ownership_.release();
}
auto materialize() &&
noexcept(std::is_nothrow_move_constructible<Data>::value) {
assert_acquired();
return materializeImpl(std::move(*this));
}
template <typename OData, typename OAnnotation,
std::enable_if_t<!detail::composition::is_composition_strategy<
OAnnotation>::value>* = nullptr>
static auto
materializeImpl(continuable_base<OData, OAnnotation>&& continuable) {
return std::move(continuable);
}
template <typename OData, typename OAnnotation,
std::enable_if_t<detail::composition::is_composition_strategy<
OAnnotation>::value>* = nullptr>
static auto
materializeImpl(continuable_base<OData, OAnnotation>&& continuable) {
return detail::composition::finalize_composition(std::move(continuable));
}
Data&& consume_data() && {
assert_acquired();
release();
return std::move(data_);
}

View File

@ -262,13 +262,13 @@ struct composition_finalizer<composition_strategy_all_tag> {
};
}
template <typename Composition>
/*template <typename Composition>
static auto finalize_new(Composition&& composition) {
return [composition = std::forward<Composition>(composition)](
auto&& callback) mutable {
// TODO
};
}
}*/
};
} // namespace composition
} // namespace detail

View File

@ -159,6 +159,27 @@ auto finalize_composition(continuable_base<Data, Strategy>&& continuation) {
signature, std::move(ownership));
}
/// A base class from which the continuable may inherit in order to
/// provide a materializer method which will finalize an oustanding strategy.
template <typename Continuable, typename = void>
struct materializer {
protected:
constexpr auto&& materialize() && {
return std::move(*static_cast<Continuable*>(this));
}
};
template <typename Data, typename Strategy>
struct materializer<
continuable_base<Data, Strategy>,
std::enable_if_t<is_composition_strategy<Strategy>::value>> {
protected:
constexpr auto materialize() && {
return finalize_composition(
std::move(*static_cast<continuable_base<Data, Strategy>*>(this)));
}
};
struct prepare_continuables {
util::ownership& ownership_;