MCPcopy Create free account
hub / github.com/NVIDIA/stdexec / __associate_data

Class __associate_data

include/stdexec/__detail/__associate.hpp:48–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46 {
47 template <scope_token _Token, sender _Sender>
48 struct __associate_data
49 {
50 using __wrap_result_t = decltype(__declval<_Token&>().wrap(__declval<_Sender>()));
51 using __wrap_sender_t = std::remove_cvref_t<__wrap_result_t>;
52
53 using __assoc_t = decltype(__declval<_Token&>().try_associate());
54
55 // NOTE: the spec says the deleter should be a lambda like so:
56 //
57 // using __sender_ref = std::unique_ptr<
58 // __wrap_sender_t,
59 // // this decltype(<lamnda>) breaks things
60 // decltype([](auto* p) noexcept { std::destroy_at(p); })
61 // >;
62 //
63 // but the above code ICEs gcc 11 and 12 (and maybe MSVC)
64 // so we declare a named callable
65 struct __deleter
66 {
67 constexpr void operator()(__wrap_sender_t* __p) const noexcept
68 {
69 std::destroy_at(__p);
70 }
71 };
72
73 using __sender_ref = std::unique_ptr<__wrap_sender_t, __deleter>;
74
75 // BUGBUG: should the spec require __token to be declared as a const _Token, or should this be
76 // changed to declare __token as a mutable _Token?
77 explicit __associate_data(_Token const __token, _Sender&& __sndr)
78 noexcept(__nothrow_constructible_from<__wrap_sender_t, __wrap_result_t>
79 && noexcept(__token.wrap(static_cast<_Sender&&>(__sndr)))
80 && noexcept(__token.try_associate()))
81 : __sndr_(__token.wrap(static_cast<_Sender&&>(__sndr)))
82 , __assoc_(
83 [&]
84 {
85 __sender_ref guard{std::addressof(__sndr_)};
86
87 auto assoc = __token.try_associate();
88
89 if (assoc)
90 {
91 (void) guard.release();
92 }
93
94 return assoc;
95 }())
96 {}
97
98 __associate_data(__associate_data const & __other)
99 noexcept(__nothrow_copy_constructible<__wrap_sender_t>
100 && noexcept(__other.__assoc_.try_associate()))
101 requires __std::copy_constructible<__wrap_sender_t>
102 : __assoc_(__other.__assoc_.try_associate())
103 {
104 if (__assoc_)
105 {

Callers 1

operator()Method · 0.85

Calls 2

wrapMethod · 0.45
try_associateMethod · 0.45

Tested by

no test coverage detected