Quick Links: |
#include <bslstl_function.h>
Classes | |
struct | Decay |
struct | IsInvocableWithPrototype |
struct | IsReferenceCompatible |
Public Types | |
typedef Function_Rep::allocator_type | allocator_type |
Public Member Functions | |
BSLMF_NESTED_TRAIT_DECLARATION (function, BloombergLP::bslma::UsesBslmaAllocator) | |
BSLMF_NESTED_TRAIT_DECLARATION (function, BloombergLP::bslmf::UsesAllocatorArgT) | |
BSLMF_NESTED_TRAIT_DECLARATION (function, bsl::is_nothrow_move_constructible) | |
function () BSLS_KEYWORD_NOEXCEPT | |
function (nullptr_t) BSLS_KEYWORD_NOEXCEPT | |
function (allocator_arg_t, const allocator_type &allocator) BSLS_KEYWORD_NOEXCEPT | |
function (allocator_arg_t, const allocator_type &allocator, nullptr_t) BSLS_KEYWORD_NOEXCEPT | |
template<class FUNC > | |
function (BSLS_COMPILERFEATURES_FORWARD_REF(FUNC) func, typename enable_if< !IsReferenceCompatible< typename Decay< FUNC >::type, function >::value &&IsInvocableWithPrototype< typename Decay< FUNC >::type >::value &&!MovableRefUtil::IsMovableReference< FUNC >::value, int >::type=0) | |
template<class FUNC > | |
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) | |
template<class FUNC > | |
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) | |
function (const function &original) | |
function (allocator_arg_t, const allocator_type &allocator, const function &original) | |
function (BloombergLP::bslmf::MovableRef< function > original) BSLS_KEYWORD_NOEXCEPT | |
function (allocator_arg_t, const allocator_type &allocator, BloombergLP::bslmf::MovableRef< function > original) | |
function & | operator= (const function &rhs) |
function & | operator= (BloombergLP::bslmf::MovableRef< function > rhs) |
template<class FUNC > | |
enable_if < !IsReferenceCompatible < typename Decay< FUNC >::type, function >::value &&IsInvocableWithPrototype < typename Decay< FUNC >::type > ::value, function & >::type | operator= (BSLS_COMPILERFEATURES_FORWARD_REF(FUNC) rhs) |
template<class FUNC > | |
enable_if < IsInvocableWithPrototype < typename Decay< FUNC >::type > ::value, function & >::type | operator= (bsl::reference_wrapper< FUNC > rhs) BSLS_KEYWORD_NOEXCEPT |
function & | operator= (nullptr_t) BSLS_KEYWORD_NOEXCEPT |
void | swap (function &other) BSLS_KEYWORD_NOEXCEPT |
template<class TP > | |
TP * | target () BSLS_KEYWORD_NOEXCEPT |
operator UnspecifiedBool () const BSLS_KEYWORD_NOEXCEPT | |
allocator_type | get_allocator () const BSLS_KEYWORD_NOEXCEPT |
template<class TP > | |
const TP * | target () const BSLS_KEYWORD_NOEXCEPT |
const std::type_info & | target_type () const BSLS_KEYWORD_NOEXCEPT |
operator BloombergLP::bdef_Function< PROTOTYPE * > & () BSLS_KEYWORD_NOEXCEPT | |
operator const BloombergLP::bdef_Function< PROTOTYPE * > & () const BSLS_KEYWORD_NOEXCEPT | |
BloombergLP::bslma::Allocator * | allocator () const BSLS_KEYWORD_NOEXCEPT |
bool | isInplace () const BSLS_KEYWORD_NOEXCEPT |
This class template implements the C++ Standard Library std::function
template, enhanced for allocator support as per Standards Proposal P0987. An instantiation of this template generalizes the notion of a pointer to a function having the specified PROTOTYPE
expressed as a function type (e.g., int(const char *, float)
). An object of this class wraps a copy of the callable object specified at construction (if any), such as a function pointer, member-function pointer, member-data pointer, or functor object. The wrapped object (called the target or target object) is owned by the bsl::function
object (unlike the function pointer that it mimics). Invoking the bsl::function
object will invoke the target (or throw an exception, if there is no target). Note that function
will compile only if PROTOTYPE
is a function type.
To optimize away many heap allocations, objects of this type have a buffer into which small callable objects can be stored. In order to qualify for this small-object optimization, a callable type must not only fit in the buffer but must also be nothrow move constructible. The latter constraint allows this type to be nothrow move constructible and nothrow swappable, as required by the C++ Standard. The small object buffer is guaranteed to be large enough to hold a pointer to function, pointer to member function, pointer to member data, a bsl::reference_wrapper
, or an empty struct. Although the standard does not specify a minimum size beyond the aforementioned guarantee, many small structs will fit in the small object buffer, as defined in the bslstl_function_smallobjectoptimization
component.
typedef Function_Rep::allocator_type bsl::function< PROTOTYPE >::allocator_type |
bsl::function< PROTOTYPE >::function | ( | ) |
bsl::function< PROTOTYPE >::function | ( | nullptr_t | ) |
IMPLICIT:
bsl::function< PROTOTYPE >::function | ( | allocator_arg_t | , | |
const allocator_type & | allocator | |||
) |
bsl::function< PROTOTYPE >::function | ( | allocator_arg_t | , | |
const allocator_type & | allocator, | |||
nullptr_t | ||||
) |
Create an empty function
object. Optionally specify an allocator
(e.g., the address of a bslma::Allocator
object) to supply memory; otherwise, the default allocator is used.
bsl::function< PROTOTYPE >::function | ( | BSLS_COMPILERFEATURES_FORWARD_REF(FUNC) | func, | |
typename enable_if< !IsReferenceCompatible< typename Decay< FUNC >::type, function< PROTOTYPE > >::value &&IsInvocableWithPrototype< typename Decay< FUNC >::type >::value &&!MovableRefUtil::IsMovableReference< FUNC >::value, int >::type | = 0 | |||
) | [inline] |
func | IMPLICIT: |
bsl::function< PROTOTYPE >::function | ( | const BloombergLP::bslmf::MovableRef< FUNC > & | func, | |
typename enable_if< !IsReferenceCompatible< typename Decay< FUNC >::type, function< PROTOTYPE > >::value &&IsInvocableWithPrototype< typename Decay< FUNC >::type >::value, int >::type | = 0 | |||
) | [inline, explicit] |
bsl::function< PROTOTYPE >::function | ( | allocator_arg_t | , | |
const allocator_type & | allocator, | |||
BSLS_COMPILERFEATURES_FORWARD_REF(FUNC) | func, | |||
typename enable_if< !IsReferenceCompatible< typename Decay< FUNC >::type, function< PROTOTYPE > >::value &&IsInvocableWithPrototype< typename Decay< FUNC >::type >::value, int >::type | = 0 | |||
) | [inline] |
bsl::function< PROTOTYPE >::function | ( | const function< PROTOTYPE > & | original | ) |
bsl::function< PROTOTYPE >::function | ( | allocator_arg_t | , | |
const allocator_type & | allocator, | |||
const function< PROTOTYPE > & | original | |||
) |
Create a function
having the same value as (i.e., wrapping a copy of the target held by) the specified original
object. Optionally specify an allocator
(e.g., the address of a bslma::Allocator
object) to supply memory; otherwise, the default allocator is used.
bsl::function< PROTOTYPE >::function | ( | BloombergLP::bslmf::MovableRef< function< PROTOTYPE > > | original | ) |
IMPLICIT: Create a function
having the same target as the specified original
object. Use original.get_allocator()
as the allocator to supply memory. The original
object is set to empty after the new object is created. If the target qualifies for the small-object optimization (see class-level documentation), then it is move-constructed into the new object; otherwise ownership of the target is transferred without using the target's move constructor.
bsl::function< PROTOTYPE >::function | ( | allocator_arg_t | , | |
const allocator_type & | allocator, | |||
BloombergLP::bslmf::MovableRef< function< PROTOTYPE > > | original | |||
) |
Create a function
having the same value as (i.e., wrapping a copy of the target held by) the specified original
object. Use the specified allocator
(e.g., the address of a bslma::Allocator
object) to supply memory. If allocator == original.allocator()
, this object is created as if by move construction; otherwise it is created as if by extended copy construction using allocator
.
bsl::function< PROTOTYPE >::BSLMF_NESTED_TRAIT_DECLARATION | ( | function< PROTOTYPE > | , | |
BloombergLP::bslma::UsesBslmaAllocator | ||||
) |
bsl::function< PROTOTYPE >::BSLMF_NESTED_TRAIT_DECLARATION | ( | function< PROTOTYPE > | , | |
BloombergLP::bslmf::UsesAllocatorArgT | ||||
) |
bsl::function< PROTOTYPE >::BSLMF_NESTED_TRAIT_DECLARATION | ( | function< PROTOTYPE > | , | |
bsl::is_nothrow_move_constructible | ||||
) |
function& bsl::function< PROTOTYPE >::operator= | ( | const function< PROTOTYPE > & | rhs | ) |
Set the target of this object to a copy of the target (if any) held by the specified rhs
object, destroy the target (if any) previously held by *this
, and return *this
. The result is equivalent to having constructed *this
from rhs
using the extended copy constructor with allocator this->get_allocator()
. If an exception is thrown, *this
is not modified (i.e., copy assignment provides the strong exception guarantee).
function& bsl::function< PROTOTYPE >::operator= | ( | BloombergLP::bslmf::MovableRef< function< PROTOTYPE > > | rhs | ) |
Set the target of this object to the target (if any) held by the specified rhs
object, destroy the target (if any) previously held by *this
, and return *this
. The result is equivalent to having constructed *this
from rhs
using the extended move constructor with allocator this->get_allocator()
. If an exception is thrown, rhs
will have a valid but unspecified value and *this
will not be modified. Note that an exception will never be thrown if get_allocator() == rhs.get_allocator()
.
enable_if< ! IsReferenceCompatible<typename Decay<FUNC>::type, function>::value && IsInvocableWithPrototype<typename Decay<FUNC>::type>::value , function&>::type bsl::function< PROTOTYPE >::operator= | ( | BSLS_COMPILERFEATURES_FORWARD_REF(FUNC) | rhs | ) | [inline] |
rhs | Set the target of this object to the specified rhs callable object, destroy the previous target (if any), and return *this . The result is equivalent to having constructed *this from std::forward<FUNC>(rhs) and this->get_allocator() . Note that this assignment operator will not participate in overload resolution if func is of the same type as this object (to avoid ambiguity with the copy and move assignment operators.) In C++03, instantiation will fail unless FUNC is invocable with the arguments and return type specified in PROTOTYPE . In C++11 and later, this assignment operator will not participate in overload resolution unless FUNC is invocable with the arguments and return type specified in PROTOTYPE . |
enable_if< IsInvocableWithPrototype<typename Decay<FUNC>::type>::value , function &>::type bsl::function< PROTOTYPE >::operator= | ( | bsl::reference_wrapper< FUNC > | rhs | ) | [inline] |
< Destroy the current target (if any) of this object, then set the target to the specified rhs
wrapper containing a reference to a callable object and return *this
. The result is equivalent to having constructed *this
from rhs
and this->get_allocator()
. Note that this assignment is a separate overload only because it is unconditionally noexcept
.
function& bsl::function< PROTOTYPE >::operator= | ( | nullptr_t | ) |
Set this object to empty and return *this
.
void bsl::function< PROTOTYPE >::swap | ( | function< PROTOTYPE > & | other | ) |
< If this object is empty, throw bsl::bad_function_call
; otherwise invoke the target object with the specified args...
and return the result (after conversion to RET
). Note that, even though it is declared const
, this call operator can mutate the target object and is thus considered a manipulator rather than an accessor. Exchange the targets held by this function
and the specified other
function
. The behavior is undefined unless get_allocator() == other.get_allocator()
.
If TP
is the same type as the target object, returns a pointer granting modifiable access to the target; otherwise return a null pointer.
bsl::function< PROTOTYPE >::operator UnspecifiedBool | ( | ) | const [inline] |
< (C++03 only) Return a null value if this object is empty, otherwise an arbitrary non-null value. Note that this operator will be invoked implicitly in boolean contexts such as in the condition of an if
or while
statement, but does not constitute an implicit conversion to bool
.
allocator_type bsl::function< PROTOTYPE >::get_allocator | ( | ) | const |
Return (a copy of) the allocator used to supply memory for this function
.
Referenced by bsl::function< void(const bsl::string &prefix, bsl::istream &stream)>::operator=().
const TP* bsl::function< PROTOTYPE >::target | ( | ) | const |
If TP
is the same type as the target object, returns a pointer granting read-only access to the target; otherwise return a null pointer.
const std::type_info& bsl::function< PROTOTYPE >::target_type | ( | ) | const |
Return typeid(void)
if this object is empty; otherwise typeid(FUNC)
where FUNC
is the type of the target object.
bsl::function< PROTOTYPE >::operator BloombergLP::bdef_Function< PROTOTYPE * > & | ( | ) |
DEPRECATED: Use bsl::function
instead of bdef_Function
.
Return *this
, converted to a mutable bdef_Function
reference by downcasting. The behavior is undefined unless bdef_Function<F*>
is derived from bsl::function<F>
and adds no new data members.
bsl::function< PROTOTYPE >::operator const BloombergLP::bdef_Function< PROTOTYPE * > & | ( | ) | const |
DEPRECATED: Use bsl::function
instead of bdef_Function
.
Return *this
converted to a const bdef_Function
reference by downcasting. The behavior is undefined unless bdef_Function<F*>
is derived from bsl::function<F>
and adds no new data members.
BloombergLP::bslma::Allocator* bsl::function< PROTOTYPE >::allocator | ( | ) | const |
DEPRECATED: Use get_allocator()
instead.
Return get_allocator().mechanism()
. Note that this function exists for BDE compatibility and is not part of the C++ Standard Library.
bool bsl::function< PROTOTYPE >::isInplace | ( | ) | const |
DEPRECATED: Runtime checking of this optimization is discouraged.
Return true
if this function
is empty or if it is non-empty and its target qualifies for the small-object optimization (and is thus allocated within this object's footprint); otherwise, return false.