proxygen
folly::pushmi::any_receiver< E, VN > Class Template Reference

#include <forwards.h>

Classes

union  data
 
struct  vtable
 

Public Types

using properties = property_set< is_receiver<>>
 

Public Member Functions

 any_receiver ()=default
 
 any_receiver (any_receiver &&that) noexcept
 
requires ReceiveValue< wrapped_t< Wrapped >, VN... > &&ReceiveError< Wrapped, Eany_receiver (Wrapped obj) noexcept(insitu< Wrapped >())
 
 ~any_receiver ()
 
any_receiveroperator= (any_receiver &&that) noexcept
 
void value (VN &&...vn)
 
void error (E e) noexcept
 
void done ()
 

Private Types

template<class T , class U = std::decay_t<T>>
using wrapped_t = std::enable_if_t<!std::is_same< U, any_receiver >::value, U >
 

Private Member Functions

template<class Wrapped >
 any_receiver (Wrapped obj, std::false_type)
 
template<class Wrapped >
 any_receiver (Wrapped obj, std::true_type) noexcept
 

Static Private Member Functions

template<class Wrapped >
static constexpr bool insitu () noexcept
 
template<class Wrapped >
static void check ()
 

Private Attributes

bool done_ = false
 
union folly::pushmi::any_receiver::data data_
 
vtable const * vptr_ = &noop_
 

Static Private Attributes

static constexpr vtable const noop_ {}
 

Detailed Description

template<class E, class... VN>
class folly::pushmi::any_receiver< E, VN >

Definition at line 101 of file forwards.h.

Member Typedef Documentation

template<class E, class... VN>
using folly::pushmi::any_receiver< E, VN >::properties = property_set<is_receiver<>>

Definition at line 118 of file receiver.h.

template<class E, class... VN>
template<class T , class U = std::decay_t<T>>
using folly::pushmi::any_receiver< E, VN >::wrapped_t = std::enable_if_t<!std::is_same<U, any_receiver>::value, U>
private

Definition at line 58 of file receiver.h.

Constructor & Destructor Documentation

template<class E, class... VN>
template<class Wrapped >
folly::pushmi::any_receiver< E, VN >::any_receiver ( Wrapped  obj,
std::false_type   
)
inlineprivate

Definition at line 72 of file receiver.h.

72  : any_receiver() {
73  struct s {
74  static void op(data& src, data* dst) {
75  if (dst)
76  dst->pobj_ = std::exchange(src.pobj_, nullptr);
77  delete static_cast<Wrapped const*>(src.pobj_);
78  }
79  static void done(data& src) {
80  set_done(*static_cast<Wrapped*>(src.pobj_));
81  }
82  static void error(data& src, E e) noexcept {
83  set_error(*static_cast<Wrapped*>(src.pobj_), std::move(e));
84  }
85  static void value(data& src, VN... vn) {
86  set_value(*static_cast<Wrapped*>(src.pobj_), std::move(vn)...);
87  }
88  };
89  static const vtable vtbl{s::op, s::done, s::error, s::value};
90  data_.pobj_ = new Wrapped(std::move(obj));
91  vptr_ = &vtbl;
92  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
union folly::pushmi::any_receiver::data data_
PUSHMI_INLINE_VAR constexpr __adl::set_error_fn set_error
void error(E e) noexcept
Definition: receiver.h:147
vtable const * vptr_
Definition: receiver.h:56
requires E e noexcept(noexcept(s.error(std::move(e))))
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static const char *const value
Definition: Conv.cpp:50
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
static set< string > s
const
Definition: upload.py:398
void value(VN &&...vn)
Definition: receiver.h:141
PUSHMI_INLINE_VAR constexpr __adl::set_done_fn set_done
template<class E, class... VN>
template<class Wrapped >
folly::pushmi::any_receiver< E, VN >::any_receiver ( Wrapped  obj,
std::true_type   
)
inlineprivatenoexcept

Definition at line 94 of file receiver.h.

94  : any_receiver() {
95  struct s {
96  static void op(data& src, data* dst) {
97  if (dst)
98  new (dst->buffer_)
99  Wrapped(std::move(*static_cast<Wrapped*>((void*)src.buffer_)));
100  static_cast<Wrapped const*>((void*)src.buffer_)->~Wrapped();
101  }
102  static void done(data& src) {
103  set_done(*static_cast<Wrapped*>((void*)src.buffer_));
104  }
105  static void error(data& src, E e) noexcept {
106  set_error(*static_cast<Wrapped*>((void*)src.buffer_), std::move(e));
107  }
108  static void value(data& src, VN... vn) {
109  set_value(*static_cast<Wrapped*>((void*)src.buffer_), std::move(vn)...);
110  }
111  };
112  static const vtable vtbl{s::op, s::done, s::error, s::value};
113  new ((void*)data_.buffer_) Wrapped(std::move(obj));
114  vptr_ = &vtbl;
115  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
union folly::pushmi::any_receiver::data data_
PUSHMI_INLINE_VAR constexpr __adl::set_error_fn set_error
void error(E e) noexcept
Definition: receiver.h:147
vtable const * vptr_
Definition: receiver.h:56
requires E e noexcept(noexcept(s.error(std::move(e))))
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static const char *const value
Definition: Conv.cpp:50
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
static set< string > s
const
Definition: upload.py:398
char buffer_[sizeof(std::promise< int >)]
Definition: receiver.h:36
void value(VN &&...vn)
Definition: receiver.h:141
PUSHMI_INLINE_VAR constexpr __adl::set_done_fn set_done
template<class E, class... VN>
folly::pushmi::any_receiver< E, VN >::any_receiver ( any_receiver< E, VN > &&  that)
inlinenoexcept

Definition at line 121 of file receiver.h.

121  : any_receiver() {
122  that.vptr_->op_(that.data_, &data_);
123  std::swap(that.vptr_, vptr_);
124  }
union folly::pushmi::any_receiver::data data_
vtable const * vptr_
Definition: receiver.h:56
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414
template<class E, class... VN>
requires ReceiveValue<wrapped_t<Wrapped>, VN...>&& ReceiveError< Wrapped, E> folly::pushmi::any_receiver< E, VN >::any_receiver ( Wrapped  obj)
inlineexplicitnoexcept

Definition at line 129 of file receiver.h.

130  : any_receiver{std::move(obj), bool_<insitu<Wrapped>()>{}} {
131  check<Wrapped>();
132  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class E, class... VN>
folly::pushmi::any_receiver< E, VN >::~any_receiver ( )
inline

Definition at line 133 of file receiver.h.

Referenced by folly::pushmi::any_receiver< E, folly::pushmi::any_executor_ref< E > >::operator=().

133  {
134  vptr_->op_(data_, nullptr);
135  }
union folly::pushmi::any_receiver::data data_
vtable const * vptr_
Definition: receiver.h:56
void(* op_)(data &, data *)
Definition: receiver.h:50

Member Function Documentation

template<class E, class... VN>
template<class Wrapped >
static void folly::pushmi::any_receiver< E, VN >::check ( )
inlinestaticprivate

Definition at line 60 of file receiver.h.

60  {
61  static_assert(
62  ReceiveValue<Wrapped, VN...>,
63  "Wrapped receiver must support values of type VN...");
64  static_assert(
65  ReceiveError<Wrapped, std::exception_ptr>,
66  "Wrapped receiver must support std::exception_ptr and be noexcept");
67  static_assert(
68  NothrowInvocable<decltype(::folly::pushmi::set_error), Wrapped, E>,
69  "Wrapped receiver must support E and be noexcept");
70  }
PUSHMI_INLINE_VAR constexpr __adl::set_error_fn set_error
template<class E, class... VN>
void folly::pushmi::any_receiver< E, VN >::done ( )
inline

Definition at line 153 of file receiver.h.

Referenced by folly::pushmi::any_receiver< E, folly::pushmi::any_executor_ref< E > >::any_receiver().

153  {
154  if (!done_) {
155  done_ = true;
156  vptr_->done_(data_);
157  }
158  }
union folly::pushmi::any_receiver::data data_
vtable const * vptr_
Definition: receiver.h:56
template<class E, class... VN>
void folly::pushmi::any_receiver< E, VN >::error ( E  e)
inlinenoexcept

Definition at line 147 of file receiver.h.

Referenced by folly::pushmi::any_receiver< E, folly::pushmi::any_executor_ref< E > >::any_receiver().

147  {
148  if (!done_) {
149  done_ = true;
150  vptr_->error_(data_, std::move(e));
151  }
152  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
union folly::pushmi::any_receiver::data data_
vtable const * vptr_
Definition: receiver.h:56
void(* error_)(data &, E) noexcept
Definition: receiver.h:52
template<class E, class... VN>
template<class Wrapped >
static constexpr bool folly::pushmi::any_receiver< E, VN >::insitu ( )
inlinestaticprivatenoexcept

Definition at line 39 of file receiver.h.

39  {
40  return sizeof(Wrapped) <= sizeof(data::buffer_) &&
42  }
static const char *const value
Definition: Conv.cpp:50
char buffer_[sizeof(std::promise< int >)]
Definition: receiver.h:36
template<class E, class... VN>
any_receiver& folly::pushmi::any_receiver< E, VN >::operator= ( any_receiver< E, VN > &&  that)
inlinenoexcept

Definition at line 136 of file receiver.h.

136  {
137  this->~any_receiver();
138  new ((void*)this) any_receiver(std::move(that));
139  return *this;
140  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class E, class... VN>
void folly::pushmi::any_receiver< E, VN >::value ( VN &&...  vn)
inline

Definition at line 141 of file receiver.h.

Referenced by folly::pushmi::any_receiver< E, folly::pushmi::any_executor_ref< E > >::any_receiver().

141  {
142  if (!done_) {
143  // done_ = true;
144  vptr_->value_(data_, (VN &&) vn...);
145  }
146  }
union folly::pushmi::any_receiver::data data_
vtable const * vptr_
Definition: receiver.h:56
void(* value_)(data &, VN...)
Definition: receiver.h:53

Member Data Documentation

template<class E, class... VN>
bool folly::pushmi::any_receiver< E, VN >::done_ = false
private
template<class E, class... VN>
constexpr any_receiver< E, VN... >::vtable const folly::pushmi::any_receiver< E, VN >::noop_ {}
staticprivate
template<class E, class... VN>
vtable const* folly::pushmi::any_receiver< E, VN >::vptr_ = &noop_
private

The documentation for this class was generated from the following files: