BDE 4.14.0 Production release
|
Macros | |
#define | BSLSTL_FUNCTION_INVOKERUTIL_CAST_RESULT(RET, X) static_cast<RET>(X) |
Provide invoker adaptors for bsl::function
@MACROS BSLSTL_FUNCTION_INVOKERUTIL_SUPPORT_IS_FUNC_INVOCABLE: defined if supported
This component provides a struct, Function_InvokerUtil
, containing a function template, invokerForFunc
, that returns a pointer to a function that is used to invoke a callable object of a particular type. The returned type is custom-generated for each specific target type. This component is for private use only.
The client of this component, bsl::function
, is a complex class that is templated in two ways:
bsl::function<int(char*)>
has member int operator()(char*);
.bsl::function
.Only the invocation mechanism needs both kinds of template parameters; other parts of bsl::function
(e.g., bslstl::Function_Rep
) concern themselves with only the callable object type, not with the prototype of the call operator. This component factors out most of that complexity so as to minimise code size, especially when using the sim_cpp11_features.pl
script to simulate C++11 variadic templates in C++03.
The classes in this component are stateless and contain only static functions.
If this component supports checking whether an object of an arbitrary non-cvref-qualified type is invocable under a particular prototype, the BSLSTL_FUNCTION_INVOKERUTIL_SUPPORT_IS_FUNC_INVOCABLE
macro is defined, and it is not defined otherwise.
The function pointer, invoker_p
, returned by Function_InvokerUtil::invokerForFunc<RET(ARG0, ARG1, ...)>
takes an argument of type Function_Rep *
and zero or more argument types ARG0
, ARG1
, ..., as specified by the template argument. Calling invoker_p(rep, arg0, arg1, ...)
gets the target, f
from rep
and invokes it with the supplied arguments. Invocation of f
follows the definition of INVOKE in section [func.require] of the C++ standard. These rules are summarized in the following table:
The arguments to f
must be implicitly convertible from the corresponding argument types ARG0
, ARG1
, ... and the return value of the call expression must be implicitly convertible to RET
, unless RET
is void
.
In the case of a pointer to member function, R (T::*f)(...)
, or pointer to data member R T::*f
, arg0X
is one of the following:
arg0
if ARG0
is T
or derived from T
.arg0.get()
if ARG0
is a specialization of reference_wrapper .(*arg0)
if ARG0
is a pointer type or pointer-like type (e.g., a smart pointer).Note that, consistent with the C++ Standard definition of INVOKE, we consider pointer-to-member-function and pointer-to-data-member types to be "callable" even though, strictly speaking, they lack an operator()
.
The class template, Function_InvokerUtilNullCheck<T>
provides a single, static
member function isNull(const T& f)
that returns true
iff f
represents a "null value". By default, Function_InvokerUtilNullCheck<T>::isNull
returns true
iff T
is a pointer or pointer-to-member type and has a null value. For non-pointer types, the primary template always returns false
. However, other components can provide specializations of Function_InvokerUtilNullCheck
that add the notion of "nullness" to other invocable types. In particular, bslstl_function.h
specializes this template for bsl::function
and bdef_function.h
specializes this template for bdef_function . In both cases, a function object is considered null if it is empty, i.e., it does not wrap an invocable object. Although it is theoretically possible to specialize Function_InvokerUtilNullCheck
for types not related to bsl::function
, doing so would go outside of the behavior of the standard std::function
type that bsl::function
is emulating. For this reason, Function_InvokerUtilNullCheck
is tucked away in this private component for use only through explicit collaboration.
#define BSLSTL_FUNCTION_INVOKERUTIL_CAST_RESULT | ( | RET, | |
X | |||
) | static_cast<RET>(X) |