8#ifndef INCLUDED_BSLSTL_FUNCTION
9#define INCLUDED_BSLSTL_FUNCTION
640#include <bslscm_version.h>
666#ifdef BDE_BUILD_TARGET_EXC
669#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
675#ifdef BSLSTL_FUNCTION_VARIADIC_LIMIT
676#define BSLSTL_FUNCTION_INVOKERUTIL_VARIADIC_LIMIT \
677 BSLSTL_FUNCTION_VARIADIC_LIMIT
689#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
693#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
697# define COMPILING_BSLSTL_FUNCTION_H
699# undef COMPILING_BSLSTL_FUNCTION_H
703#ifdef BSLS_ASSERTIMPUTIL_AVOID_STRING_CONSTANTS
705extern const char s_bslstl_function_h[];
706#undef BSLS_ASSERTIMPUTIL_FILE
707#define BSLS_ASSERTIMPUTIL_FILE BloombergLP::s_bslstl_function_h
715template <
class PROTOTYPE>
722#ifndef BDE_OMIT_INTERNAL_DEPRECATED
730template <
class PROTOTYPE>
754template <
class PROTOTYPE>
761template <
class RET,
class ARG>
766 "deprecated_cpp17_standard_library_features",
770 typedef ARG argument_type;
776template <class RET, class ARG1, class ARG2>
781 "deprecated_cpp17_standard_library_features",
785 typedef ARG1 first_argument_type;
788 "deprecated_cpp17_standard_library_features",
792 typedef ARG2 second_argument_type;
799#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
801template <
class PROTOTYPE>
817template <
class RET,
class... ARGS>
869 RET operator()(ARGS... args)
const;
893template <
class PROTOTYPE,
class FUNC>
933template <
class PROTOTYPE>
934class function :
public BloombergLP::bslstl::Function_Variadic<PROTOTYPE> {
938 typedef BloombergLP::bslstl::Function_Variadic<PROTOTYPE> Base;
939 typedef BloombergLP::bslstl::Function_Rep Function_Rep;
940 typedef BloombergLP::bslmf::MovableRefUtil MovableRefUtil;
945 template <
class FROM,
class TO>
946 struct IsReferenceCompatible
947 : BloombergLP::bslstl::Function_IsReferenceCompatible<FROM, TO>::type {
953 template <
class TYPE>
954 struct Decay : MovableRefUtil::Decay<TYPE> {
961 template <
class FUNC>
962 struct IsInvocableWithPrototype
963 : BloombergLP::bslstl::Function_IsInvocableWithPrototype<PROTOTYPE, FUNC> {
966#ifndef BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT
972 typedef BloombergLP::bsls::UnspecifiedBool<function> UnspecifiedBoolUtil;
973 typedef typename UnspecifiedBoolUtil::BoolType UnspecifiedBool;
981 bool operator==(
const function&)
const;
982 bool operator!=(
const function&)
const;
994 template <
class FUNC>
1000 BloombergLP::bslma::UsesBslmaAllocator);
1002 BloombergLP::bslmf::UsesAllocatorArgT);
1037 template <class FUNC>
1040 ! IsReferenceCompatible<typename Decay<FUNC>::type,
1042 && IsInvocableWithPrototype<
1043 typename Decay<FUNC>::type>::value
1044#ifndef BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES
1045 && ! MovableRefUtil::IsMovableReference<FUNC>::value
1047#ifdef BSLS_PLATFORM_CMP_IBM
1075#ifdef BSLS_PLATFORM_CMP_IBM
1076 template <
class FUNC>
1080 : Base(allocator_type())
1101#ifndef BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES
1133 template <
class FUNC>
1134 explicit function(
const BloombergLP::bslmf::MovableRef<FUNC>& func,
1136 ! IsReferenceCompatible<
typename Decay<FUNC>::type,
1138 && IsInvocableWithPrototype<
1139 typename Decay<FUNC>::type>::value
1148 installFunc(BloombergLP::bslmf::MovableRefUtil::move(func));
1168 template <
class FUNC>
1173 ! IsReferenceCompatible<
typename Decay<FUNC>::type,
1175 && IsInvocableWithPrototype<
1176 typename Decay<FUNC>::type>::value
1177#ifdef BSLS_PLATFORM_CMP_IBM
1205#ifdef BSLS_PLATFORM_CMP_IBM
1206 template <
class FUNC>
1248 function(BloombergLP::bslmf::MovableRef<function> original)
1259 BloombergLP::bslmf::MovableRef<function> original);
1294 template <
class FUNC>
1296 ! IsReferenceCompatible<typename Decay<FUNC>::type,
function>::value
1297 && IsInvocableWithPrototype<typename Decay<FUNC>::type>::value
1306 function(allocator_arg, this->get_allocator(),
1311#ifdef BSLS_PLATFORM_CMP_IBM
1316 template <
class FUNC>
1318 operator=(FUNC *rhs)
1329 function(allocator_arg, this->get_allocator(), rhs).
swap(*
this);
1340 template <
class FUNC>
1342 IsInvocableWithPrototype<typename Decay<FUNC>::type>::value
1351 function(allocator_arg, this->get_allocator(), rhs).
swap(*
this);
1365 using Base::operator();
1378#ifdef BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT
1395 return UnspecifiedBoolUtil::makeValue(0 != this->d_rep.invoker());
1412#ifndef BDE_OMIT_INTERNAL_DEPRECATED
1427 operator const BloombergLP::bdef_Function<PROTOTYPE *>&()
const
1448#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
1453template<
class RET,
class... ARGS>
1458template<
class ALLOC,
class RET,
class... ARGS>
1459function(allocator_arg_t, ALLOC, RET(*)(ARGS...)) ->
function<RET(ARGS...)>;
1465struct FunctionDeductionHelper {
1469 template<
class FUNCTOR>
1470 struct StripSignature {};
1472 template<
class RET,
class FUNCTOR,
class ...ARGS>
1473 struct StripSignature<RET (FUNCTOR::*) (ARGS...)>
1474 {
using Sig = RET(ARGS...); };
1476 template<
class RET,
class FUNCTOR,
class ...ARGS>
1477 struct StripSignature<RET (FUNCTOR::*) (ARGS...) const>
1478 {
using Sig = RET(ARGS...); };
1480 template<
class RET,
class FUNCTOR,
class ...ARGS>
1481 struct StripSignature<RET (FUNCTOR::*) (ARGS...) noexcept>
1482 {
using Sig = RET(ARGS...); };
1484 template<
class RET,
class FUNCTOR,
class ...ARGS>
1485 struct StripSignature<RET (FUNCTOR::*) (ARGS...) const noexcept>
1486 {
using Sig = RET(ARGS...); };
1488 template<
class RET,
class FUNCTOR,
class ...ARGS>
1489 struct StripSignature<RET (FUNCTOR::*) (ARGS...) &>
1490 {
using Sig = RET(ARGS...); };
1492 template<
class RET,
class FUNCTOR,
class ...ARGS>
1493 struct StripSignature<RET (FUNCTOR::*) (ARGS...) const &>
1494 {
using Sig = RET(ARGS...); };
1496 template<
class RET,
class FUNCTOR,
class ...ARGS>
1497 struct StripSignature<RET (FUNCTOR::*) (ARGS...) & noexcept>
1498 {
using Sig = RET(ARGS...); };
1500 template<
class RET,
class FUNCTOR,
class ...ARGS>
1501 struct StripSignature<RET (FUNCTOR::*) (ARGS...) const & noexcept>
1502 {
using Sig = RET(ARGS...); };
1509 class PROTOTYPE =
typename
1510 FunctionDeductionHelper::StripSignature<
decltype(&FP::operator())>::Sig
1512function(FP) -> function<PROTOTYPE>;
1519 class PROTOTYPE =
typename
1520 FunctionDeductionHelper::StripSignature<
decltype(&FP::operator())>::Sig
1522function(allocator_arg_t, ALLOC, FP) -> function<PROTOTYPE>;
1526template <
class PROTOTYPE>
1530template <
class PROTOTYPE>
1533template <
class PROTOTYPE>
1537template <
class PROTOTYPE>
1543template <
class PROTOTYPE>
1554#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1561template <
class RET,
class... ARGS>
1570template <
class RET,
class... ARGS>
1576 Invoker *invoker_p =
reinterpret_cast<Invoker*
>(d_rep.invoker());
1579#ifdef BDE_BUILD_TARGET_EXC
1581 throw bsl::bad_function_call();
1592 return invoker_p(&d_rep, args...);
1599#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1605#ifdef BSLSTL_FUNCTION_INVOKERUTIL_SUPPORT_IS_FUNC_INVOCABLE
1616template <
class RET,
class FUNC,
class... ARGS>
1618: Function_InvokerUtil::IsFuncInvocable<RET(ARGS...), FUNC> {
1635template <
class RET,
class FUNC,
class... ARGS>
1651template <
class PROTOTYPE>
1652template <
class FUNC>
1657 typedef BloombergLP::bslstl::Function_InvokerUtil InvokerUtil;
1658 typedef InvokerUtil::GenericInvoker GenericInvoker;
1659 typedef typename Decay<FUNC>::type DecayedFunc;
1661 const DecayedFunc& decayedFunc = func;
1662 GenericInvoker *
const invoker =
1663 InvokerUtil::invokerForFunc<PROTOTYPE>(decayedFunc);
1670template <
class PROTOTYPE>
1676template <
class PROTOTYPE>
1682template <
class PROTOTYPE>
1691template <
class PROTOTYPE>
1700template <
class PROTOTYPE>
1704 this->d_rep.copyInit(original.d_rep);
1707template <
class PROTOTYPE>
1713 this->d_rep.copyInit(original.d_rep);
1716template <
class PROTOTYPE>
1720 : Base(MovableRefUtil::access(original).get_allocator())
1722 this->d_rep.moveInit(&MovableRefUtil::access(original).d_rep);
1725template <
class PROTOTYPE>
1729 BloombergLP::bslmf::MovableRef<function> original)
1732 this->d_rep.moveInit(&MovableRefUtil::access(original).d_rep);
1736template <
class PROTOTYPE>
1740 function temp(allocator_arg, this->get_allocator(), rhs);
1741 this->d_rep.makeEmpty();
1742 this->d_rep.moveInit(&temp.d_rep);
1746template <
class PROTOTYPE>
1749 BloombergLP::bslmf::MovableRef<function> rhs)
1751 function temp(allocator_arg, this->get_allocator(),
1752 MovableRefUtil::move(rhs));
1753 this->d_rep.makeEmpty();
1754 this->d_rep.moveInit(&temp.d_rep);
1758template <
class PROTOTYPE>
1762 this->d_rep.makeEmpty();
1766template <
class PROTOTYPE>
1770 this->d_rep.
swap(other.d_rep);
1773template <
class PROTOTYPE>
1778 return this->d_rep.template target<TP>();
1783#ifdef BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT
1784template <
class PROTOTYPE>
1790 return 0 != this->d_rep.invoker();
1794template <
class PROTOTYPE>
1802template <
class PROTOTYPE>
1807#if defined(BSLS_PLATFORM_CMP_MSVC) && BSLS_PLATFORM_CMP_VERSION < 1900
1809 return (
const TP*) this->d_rep.target<TP>();
1811 return this->d_rep.template target<TP>();
1815template <
class PROTOTYPE>
1816const std::type_info&
1819 return this->d_rep.target_type();
1822#ifndef BDE_OMIT_INTERNAL_DEPRECATED
1824template <
class PROTOTYPE>
1829 typedef BloombergLP::bdef_Function<PROTOTYPE *> Ret;
1830 return *
static_cast<Ret*
>(
this);
1833template <
class PROTOTYPE>
1836operator
const BloombergLP::bdef_Function<PROTOTYPE *>&()
const
1839 typedef const BloombergLP::bdef_Function<PROTOTYPE *> Ret;
1840 return *
static_cast<Ret*
>(
this);
1843template <
class PROTOTYPE>
1845BloombergLP::bslma::Allocator *
1848 return get_allocator().mechanism();
1851template <
class PROTOTYPE>
1860template <
class PROTOTYPE>
1868template <
class PROTOTYPE>
1876template <
class PROTOTYPE>
1884template <
class PROTOTYPE>
1892template <
class PROTOTYPE>
1909template <
class PROTO>
1926#ifdef BSLS_ASSERTIMPUTIL_AVOID_STRING_CONSTANTS
1927#undef BSLS_ASSERTIMPUTIL_FILE
1928#define BSLS_ASSERTIMPUTIL_FILE BSLS_ASSERTIMPUTIL_DEFAULTFILE
Definition bslstl_function.h:731
Forward declaration.
Definition bslstl_function.h:934
function(const BloombergLP::bslmf::MovableRef< FUNC > &func, typename enable_if< ! IsReferenceCompatible< typename Decay< FUNC >::type, function >::value &&IsInvocableWithPrototype< typename Decay< FUNC >::type >::value, int >::type=0)
Definition bslstl_function.h:1134
function(allocator_arg_t, const allocator_type &allocator, BSLS_COMPILERFEATURES_FORWARD_REF(FUNC) func, typename enable_if< ! IsReferenceCompatible< typename Decay< FUNC >::type, function >::value &&IsInvocableWithPrototype< typename Decay< FUNC >::type >::value, int >::type=0)
Definition bslstl_function.h:1169
BSLMF_NESTED_TRAIT_DECLARATION(function, bsl::is_nothrow_move_constructible)
BSLMF_NESTED_TRAIT_DECLARATION(function, BloombergLP::bslma::UsesBslmaAllocator)
BSLMF_NESTED_TRAIT_DECLARATION(function, BloombergLP::bslmf::UsesAllocatorArgT)
enable_if< IsInvocableWithPrototype< typenameDecay< FUNC >::type >::value, function & >::type operator=(bsl::reference_wrapper< FUNC > rhs) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_function.h:1344
Function_Rep::allocator_type allocator_type
Definition bslstl_function.h:1007
enable_if<!IsReferenceCompatible< typenameDecay< FUNC >::type, function >::value &&IsInvocableWithPrototype< typenameDecay< FUNC >::type >::value, function & >::type operator=(BSLS_COMPILERFEATURES_FORWARD_REF(FUNC) rhs)
Definition bslstl_function.h:1299
Imp::Type Type
Definition bslmf_forwardingtype.h:439
Definition bslstl_function_rep.h:132
~Function_Variadic()=default
RET result_type
Definition bslstl_function.h:850
Function_Rep d_rep
Definition bslstl_function.h:835
Function_Rep::allocator_type allocator_type
Definition bslstl_function.h:851
Definition bslstl_function.h:802
#define BSLS_ASSERT_OPT(X)
Definition bsls_assert.h:1856
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2012
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2018
#define BSLS_DEPRECATE_FEATURE(UOR, FEATURE, MESSAGE)
Definition bsls_deprecatefeature.h:319
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_DELETED
Definition bsls_keyword.h:609
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
BloombergLP::bslma::Allocator * allocator() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_function.h:1846
function & operator=(const function &rhs)
Definition bslstl_function.h:1738
function & operator=(BloombergLP::bslmf::MovableRef< function > rhs)
Definition bslstl_function.h:1748
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_function.h:1797
const std::type_info & target_type() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_function.h:1817
bool isInplace() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_function.h:1853
function(allocator_arg_t, const allocator_type &allocator, const function &original)
Definition bslstl_function.h:1708
function(allocator_arg_t, const allocator_type &allocator, BloombergLP::bslmf::MovableRef< function > original)
Definition bslstl_function.h:1726
function & operator=(nullptr_t) BSLS_KEYWORD_NOEXCEPT
Set this object to empty and return *this.
Definition bslstl_function.h:1760
void swap(function &other) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_function.h:1768
TP * target() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_function.h:1776
function() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_function.h:1671
function(const function &original)
Definition bslstl_function.h:1701
function(BloombergLP::bslmf::MovableRef< function > original) BSLS_KEYWORD_NOEXCEPT
Definition bslstl_function.h:1718
Definition bdlb_printmethods.h:283
BloombergLP::bsls::Nullptr_Impl::Type nullptr_t
Definition bsls_nullptr.h:281
void swap(array< VALUE_TYPE, SIZE > &lhs, array< VALUE_TYPE, SIZE > &rhs)
bool operator==(const memory_resource &a, const memory_resource &b)
bool operator!=(const memory_resource &a, const memory_resource &b)
Definition bslstl_algorithm.h:82
Definition bdldfp_decimal.h:5188
Definition bslmf_enableif.h:525
Definition bslmf_integralconstant.h:244
Definition bslmf_isfunction.h:232
Definition bslmf_isnothrowmoveconstructible.h:358
BSLS_DEPRECATE_FEATURE("bsl", "deprecated_cpp17_standard_library_features", "do not use") typedef ARG1 first_argument_type
BSLS_DEPRECATE_FEATURE("bsl", "deprecated_cpp17_standard_library_features", "do not use") typedef ARG argument_type
Definition bslstl_function.h:755
static bool isNull(const bsl::function< PROTO > &f)
Definition bslstl_function.h:1916
Definition bslstl_function_invokerutil.h:294
Definition bslstl_function.h:894