Skip to content

Commit

Permalink
added connect_result_t and work towards basic_operation
Browse files Browse the repository at this point in the history
  • Loading branch information
dietmarkuehl committed Aug 29, 2024
1 parent 8f0697d commit 759b4f2
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 1 deletion.
34 changes: 34 additions & 0 deletions include/beman/execution26/detail/basic_operation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// include/beman/execution26/detail/basic_operation.hpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_BASIC_OPERATION
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_BASIC_OPERATION

#include <beman/execution26/detail/basic_state.hpp>
#include <beman/execution26/detail/state_type.hpp>
#include <beman/execution26/detail/valid_specialization.hpp>
#include <utility>

// ----------------------------------------------------------------------------

namespace beman::execution26::detail
{
template <typename Sender, typename Receiver>
requires ::beman::execution26::detail::valid_specialization<
::beman::execution26::detail::state_type, Sender, Receiver
>
struct basic_operation
: ::beman::execution26::detail::basic_state<Sender, Receiver>
{
basic_operation(Sender&& sender, Receiver&& receiver) noexcept(true/*-dk:TODO*/)
: ::beman::execution26::detail::basic_state<Sender, Receiver>(
::std::forward<Sender>(sender), ::std::move(receiver)
)
{
}
};
}

// ----------------------------------------------------------------------------

#endif
2 changes: 1 addition & 1 deletion include/beman/execution26/detail/connect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace beman::execution26
}
else
{
static_assert(::std::same_as<int, Sender>);
static_assert(::std::same_as<int, Sender>, "can't connect the sender");
}
}
};
Expand Down
27 changes: 27 additions & 0 deletions include/beman/execution26/detail/connect_all.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// include/beman/execution26/detail/connect_all.hpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_CONNECT_ALL
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_CONNECT_ALL

// ----------------------------------------------------------------------------

namespace beman::execution26::detail
{
struct connect_all_t
{
template <typename Sender, typename Receiver>
struct state
{
};
auto operator()(auto&&...) const noexcept(true/*-dk:TODO*/)
{
return 0;
}
};
inline constexpr connect_all_t connect_all{};
}

// ----------------------------------------------------------------------------

#endif
22 changes: 22 additions & 0 deletions include/beman/execution26/detail/connect_result_t.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// include/beman/execution26/detail/connect_result_t.hpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_CONNECT_RESULT
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_CONNECT_RESULT

#include <beman/execution26/detail/connect.hpp>
#include <type_traits>

// ----------------------------------------------------------------------------

namespace beman::execution26
{
template <typename Sender, typename Receiver>
using connect_result_t
= decltype(::beman::execution26::connect(::std::declval<Sender>(),
::std::declval<Receiver>()));
}

// ----------------------------------------------------------------------------

#endif
44 changes: 44 additions & 0 deletions src/beman/execution26/tests/exec-snd-expos.pass.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// src/beman/execution26/tests/exe-snd-expos.pass.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution26/detail/basic_operation.hpp>
#include <beman/execution26/detail/connect_all.hpp>
#include <beman/execution26/detail/fwd_env.hpp>
#include <beman/execution26/detail/make_env.hpp>
#include <beman/execution26/detail/join_env.hpp>
Expand Down Expand Up @@ -88,6 +90,23 @@ namespace
auto operator== (scheduler const&) const -> bool = default;
};

struct tag {};

struct sender0
{
using sender_concept = test_std::sender_t;
tag t{};
int data{};
};

struct receiver
{
using receiver_concept = test_std::receiver_t;
auto set_value(auto&&...) noexcept -> void {}
auto set_error(auto&&) noexcept -> void {}
auto set_stopped() noexcept -> void {}
};

// ------------------------------------------------------------------------

template <bool Expect, typename Query>
Expand Down Expand Up @@ -746,6 +765,29 @@ namespace
static_assert(not test_detail::completion_tag<int>);
static_assert(not test_detail::completion_tag<no_completion>);
}

auto test_connect_all() -> void
{
{
sender0 s{};
test_detail::basic_state state{std::move(s), receiver{}};
auto product{test_detail::connect_all(&state, std::move(s), std::index_sequence<>{})};
(void)product;
}
{
sender0 const s{};
test_detail::basic_state state{std::move(s), receiver{}};
auto product{test_detail::connect_all(&state, s, std::index_sequence<>{})};
(void)product;
}
}

auto test_basic_operation() -> void
{
test_detail::basic_operation op{sender0{}, receiver{}};
(void)op;
//-dk:TODO test basic_operation
}
}

auto main() -> int
Expand All @@ -767,4 +809,6 @@ auto main() -> int
test_env_type();
test_basic_receiver<int>();
test_completion_tag();
test_connect_all();
test_basic_operation();
}
42 changes: 42 additions & 0 deletions src/beman/execution26/tests/execution-syn.pass.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// src/beman/execution26/tests/execution-syn.pass.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution26/detail/connect_result_t.hpp>
#include <beman/execution26/detail/connect.hpp>
#include <beman/execution26/detail/single_sender.hpp>
#include <beman/execution26/detail/single_sender_value_type.hpp>
#include <beman/execution26/detail/type_list.hpp>
Expand Down Expand Up @@ -320,6 +322,45 @@ namespace
static_assert(test_detail::single_sender<multi_type_sender, test_std::empty_env>);
static_assert(not test_detail::single_sender<no_value_sender, test_std::empty_env>);
}

struct connect_sender
{
using sender_concept = test_std::sender_t;
template <typename Receiver>
struct state
{
using operation_state_concept = test_std::operation_state_t;
auto start() noexcept -> void {}
};
struct tag {};

tag t{};
int d{};

template <test_std::receiver Receiver>
auto connect(Receiver&&) const noexcept -> state<Receiver>
{
return {};
}
};

auto test_conect_result_t() -> void
{
struct receiver
{
using receiver_concept = test_std::receiver_t;
};

static_assert(test_std::sender<connect_sender>);
static_assert(test_std::receiver<receiver>);
static_assert(requires{ connect_sender{}.connect(receiver{}); });

auto op{test_std::connect(connect_sender{}, receiver{})};
static_assert(std::same_as<
decltype(op),
test_std::connect_result_t<connect_sender, receiver>
>);
}
}

auto main() -> int
Expand All @@ -332,4 +373,5 @@ auto main() -> int
test_type_list();
test_single_sender_value_type();
test_single_sender();
test_conect_result_t();
}

0 comments on commit 759b4f2

Please sign in to comment.