Rework the alias trait

This commit is contained in:
Denis Blank 2017-03-03 17:10:29 +01:00
parent 54de52cb4b
commit 8d851d6d42
5 changed files with 86 additions and 44 deletions

View File

@ -5,7 +5,7 @@
\_,(_)| | | || ||_|(_||_)|(/_
https://github.com/Naios/continuable
v0.8.0
Copyright(c) 2015 - 2017 Denis Blank <denis.blank at outlook dot com>
@ -1997,14 +1997,31 @@ auto seq_of(Continuables&&... continuables) {
std::forward<Continuables>(continuables)...);
}
/// Trait to retrieve a continuable_base type with a given type-erasure backend.
///
/// Every object may me used as type-erasure backend as long as the
/// requirements of a `std::function` like wrapper are satisfied.
///
/// \tparam CallbackWrapper The type which is used to erase the callback.
///
/// \tparam ContinuationWrapper The type which is used to erase the
/// continuation data.
///
/// \tparam Args The current signature of the continuable.
template <template <typename> class CallbackWrapper,
template <typename> class ContinuationWrapper, typename... Args>
using continuable_erasure_of_t =
CallbackWrapper<void(ContinuationWrapper<void(Args...)>)>;
struct continuable_trait {
/// The callback type which is passed to continuations
using callback = CallbackWrapper<void(Args...)>;
template <typename Erasure, typename... Args>
using continuable_of_t =
continuable_base<Erasure, detail::signature_hint_tag<Args...>>;
/// The continuation type which is used to erase the internal data.
using continuation =
ContinuationWrapper<void(CallbackWrapper<void(Args...)>)>;
/// The continuable type for the given parameters.
using continuable =
continuable_base<continuation, detail::signature_hint_tag<Args...>>;
};
/// \cond false
} // end inline namespace abi_...

View File

@ -5,7 +5,7 @@
\_,(_)| | | || ||_|(_||_)|(/_
https://github.com/Naios/continuable
v0.8.0
Copyright(c) 2015 - 2017 Denis Blank <denis.blank at outlook dot com>

View File

@ -5,7 +5,7 @@
\_,(_)| | | || ||_|(_||_)|(/_
https://github.com/Naios/continuable
v0.8.0
Copyright(c) 2015 - 2017 Denis Blank <denis.blank at outlook dot com>
@ -31,30 +31,69 @@
#ifndef CONTINUABLE_HPP_INCLUDED__
#define CONTINUABLE_HPP_INCLUDED__
#include <type_traits>
#include "continuable/continuable-base.hpp"
#include "function2/function2.hpp"
namespace cti {
// clang-format off
/// \cond false
inline namespace abi_v1 {
/// \endcond
namespace detail {
template<typename... Args>
using trait_of = continuable_trait<
fu2::function,
fu2::function,
Args...
>;
template<typename... Args>
using unique_trait_of = continuable_trait<
fu2::unique_function,
fu2::unique_function,
Args...
>;
} // end namespace detail
/// Defines a copyable continuation type which uses the
/// function2 backend for type erasure.
///
/// Usable like: continuable<int, float>
/// Usable like: `cti::continuable<int, float>`
template <typename... Args>
using continuable = continuable_of_t<
continuable_erasure_of_t<fu2::function, fu2::unique_function, Args...>,
Args...>;
using continuable = typename detail::trait_of<
Args...
>::continuable;
/// Defines a copyable callback type which uses the
/// function2 backend for the continuable type erasure.
///
/// Usable like: `callback<int, float>`
template <typename... Args>
using callback = typename detail::trait_of<
Args...
>::callback;
/// Defines a non-copyable continuation type which uses the
/// function2 backend for type erasure.
///
/// Usable like: unique_continuable<int, float>
/// Usable like: `unique_continuable<int, float>`
template <typename... Args>
using unique_continuable =
continuable_of_t<continuable_erasure_of_t<fu2::unique_function,
fu2::unique_function, Args...>,
Args...>;
using unique_continuable = typename detail::unique_trait_of<
Args...
>::continuable;
/// Defines a non-copyable callback type which uses the
/// function2 backend for the continuable type erasure.
///
/// Usable like: `unique_callback<int, float>`
template <typename... Args>
using unique_callback = typename detail::unique_trait_of<
Args...
>::callback;
/// \cond false
} // end inline namespace abi_...
/// \endcond
// clang-format on
} // end namespace cti
#endif // CONTINUABLE_HPP_INCLUDED__

View File

@ -22,31 +22,6 @@
#include "continuable/continuable.hpp"
using namespace cti::detail;
using namespace cti::detail::util;
/// Predicate to check whether an object is callable with the given arguments
template <typename... Args> auto is_invokable_with(identity<Args...>) {
return [](auto&& callable) {
(void)callable;
return is_invokable_t<decltype(callable), identity<Args...>>{};
};
}
template <typename... Right>
auto reverse(identity<>, identity<Right...> right = identity<>{}) {
return right;
}
template <typename First, typename... Left, typename... Right>
auto reverse(identity<First, Left...>, identity<Right...> = identity<>{}) {
return reverse(identity<Left...>{}, identity<First, Right...>{});
}
int main(int, char**) {
auto cb = [](int, int) { return 0; };
partial_invoke(cb, 0, 0, 0, 0, 0, 0, 0);
return 0;
}

View File

@ -38,3 +38,14 @@ TYPED_TEST(single_dimension_tests, is_eraseable) {
EXPECT_ASYNC_RESULT(std::move(erasure), 0xDF);
}
}
TYPED_TEST(single_dimension_tests, is_callable) {
cti::unique_continuable<int, int> erased =
[](cti::unique_callback<int, int>&& callback) {
std::move(callback)(0xDF, 0xDD);
};
EXPECT_ASYNC_RESULT(std::move(erased), 0xDF, 0xDD);
}