|
| 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< typenameDecay< FUNC >::type, function >::value &&IsInvocableWithPrototype< typenameDecay< FUNC >::type >::value, function & >::type | operator= (BSLS_COMPILERFEATURES_FORWARD_REF(FUNC) rhs) |
|
template<class FUNC > |
enable_if< IsInvocableWithPrototype< typenameDecay< FUNC >::type >::value, function & >::type | operator= (bsl::reference_wrapper< FUNC > rhs) BSLS_KEYWORD_NOEXCEPT |
|
function & | operator= (nullptr_t) BSLS_KEYWORD_NOEXCEPT |
| Set this object to empty and return *this .
|
|
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 |
|
template<class PROTOTYPE>
class bsl::function< PROTOTYPE >
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.
See bslstl_function
template<class PROTOTYPE >
template<class FUNC >
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 |
|
) |
| |
|
inlineexplicit |
Create an object wrapping the specified func
callable object. This constructor (ctor 2) is identical to the previous constructor (ctor 1) except that, in C++03 ctor 2 provides for explicit construction from a MovableRef
referencing a callable type, rather than an implicit conversion for FUNC
not being a MovableRef
. In C++11, overload resolution matching an argument of type T&&
to a parameter of type T
(exact match) is always preferred over matching T&&
to bsl::function
(conversion). In C++03, however MovableRef
is not a real reference type, so it sometimes creates overload ambiguities whereby matching MovableRef<T>
to T
(conversion) is no better than matching MovableRef<T>
to bsl::function
(also conversion). This ambiguity is resolved by making this constructor from MovableRef<T>
explicit, while leaving other constructor from FUNC
implicit. This means that move
will fail in a narrow set of cases in C++03, as shown below:
MyCallableType x;
Obj f1 = x;
void y(const Obj& f);
y(x);
Forward declaration.
Definition bslstl_function.h:934
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1060
As you can see from the examples above, there are simple workarounds for the problem cases, although generic code might need to be extra careful.
Implementation Note