Quick Links: |
#include <bslma_constructionutil.h>
Static Public Member Functions | |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, void *allocator) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator, const TARGET_TYPE &original) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, void *, const TARGET_TYPE &original) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator, TARGET_TYPE &original) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, void *, TARGET_TYPE &original) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator, bslmf::MovableRef< TARGET_TYPE > original) |
template<class TARGET_TYPE > | |
static void | construct (TARGET_TYPE *address, void *allocator, bslmf::MovableRef< TARGET_TYPE > original) |
template<class TARGET_TYPE , class ARG1 , class... ARGS> | |
static void | construct (TARGET_TYPE *address, bslma::Allocator *allocator, ARG1 &&argument, ARGS &&...arguments) |
template<class TARGET_TYPE , class ARG1 , class... ARGS> | |
static void | construct (TARGET_TYPE *address, void *allocator, ARG1 &&argument, ARGS &&...arguments) |
template<class TARGET_TYPE , class ALLOCATOR > | |
static void | destructiveMove (TARGET_TYPE *address, ALLOCATOR *allocator, TARGET_TYPE *original) |
This struct
provides a namespace for utility functions that construct elements of (a template parameter) TARGET_TYPE
.
See Component bslma_constructionutil
void bslma::ConstructionUtil::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator | |||
) | [inline, static] |
References bslma::ConstructionUtil_Imp::construct(), bslma::ConstructionUtil_Imp::e_HAS_TRIVIAL_DEFAULT_CTOR_TRAITS, bslma::ConstructionUtil_Imp::e_NIL_TRAITS, and bslma::ConstructionUtil_Imp::e_USES_ALLOCATOR_ARG_T_TRAITS.
Referenced by bdlc::FlatHashTable< KEY, KEY, FlatHashSet_EntryUtil< KEY >, HASH, EQUAL >::insert(), bslalg::NothrowMovableWrapper< TYPE >::NothrowMovableWrapper(), bdlb::Variant_MoveConstructVisitor::operator()(), bdlb::Variant_CopyConstructVisitor::operator()(), and bdlb::Variant_DefaultConstructVisitor::operator()().
void bslma::ConstructionUtil::construct | ( | TARGET_TYPE * | address, | |
void * | allocator | |||
) | [inline, static] |
Create a default-constructed object of (template parameter) TARGET_TYPE
at the specified address
. If allocator
is of type bslma::Allocator
and TARGET_TYPE
supports bslma
-style allocation, allocator
is passed to the default constructor. If the constructor throws, the memory at address
is left in an unspecified state. Note that this operation may bypass the call to the default constructor of a user-defined type entirely if TARGET_TYPE
1) does not use bslma
-style allocators and 2) has a trivial default constructor.
References bslma::ConstructionUtil_Imp::construct(), bslma::ConstructionUtil_Imp::e_HAS_TRIVIAL_DEFAULT_CTOR_TRAITS, and bslma::ConstructionUtil_Imp::e_NIL_TRAITS.
void bslma::ConstructionUtil::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator, | |||
const TARGET_TYPE & | original | |||
) | [inline, static] |
void bslma::ConstructionUtil::construct | ( | TARGET_TYPE * | address, | |
void * | , | |||
const TARGET_TYPE & | original | |||
) | [inline, static] |
void bslma::ConstructionUtil::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator, | |||
TARGET_TYPE & | original | |||
) | [inline, static] |
void bslma::ConstructionUtil::construct | ( | TARGET_TYPE * | address, | |
void * | , | |||
TARGET_TYPE & | original | |||
) | [inline, static] |
Create an object of (template parameter) TARGET_TYPE
, having the same value as the specified original
object, at the specified address
. If allocator
is of type bslma::Allocator
and TARGET_TYPE
supports bslma
-style allocation, allocator
is propagated to the newly created object. If a constructor throws, the memory at address
is left in an unspecified state. Note that this operation may elide the call to the copy constructor entirely if TARGET_TYPE
1) does not use bslma
-style allocators and 2) is trivially copyable. Further note that we provide (unconventional) overloads for modifiable lvalues because these may match more generic overloads (below) taking a variable number of deduced template parameters.
References bslma::ConstructionUtil_Imp::construct(), bslma::ConstructionUtil_Imp::e_BITWISE_COPYABLE_TRAITS, and bslma::ConstructionUtil_Imp::e_NIL_TRAITS.
void bslma::ConstructionUtil::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator, | |||
bslmf::MovableRef< TARGET_TYPE > | original | |||
) | [inline, static] |
void bslma::ConstructionUtil::construct | ( | TARGET_TYPE * | address, | |
void * | allocator, | |||
bslmf::MovableRef< TARGET_TYPE > | original | |||
) | [inline, static] |
Create an object of (template parameter) TARGET_TYPE
, having the same value as the specified original
object, at the specified address
. original
is left in a valid but unspecified state. If the specified allocator
is of type bslma::Allocator
and TARGET_TYPE
supports bslma
-style allocation, allocator
is propagated to the newly created object. If a constructor throws, the memory at address
is left in an unspecified state. Note that this operation may elide the call to the copy constructor entirely if TARGET_TYPE
1) does not use bslma
-style allocators and 2) is trivially copyable. Further note that we provide (unconventional) overloads for modifiable lvalues because these may match more generic overloads (below) taking a variable number of deduced template parameters.
References BSLS_COMPILERFEATURES_FORWARD, bslma::ConstructionUtil_Imp::construct(), bslma::ConstructionUtil_Imp::e_BITWISE_COPYABLE_TRAITS, and bslma::ConstructionUtil_Imp::e_NIL_TRAITS.
void bslma::ConstructionUtil::construct | ( | TARGET_TYPE * | address, | |
bslma::Allocator * | allocator, | |||
ARG1 && | argument, | |||
ARGS &&... | arguments | |||
) | [inline, static] |
void bslma::ConstructionUtil::construct | ( | TARGET_TYPE * | address, | |
void * | allocator, | |||
ARG1 && | argument, | |||
ARGS &&... | arguments | |||
) | [inline, static] |
Create an object of (template parameter) TARGET_TYPE
at the specified address
, constructed by forwarding the specified argument
and the (variable number of) additional specified arguments
to the corresponding constructor of TARGET_TYPE
. If the specified allocator
is of type bslma::Allocator *
and TARGET_TYPE
supports bslma
-style allocation, the allocator is passed to the constructor (as the last argument). If the constructor throws, the memory at address
is left in an unspecified state.
References BSLS_COMPILERFEATURES_FORWARD, and bslma::ConstructionUtil_Imp::voidify().
void bslma::ConstructionUtil::destructiveMove | ( | TARGET_TYPE * | address, | |
ALLOCATOR * | allocator, | |||
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
, except that this method elides the calls to the constructor and destructor for objects that are bitwise movable. 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 and is not bitwise-movable, then original
will be only partially destroyed.
References BSLS_ASSERT_SAFE, bslma::ConstructionUtil_Imp::destructiveMove(), bslma::ConstructionUtil_Imp::e_BITWISE_MOVABLE_TRAITS, and bslma::ConstructionUtil_Imp::e_NIL_TRAITS.