Quick Links: |
#include <bslma_constructionutil.h>
Public Types | |
enum | { e_USES_ALLOCATOR_ARG_T_TRAITS = 5, e_USES_BSLMA_ALLOCATOR_TRAITS = 4, e_HAS_TRIVIAL_DEFAULT_CTOR_TRAITS = 3, e_BITWISE_COPYABLE_TRAITS = 2, e_BITWISE_MOVABLE_TRAITS = 1, e_NIL_TRAITS = 0 } |
Static Public Member Functions | |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator, bsl::integral_constant< int, e_HAS_TRIVIAL_DEFAULT_CTOR_TRAITS > *) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, bsl::integral_constant< int, e_HAS_TRIVIAL_DEFAULT_CTOR_TRAITS > *) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator, bsl::integral_constant< int, e_BITWISE_COPYABLE_TRAITS > *, const TARGET_TYPE &original) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, bsl::integral_constant< int, e_BITWISE_COPYABLE_TRAITS > *, const TARGET_TYPE &original) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator, bsl::integral_constant< int, e_BITWISE_COPYABLE_TRAITS > *, bslmf::MovableRef< TARGET_TYPE > original) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, bsl::integral_constant< int, e_BITWISE_COPYABLE_TRAITS > *, bslmf::MovableRef< TARGET_TYPE > original) |
template<class TARGET_TYPE , class... ARGS> | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator, bsl::integral_constant< int, e_USES_BSLMA_ALLOCATOR_TRAITS > *, ARGS &&...arguments) |
template<class TARGET_TYPE , class... ARGS> | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator, bsl::integral_constant< int, e_USES_ALLOCATOR_ARG_T_TRAITS > *, ARGS &&...arguments) |
template<class TARGET_TYPE , class... ARGS> | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator, bsl::integral_constant< int, e_NIL_TRAITS > *, ARGS &&...arguments) |
template<class TARGET_TYPE , class... ARGS> | |
static void | construct (TARGET_TYPE *address, bsl::integral_constant< int, e_NIL_TRAITS > *, ARGS &&...arguments) |
template<class TARGET_TYPE , class ALLOCATOR > | |
static void | destructiveMove (TARGET_TYPE *address, ALLOCATOR *allocator, bsl::integral_constant< int, e_BITWISE_MOVABLE_TRAITS > *, TARGET_TYPE *original) |
template<class TARGET_TYPE , class ALLOCATOR > | |
static void | destructiveMove (TARGET_TYPE *address, ALLOCATOR *allocator, bsl::integral_constant< int, e_NIL_TRAITS > *, TARGET_TYPE *original) |
template<class TARGET_TYPE > | |
static void * | voidify (TARGET_TYPE *address) |
This struct
provides a namespace for a suite of utility functions that are used to implement functions in ConstructionUtil
. In particular, they provide overloads, resolved at compile-time, for various features (e.g., passing down the allocator to sub-elements of pair
-like types) and optimizations (e.g., bypassing the call to the constructor for classes with trivial default and copy constructors). These functions should not be used outside this component.
See Component bslma_constructionutil
anonymous enum |
These constants are used in the overloads below, when the last argument is of type bsl::integral_constant<int, N> *
, indicating that TARGET_TYPE
has the traits for which the enumerator equal to N
is named.
void bslma::ConstructionUtil_Imp::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator, | |||
bsl::integral_constant< int, e_HAS_TRIVIAL_DEFAULT_CTOR_TRAITS > * | ||||
) | [inline, static] |
References e_HAS_TRIVIAL_DEFAULT_CTOR_TRAITS.
Referenced by construct(), bslma::ConstructionUtil::construct(), and destructiveMove().
void bslma::ConstructionUtil_Imp::construct | ( | TARGET_TYPE * | address, | |
bsl::integral_constant< int, e_HAS_TRIVIAL_DEFAULT_CTOR_TRAITS > * | ||||
) | [inline, static] |
Construct a default instance of (template parameter) TARGET_TYPE
that has a trivial default constructor, at the specified address
. If the constructor throws, the memory at address
is left in an unspecified state. Note that the behavior is undefined if TARGET_TYPE
supports bslma
-style allocators.
References voidify().
void bslma::ConstructionUtil_Imp::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator, | |||
bsl::integral_constant< int, e_BITWISE_COPYABLE_TRAITS > * | , | |||
const TARGET_TYPE & | original | |||
) | [inline, static] |
References construct().
void bslma::ConstructionUtil_Imp::construct | ( | TARGET_TYPE * | address, | |
bsl::integral_constant< int, e_BITWISE_COPYABLE_TRAITS > * | , | |||
const TARGET_TYPE & | original | |||
) | [inline, static] |
Create an object of a bitwise copyable (template parameter) TARGET_TYPE
at the specified address
, with the same value as the specified original
object. If the constructor throws, the memory at address
is left in an unspecified state. Note that the behavior is undefined if TARGET_TYPE
supports bslma
-style allocators.
References voidify().
void bslma::ConstructionUtil_Imp::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator, | |||
bsl::integral_constant< int, e_BITWISE_COPYABLE_TRAITS > * | , | |||
bslmf::MovableRef< TARGET_TYPE > | original | |||
) | [inline, static] |
References BSLS_COMPILERFEATURES_FORWARD, and construct().
void bslma::ConstructionUtil_Imp::construct | ( | TARGET_TYPE * | address, | |
bsl::integral_constant< int, e_BITWISE_COPYABLE_TRAITS > * | , | |||
bslmf::MovableRef< TARGET_TYPE > | original | |||
) | [inline, static] |
Create an object of a bitwise moveable (template parameter) TARGET_TYPE
at the specified address
, with the same value as the specified original
object. If the constructor throws, the memory at address
is left in an unspecified state. Note that the behavior is undefined if TARGET_TYPE
supports bslma
-style allocators.
References BSLS_COMPILERFEATURES_FORWARD, bslmf::MovableRefUtil::move(), and voidify().
void bslma::ConstructionUtil_Imp::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator, | |||
bsl::integral_constant< int, e_USES_BSLMA_ALLOCATOR_TRAITS > * | , | |||
ARGS &&... | arguments | |||
) | [inline, static] |
References BSLS_COMPILERFEATURES_FORWARD, and voidify().
void bslma::ConstructionUtil_Imp::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator, | |||
bsl::integral_constant< int, e_USES_ALLOCATOR_ARG_T_TRAITS > * | , | |||
ARGS &&... | arguments | |||
) | [inline, static] |
Construct an object at the specified address
having the specified (template parameter) TARGET_TYPE
that supports bslma
-style allocators. Invoke the constructor of TARGET_TYPE
using the specified arguments
. For the e_USES_BSLMA_ALLOCATOR_TRAITS
overload, the specified allocator
is passed as an additional last argument to the constructor. For the e_USES_ALLOCATOR_ARG_T_TRAITS
overload, the allocator
is passed as the second argument to the constructor, preceded by bsl::allocator_arg
. If the constructor throws, the memory at address
is left in an uninitialized state.
References bsl::allocator_arg, BSLS_COMPILERFEATURES_FORWARD, and voidify().
void bslma::ConstructionUtil_Imp::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator, | |||
bsl::integral_constant< int, e_NIL_TRAITS > * | , | |||
ARGS &&... | arguments | |||
) | [inline, static] |
References BSLS_COMPILERFEATURES_FORWARD, and construct().
void bslma::ConstructionUtil_Imp::construct | ( | TARGET_TYPE * | address, | |
bsl::integral_constant< int, e_NIL_TRAITS > * | , | |||
ARGS &&... | arguments | |||
) | [inline, static] |
Construct an object of (template parameter) TARGET_TYPE
, that does not support bslma
-style allocators, at the specified address
, invoking the constructor of TARGET_TYPE
corresponding to the specified arguments
. If the constructor throws, the memory at address
is left in an unspecified state.
References BSLS_COMPILERFEATURES_FORWARD, and voidify().
void bslma::ConstructionUtil_Imp::destructiveMove | ( | TARGET_TYPE * | address, | |
ALLOCATOR * | allocator, | |||
bsl::integral_constant< int, e_BITWISE_MOVABLE_TRAITS > * | , | |||
TARGET_TYPE * | original | |||
) | [inline, static] |
Move the bitwise movable object of (template parameter) TARGET_TYPE
at the specified original
address to the specified address
, eliding the call to the move constructor and destructor in favor of performing a bitwise copy. The behavior is undefined unless either TARGET_TYPE
does not support bslma
-style allocation or original
uses the specified allocator
to supply memory.
References voidify().
Referenced by bslma::ConstructionUtil::destructiveMove().
void bslma::ConstructionUtil_Imp::destructiveMove | ( | TARGET_TYPE * | address, | |
ALLOCATOR * | allocator, | |||
bsl::integral_constant< int, e_NIL_TRAITS > * | , | |||
TARGET_TYPE * | original | |||
) | [inline, static] |
Create an object of (template parameter) TARGET_TYPE
at the specified address
having the same value as the object at the specified original
address, propagating the specified allocator
to the moved object if TARGET_TYPE
uses bslma
-style allocation and the (template parameter) type ALLOCATOR
is implicitly convertible to bslma::Allocator
, and destroy original
. If the move constructor throws an exception, the memory at address
is left in an unspecified state and original
is left in a valid but unspecified state. The behavior is undefined unless either TARGET_TYPE
does not support bslma
-style allocation or original
uses allocator
to supply memory. Note that this class method is equivalent to move-constructing an object at address
from *original
and then destroying original
. Also note that if original
actually points to an object of a type derived from TARGET_TYPE
(i.e., a slicing move) where TARGET_TYPE
has a non-'virtual' destructor, then original
will be only partially destroyed.
References construct(), and bslmf::MovableRefUtil::move().
void * bslma::ConstructionUtil_Imp::voidify | ( | TARGET_TYPE * | address | ) | [inline, static] |
Return the specified address
cast as a pointer to void
, even if the (template parameter) TARGET_TYPE
is cv-qualified.
Referenced by bslma::ConstructionUtil::construct(), construct(), and destructiveMove().