Commit e24ad712 authored by Dominik Charousset's avatar Dominik Charousset

Add additional static assertions

parent f0c25cbd
...@@ -38,14 +38,11 @@ namespace caf { ...@@ -38,14 +38,11 @@ namespace caf {
/// @param done Predicate returning `true` when generator is done. /// @param done Predicate returning `true` when generator is done.
/// @param fin Cleanup handler. /// @param fin Cleanup handler.
/// @returns The new `stream_manager`. /// @returns The new `stream_manager`.
template <class Driver, class Init, class Pull, class Done, template <class Driver, class... Ts>
class Finalize = unit_t>
typename Driver::source_ptr_type typename Driver::source_ptr_type
attach_continuous_stream_source(scheduled_actor* self, Init init, Pull pull, attach_continuous_stream_source(scheduled_actor* self, Ts&&... xs) {
Done done, Finalize fin = {}) {
using detail::make_stream_source; using detail::make_stream_source;
auto mgr = make_stream_source<Driver>(self, std::move(init), std::move(pull), auto mgr = make_stream_source<Driver>(self, std::forward<Ts>(xs)...);
std::move(done), std::move(fin));
mgr->continuous(true); mgr->continuous(true);
return mgr; return mgr;
} }
...@@ -60,12 +57,23 @@ attach_continuous_stream_source(scheduled_actor* self, Init init, Pull pull, ...@@ -60,12 +57,23 @@ attach_continuous_stream_source(scheduled_actor* self, Init init, Pull pull,
/// @param fin Cleanup handler. /// @param fin Cleanup handler.
/// @returns The new `stream_manager`. /// @returns The new `stream_manager`.
template <class Init, class Pull, class Done, class Finalize = unit_t, template <class Init, class Pull, class Done, class Finalize = unit_t,
class Trait = stream_source_trait_t<Pull>,
class DownstreamManager = broadcast_downstream_manager< class DownstreamManager = broadcast_downstream_manager<
typename stream_source_trait_t<Pull>::output>> typename Trait::output>>
stream_source_ptr<DownstreamManager> stream_source_ptr<DownstreamManager>
attach_continuous_stream_source(scheduled_actor* self, Init init, Pull pull, attach_continuous_stream_source(scheduled_actor* self, Init init, Pull pull,
Done done, Finalize fin = {}, Done done, Finalize fin = {},
policy::arg<DownstreamManager> = {}) { policy::arg<DownstreamManager> = {}) {
using state_type = typename Trait::state;
static_assert(std::is_same<
void(state_type&),
typename detail::get_callable_trait<Init>::fun_sig>::value,
"Expected signature `void (State&)` for init function");
static_assert(std::is_same<
bool(const state_type&),
typename detail::get_callable_trait<Done>::fun_sig>::value,
"Expected signature `bool (const State&)` "
"for done predicate function");
using driver = detail::stream_source_driver_impl<DownstreamManager, Pull, using driver = detail::stream_source_driver_impl<DownstreamManager, Pull,
Done, Finalize>; Done, Finalize>;
return attach_continuous_stream_source<driver>(self, std::move(init), return attach_continuous_stream_source<driver>(self, std::move(init),
......
...@@ -45,14 +45,13 @@ namespace caf { ...@@ -45,14 +45,13 @@ namespace caf {
/// @param done Predicate returning `true` when generator is done. /// @param done Predicate returning `true` when generator is done.
/// @param fin Optional cleanup handler. /// @param fin Optional cleanup handler.
/// @returns The allocated `stream_manager` and the output slot. /// @returns The allocated `stream_manager` and the output slot.
template <class Driver, class... Ts, class Init, class Pull, class Done, template <class Driver, class... Ts, class... CtorArgs>
class Finalize = unit_t>
make_source_result_t<typename Driver::downstream_manager_type, Ts...> make_source_result_t<typename Driver::downstream_manager_type, Ts...>
attach_stream_source(scheduled_actor* self, std::tuple<Ts...> xs, Init init, attach_stream_source(scheduled_actor* self, std::tuple<Ts...> xs,
Pull pull, Done done, Finalize fin = {}) { CtorArgs&&... ctor_args) {
using namespace detail; using namespace detail;
auto mgr = make_stream_source<Driver>(self, std::move(init), std::move(pull), auto mgr = make_stream_source<Driver>(self,
std::move(done), std::move(fin)); std::forward<CtorArgs>(ctor_args)...);
auto slot = mgr->add_outbound_path(std::move(xs)); auto slot = mgr->add_outbound_path(std::move(xs));
return {slot, std::move(mgr)}; return {slot, std::move(mgr)};
} }
...@@ -67,13 +66,23 @@ attach_stream_source(scheduled_actor* self, std::tuple<Ts...> xs, Init init, ...@@ -67,13 +66,23 @@ attach_stream_source(scheduled_actor* self, std::tuple<Ts...> xs, Init init,
/// @param fin Cleanup handler. /// @param fin Cleanup handler.
/// @returns The allocated `stream_manager` and the output slot. /// @returns The allocated `stream_manager` and the output slot.
template <class... Ts, class Init, class Pull, class Done, template <class... Ts, class Init, class Pull, class Done,
class Finalize = unit_t, class Finalize = unit_t, class Trait = stream_source_trait_t<Pull>,
class DownstreamManager = broadcast_downstream_manager< class DownstreamManager = broadcast_downstream_manager<
typename stream_source_trait_t<Pull>::output>> typename Trait::output>>
make_source_result_t<DownstreamManager, Ts...> make_source_result_t<DownstreamManager, Ts...>
attach_stream_source(scheduled_actor* self, std::tuple<Ts...> xs, Init init, attach_stream_source(scheduled_actor* self, std::tuple<Ts...> xs, Init init,
Pull pull, Done done, Finalize fin = {}, Pull pull, Done done, Finalize fin = {},
policy::arg<DownstreamManager> = {}) { policy::arg<DownstreamManager> = {}) {
using state_type = typename Trait::state;
static_assert(std::is_same<
void(state_type&),
typename detail::get_callable_trait<Init>::fun_sig>::value,
"Expected signature `void (State&)` for init function");
static_assert(std::is_same<
bool(const state_type&),
typename detail::get_callable_trait<Done>::fun_sig>::value,
"Expected signature `bool (const State&)` "
"for done predicate function");
using driver = detail::stream_source_driver_impl<DownstreamManager, Pull, using driver = detail::stream_source_driver_impl<DownstreamManager, Pull,
Done, Finalize>; Done, Finalize>;
return attach_stream_source<driver>(self, std::move(xs), std::move(init), return attach_stream_source<driver>(self, std::move(xs), std::move(init),
......
...@@ -99,7 +99,7 @@ public: ...@@ -99,7 +99,7 @@ public:
for (size_t i = 0; i < n; ++i) for (size_t i = 0; i < n; ++i)
out.push(counter++); out.push(counter++);
}, },
[](const int& counter) { return counter < 100; }); [](const size_t& counter) { return counter < 100; });
} }
}; };
......
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