Make continuable_base non copyable by default

* Actually there is no reason that the call hierarchy is copyable
  when looking at the fact that two types just cause distraction
  and bad usage.
This commit is contained in:
Denis Blank 2018-03-09 08:51:33 +01:00
parent 7a00a5f1c2
commit 86c3815ae0
4 changed files with 12 additions and 36 deletions

View File

@ -157,10 +157,10 @@ public:
/// \cond false /// \cond false
continuable_base(continuable_base&&) = default; continuable_base(continuable_base&&) = default;
continuable_base(continuable_base const&) = default; continuable_base(continuable_base const&) = delete;
continuable_base& operator=(continuable_base&&) = default; continuable_base& operator=(continuable_base&&) = default;
continuable_base& operator=(continuable_base const&) = default; continuable_base& operator=(continuable_base const&) = delete;
/// \endcond /// \endcond
/// The destructor automatically invokes the continuable_base /// The destructor automatically invokes the continuable_base

View File

@ -40,16 +40,9 @@
namespace cti { namespace cti {
// clang-format off // clang-format off
namespace detail { namespace detail {
/// A function which isn't size adjusted and copyable
template<std::size_t Size, typename... Args>
using function_adapter = fu2::function<Args...>;
/// A function which isn't size adjusted and move only /// A function which isn't size adjusted and move only
template<std::size_t, typename... Args> template<std::size_t, typename... Args>
using unique_function_adapter = fu2::unique_function<Args...>; using unique_function_adapter = fu2::unique_function<Args...>;
/// A function which is size adjusted and copyable
template<std::size_t Size, typename... Args>
using function_adjustable = fu2::function_base<true, true, Size,
true, false, Args...>;
/// A function which is size adjusted and move only /// A function which is size adjusted and move only
template<std::size_t Size, typename... Args> template<std::size_t Size, typename... Args>
using unique_function_adjustable = fu2::function_base<true, false, Size, using unique_function_adjustable = fu2::function_base<true, false, Size,
@ -57,13 +50,6 @@ using unique_function_adjustable = fu2::function_base<true, false, Size,
/// We adjust the internal capacity of the outer function wrapper so /// We adjust the internal capacity of the outer function wrapper so
/// we don't have to allocate twice when using `continuable<...>`. /// we don't have to allocate twice when using `continuable<...>`.
template<typename... Args>
using trait_of = continuable_trait<
unique_function_adapter,
function_adjustable,
Args...
>;
template<typename... Args> template<typename... Args>
using unique_trait_of = continuable_trait< using unique_trait_of = continuable_trait<
unique_function_adapter, unique_function_adapter,
@ -72,21 +58,12 @@ using unique_trait_of = continuable_trait<
>; >;
} // namespace detail } // namespace detail
/// Defines a copyable continuation type which uses the
/// function2 backend for type erasure.
///
/// Usable like: `cti::continuable<int, float>`
template <typename... Args>
using continuable = typename detail::trait_of<
Args...
>::continuable;
/// Defines a non-copyable continuation type which uses the /// Defines a non-copyable continuation type which uses the
/// function2 backend for type erasure. /// function2 backend for type erasure.
/// ///
/// Usable like: `unique_continuable<int, float>` /// Usable like: `continuable<int, float>`
template <typename... Args> template <typename... Args>
using unique_continuable = typename detail::unique_trait_of< using continuable = typename detail::unique_trait_of<
Args... Args...
>::continuable; >::continuable;

View File

@ -28,20 +28,20 @@
TYPED_TEST(single_dimension_tests, is_eraseable) { TYPED_TEST(single_dimension_tests, is_eraseable) {
{ {
cti::unique_continuable<int> erasure = cti::continuable<int> erasure =
cti::make_continuable<int>(supplier_of(0xDF)); cti::make_continuable<int>(supplier_of(0xDF));
EXPECT_ASYNC_RESULT(std::move(erasure), 0xDF); EXPECT_ASYNC_RESULT(std::move(erasure), 0xDF);
} }
{ {
cti::unique_continuable<int> erasure = supplier_of(0xDF); cti::continuable<int> erasure = supplier_of(0xDF);
EXPECT_ASYNC_RESULT(std::move(erasure), 0xDF); EXPECT_ASYNC_RESULT(std::move(erasure), 0xDF);
} }
{ {
cti::unique_continuable<int> erasure = this->supply(0xDF); cti::continuable<int> erasure = this->supply(0xDF);
EXPECT_ASYNC_RESULT(std::move(erasure), 0xDF); EXPECT_ASYNC_RESULT(std::move(erasure), 0xDF);
} }
@ -49,8 +49,7 @@ TYPED_TEST(single_dimension_tests, is_eraseable) {
TYPED_TEST(single_dimension_tests, is_callable) { TYPED_TEST(single_dimension_tests, is_callable) {
cti::unique_continuable<int, int> erased = cti::continuable<int, int> erased = [](cti::promise<int, int>&& callback) {
[](cti::promise<int, int>&& callback) {
std::move(callback)(0xDF, 0xDD); std::move(callback)(0xDF, 0xDD);
}; };

View File

@ -166,13 +166,13 @@ using single_types = ::testing::Types<
#if UNIT_TEST_STEP == 0 #if UNIT_TEST_STEP == 0
provide_copyable provide_copyable
// provide_erasure<cti::continuable>, // provide_erasure<cti::continuable>,
// provide_erasure<cti::unique_continuable> // provide_erasure<cti::continuable>
#elif UNIT_TEST_STEP == 1 #elif UNIT_TEST_STEP == 1
// Some instantiations out commented for compilation speed reasons // Some instantiations out commented for compilation speed reasons
// provide_continuation_and_left<provide_copyable>, // provide_continuation_and_left<provide_copyable>,
provide_continuation_and_left<provide_unique> provide_continuation_and_left<provide_unique>
// provide_continuation_and_left<provide_erasure<cti::continuable>>, // provide_continuation_and_left<provide_erasure<cti::continuable>>,
// provide_continuation_and_left<provide_erasure<cti::unique_continuable>>, // provide_continuation_and_left<provide_erasure<cti::continuable>>,
// provide_continuation_and_right<provide_copyable>, // provide_continuation_and_right<provide_copyable>,
// provide_continuation_and_right<provide_unique>, // provide_continuation_and_right<provide_unique>,
// provide_continuation_and_left<provide_erasure<cti::continuable>> // provide_continuation_and_left<provide_erasure<cti::continuable>>