220 #include <functional> 223 #include <type_traits> 234 template <
typename FunctionType>
237 template <
typename ReturnType,
typename...
Args>
241 #if FOLLY_HAVE_NOEXCEPT_FUNCTION_TYPE 242 template <
typename ReturnType,
typename...
Args>
258 template <
typename Fun,
typename = Fun*>
261 std::is_nothrow_move_constructible<Fun>>;
265 template <
typename T>
267 template <
typename T>
270 template <
typename T>
276 template <
typename T>
280 template <
typename T>
285 template <
typename F,
typename...
Args>
291 typename =
typename std::enable_if<
295 template <
typename FunctionType>
298 template <
typename ReturnType,
typename...
Args>
306 template <
typename F>
310 template <
typename Fun>
312 return static_cast<ReturnType
>((*
static_cast<Fun*
>(
313 static_cast<void*
>(&p.
tiny)))(static_cast<Args&&>(args)...));
316 template <
typename Fun>
318 return static_cast<ReturnType
>(
319 (*
static_cast<Fun*
>(p.
big))(
static_cast<Args&&
>(args)...));
323 throw std::bad_function_call();
328 return fn.
call_(fn.data_, static_cast<Args&&>(args)...);
332 std::shared_ptr<Function<NonConstSignature>>
sp_;
338 return (*sp_)(
static_cast<Args&&
>(args)...);
343 template <
typename ReturnType,
typename...
Args>
351 template <
typename F>
356 template <
typename Fun>
358 return static_cast<ReturnType
>((*
static_cast<const Fun*
>(
359 static_cast<void*
>(&p.
tiny)))(static_cast<Args&&>(args)...));
362 template <
typename Fun>
364 return static_cast<ReturnType
>(
365 (*
static_cast<const Fun*
>(p.
big))(
static_cast<Args&&
>(args)...));
369 throw std::bad_function_call();
374 return fn.
call_(fn.data_, static_cast<Args&&>(args)...);
378 std::shared_ptr<Function<ConstSignature>>
sp_;
384 return (*sp_)(
static_cast<Args&&
>(args)...);
389 #if FOLLY_HAVE_NOEXCEPT_FUNCTION_TYPE 390 template <
typename ReturnType,
typename...
Args>
398 template <
typename F>
402 template <
typename Fun>
403 static ReturnType callSmall(
Data& p, Args&&... args) noexcept {
404 return static_cast<ReturnType
>((*
static_cast<Fun*
>(
405 static_cast<void*
>(&p.
tiny)))(static_cast<Args&&>(args)...));
408 template <
typename Fun>
409 static ReturnType callBig(
Data& p, Args&&... args) noexcept {
410 return static_cast<ReturnType
>(
411 (*
static_cast<Fun*
>(p.
big))(
static_cast<Args&&
>(args)...));
414 static ReturnType uninitCall(
Data&, Args&&...) noexcept {
415 terminate_with<std::bad_function_call>();
418 ReturnType operator()(Args... args) noexcept {
420 return fn.
call_(fn.data_, static_cast<Args&&>(args)...);
424 std::shared_ptr<Function<NonConstSignature>> sp_;
429 ReturnType operator()(Args&&... args)
const {
430 return (*sp_)(
static_cast<Args&&
>(args)...);
435 template <
typename ReturnType,
typename... Args>
443 template <
typename F>
448 template <
typename Fun>
449 static ReturnType callSmall(
Data& p, Args&&... args) noexcept {
450 return static_cast<ReturnType
>((*
static_cast<const Fun*
>(
451 static_cast<void*
>(&p.
tiny)))(static_cast<Args&&>(args)...));
454 template <
typename Fun>
455 static ReturnType callBig(
Data& p, Args&&... args) noexcept {
456 return static_cast<ReturnType
>(
457 (*
static_cast<const Fun*
>(p.
big))(
static_cast<Args&&
>(args)...));
460 static ReturnType uninitCall(
Data&, Args&&...) noexcept {
461 throw std::bad_function_call();
464 ReturnType operator()(Args... args)
const noexcept {
466 return fn.
call_(fn.data_, static_cast<Args&&>(args)...);
470 std::shared_ptr<Function<ConstSignature>> sp_;
475 ReturnType operator()(Args&&... args)
const {
476 return (*sp_)(
static_cast<Args&&
>(args)...);
482 template <
typename Fun>
486 ::new (static_cast<void*>(&dst->
tiny))
487 Fun(
std::move(*static_cast<Fun*>(static_cast<void*>(&src->
tiny))));
490 static_cast<Fun*
>(
static_cast<void*
>(&src->
tiny))->~Fun();
498 template <
typename Fun>
506 delete static_cast<Fun*
>(src->
big);
517 template <
typename FunctionType>
529 using Call =
typename Traits::Call;
532 template <
typename Fun>
540 Call call_{&Traits::uninitCall};
543 bool exec(
Op o, Data* src, Data* dst)
const {
544 return exec_ && exec_(o, src, dst);
552 template <typename Fun>
556 ::new (static_cast<void*>(&
data_.tiny)) FunT(static_cast<Fun&&>(
fun));
557 call_ = &Traits::template callSmall<FunT>;
558 exec_ = &detail::function::execSmall<FunT>;
562 template <
typename Fun>
565 data_.big =
new FunT(static_cast<Fun&&>(
fun));
566 call_ = &Traits::template callBig<FunT>;
567 exec_ = &detail::function::execBig<FunT>;
570 template <
typename Signature>
575 : call_(that.call_), exec_(that.exec_) {
576 that.call_ = &Traits::uninitCall;
577 that.exec_ =
nullptr;
592 template <
class ReturnType,
class...
Args>
594 : Function([blockCopy = (ReturnType(^)(
Args...))[objCBlock
copy]](
595 Args... args) { return blockCopy(args...); }){};
601 Function(Function&& that) noexcept : call_(that.call_), exec_(that.exec_) {
603 that.call_ = &Traits::uninitCall;
604 that.exec_ =
nullptr;
636 typename =
typename Traits::template ResultOf<Fun>>
652 typename =
typename Traits::template ResultOf<Function<Signature>>>
666 typename = decltype(Function(std::mem_fn((Member Class::*)0)))>
669 *
this = std::mem_fn(
ptr);
677 Function& operator=(
const Function&) =
delete;
681 template <
class ReturnType,
class...
Args>
682 Function& operator=(ReturnType (^objCBlock)(
Args... args)) {
683 (*this) = [blockCopy = (ReturnType(^)(
Args...))[objCBlock
copy]](
684 Args... args) {
return blockCopy(args...); };
719 template <
typename Fun,
typename = decltype(Function(std::declval<Fun>()))>
721 noexcept( Function(std::declval<Fun>()))) {
723 if (
noexcept( Function(std::declval<Fun>()))) {
740 typename =
typename Traits::template ResultOf<Function<Signature>>>
742 noexcept(Function(
std::
move(that)))) {
743 return (*
this = Function(
std::move(that)));
750 return (*
this = Function());
757 template <
typename Member,
typename Class>
761 -> decltype(
operator=(std::mem_fn(
ptr))) {
762 return ptr ? (*
this = std::mem_fn(
ptr)) : (*
this = Function());
768 using Traits::operator();
773 void swap(Function& that) noexcept {
781 explicit operator bool()
const noexcept {
782 return exec_ !=
nullptr;
792 return exec(
Op::HEAP,
nullptr,
nullptr);
795 using typename Traits::SharedProxy;
815 template <
typename FunctionType>
820 template <
typename FunctionType>
825 template <
typename FunctionType>
830 template <
typename FunctionType>
832 return !(fn ==
nullptr);
835 template <
typename FunctionType>
837 return !(
nullptr == fn);
844 template <
typename ReturnType,
typename...
Args>
846 Function<ReturnType(
Args...)>&& that) noexcept {
851 template <
typename ReturnType,
typename...
Args>
853 Function<ReturnType(
Args...)
const>&& that) noexcept {
857 #if FOLLY_HAVE_NOEXCEPT_FUNCTION_TYPE 858 template <
typename ReturnType,
typename...
Args>
860 Function<ReturnType(
Args...) noexcept>&& that) noexcept {
861 return Function<ReturnType(
Args...)
const noexcept>{
865 template <
typename ReturnType,
typename...
Args>
867 Function<ReturnType(
Args...)
const noexcept>&& that) noexcept {
892 template <
typename FunctionType>
895 template <
typename ReturnType,
typename...
Args>
900 throw std::bad_function_call();
903 template <
typename Fun>
904 static ReturnType
call(
void*
object,
Args&&... args) {
906 return static_cast<ReturnType
>(
invoke(
907 static_cast<Fun&&>(*static_cast<Pointer>(
object)),
908 static_cast<Args&&>(args)...));
911 void* object_{
nullptr};
912 Call call_{&FunctionRef::uninitCall};
927 typename std::enable_if<
938 const_cast<
void*>(static_cast<
void const*>(
std::addressof(
fun)))),
942 return call_(object_, static_cast<Args&&>(args)...);
945 constexpr
explicit operator bool()
const {
Function & operator=(Fun fun) noexcept(noexcept(/*implicit */Function(std::declval< Fun >())))
Function(Member Class::*ptr) noexcept
std::function< typename Traits::NonConstSignature > asStdFunction()&&
ReturnType operator()(Args...args) const
Function(Fun fun) noexcept(IsSmall< Fun >::value &&noexcept(Fun(std::declval< Fun >())))
typename std::enable_if< NotFunction< T >::value >::type EnableIfNotFunction
bool execSmall(Op o, Data *src, Data *dst)
Function(Function &&that) noexcept
decltype(std::declval< F >()(std::declval< Args >()...)) CallableResult
detail::function::HeapTag HeapTag
SharedProxy(Function< ConstSignature > &&func)
static ReturnType callSmall(Data &p, Args &&...args)
static ReturnType callBig(Data &p, Args &&...args)
constexpr detail::Map< Move > move
ReturnType(*)(Data &, Args &&...) Call
void swap(Function &that) noexcept
detail::function::SmallTag SmallTag
static ReturnType uninitCall(Data &, Args &&...)
A reference wrapper for callable objects.
std::shared_ptr< Function< ConstSignature > > sp_
constexpr FunctionRef(Fun &&fun) noexcept
SharedProxy(Function< NonConstSignature > &&func)
Function(Function< typename Traits::OtherSignature > &&that, CoerceTag) noexcept
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
SafeResultOf< CallableResult< _t< std::decay< F >> &, Args... >, ReturnType > ResultOf
requires E e noexcept(noexcept(s.error(std::move(e))))
ReturnType(Args...) const ConstSignature
Function(Fun &&fun, HeapTag)
bool_constant< true > true_type
FOLLY_PUSH_WARNING RHS rhs
static ReturnType callBig(Data &p, Args &&...args)
bool operator!=(const Unexpected< Error > &lhs, const Unexpected< Error > &rhs)
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
bool(*)(Op, Data *, Data *) Exec
NonConstSignature OtherSignature
constexpr auto invoke(F &&f, Args &&...args) noexcept(noexcept(static_cast< F && >(f)(static_cast< Args && >(args)...))) -> decltype(static_cast< F && >(f)(static_cast< Args && >(args)...))
std::integral_constant< bool, B > bool_constant
ReturnType(Args...) NonConstSignature
void swap(Function< FunctionType > &lhs, Function< FunctionType > &rhs) noexcept
ReturnType(Args...) NonConstSignature
Function(Function< Signature > &&that, CoerceTag)
std::aligned_storage< 6 *sizeof(void *)>::type tiny
ReturnType operator()(Args...args)
static ReturnType uninitCall(void *, Args &&...)
Function & operator=(Function< Signature > &&that) noexcept(noexcept(Function(std::move(that))))
std::shared_ptr< Function< NonConstSignature > > sp_
Function & operator=(Function &&that) noexcept
decltype(static_cast< To >(std::declval< From >())) SafeResultOf
static const char *const value
bool execBig(Op o, Data *src, Data *dst)
static ReturnType uninitCall(Data &, Args &&...)
void swap(exception_wrapper &a, exception_wrapper &b) noexcept
Function< ReturnType(Args...) const > constCastFunction(Function< ReturnType(Args...)> &&) noexcept
SafeResultOf< CallableResult< const _t< std::decay< F >> &, Args... >, ReturnType > ResultOf
Function & operator=(std::nullptr_t) noexcept
bool operator==(const Unexpected< Error > &lhs, const Unexpected< Error > &rhs)
auto operator=(Member Class::*ptr) noexcept-> decltype(operator=(std::mem_fn(ptr)))
typename Traits::Call Call
ReturnType operator()(Args &&...args) const
ConstSignature OtherSignature
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
bool_constant< false > false_type
ReturnType(Args...) const ConstSignature
bool exec(Op o, Data *src, Data *dst) const
bool hasAllocatedMemory() const noexcept
static ReturnType call(void *object, Args &&...args)
ReturnType operator()(Args &&...args) const
ReturnType operator()(Args...args) const
static ReturnType callSmall(Data &p, Args &&...args)
ReturnType(*)(Data &, Args &&...) Call
Function(std::nullptr_t) noexcept
#define FOLLY_FALLTHROUGH
ReturnType(*)(void *, Args &&...) Call
Future< bool > call(int depth, Executor *executor)
Function(Function< Signature > &&that) noexcept(noexcept(Function(std::move(that), CoerceTag{})))
SharedProxy asSharedProxy()&&