text stringlengths 0 2.2M |
|---|
// this proctor. If no memory is currently being managed, this
|
// method has no effect.
|
{
|
d_address_p = 0;
|
}
|
};
|
//..
|
// Then, we create a container class that holds a single element and uses
|
// 'bslma' allocators:
|
//..
|
#include <bslma_constructionutil.h>
|
template <class TYPE>
|
class MyContainer {
|
// This class provides a container that always holds exactly one
|
// element, dynamically allocated using the specified 'bslma'
|
// allocator.
|
// DATA
|
TYPE *d_value_p;
|
bslma::Allocator *d_allocator_p;
|
public:
|
// TRAITS
|
BSLMF_NESTED_TRAIT_DECLARATION(MyContainer, bslma::UsesBslmaAllocator);
|
// CREATORS
|
explicit MyContainer(bslma::Allocator *basicAllocator = 0);
|
// Create a container with a default-constructed element.
|
// Optionally specify a 'basicAllocator' used to supply memory. If
|
// 'basicAllocator' is 0, the currently installed default allocator
|
// is used.
|
template <class OTHER>
|
explicit MyContainer(
|
BSLS_COMPILERFEATURES_FORWARD_REF(OTHER) value,
|
typename bsl::enable_if<bsl::is_convertible<OTHER, TYPE>::value,
|
void *>::type * = 0)
|
// Create a container with an element constructed by (perfectly)
|
// forwarding the specified 'value' and that uses the currently
|
// installed default allocator to supply memory. Note that this
|
// constructor participates in overload resolution only if 'OTHER'
|
// is implicitly convertible to 'TYPE'.
|
: d_allocator_p(bslma::Default::defaultAllocator())
|
{
|
d_value_p =
|
static_cast<TYPE *>(d_allocator_p->allocate(sizeof(TYPE)));
|
MyContainerProctor<TYPE> proctor(d_allocator_p, d_value_p);
|
// Call 'construct' by forwarding 'value'.
|
bslma::ConstructionUtil::construct(
|
d_value_p,
|
d_allocator_p,
|
BSLS_COMPILERFEATURES_FORWARD(OTHER, value));
|
proctor.release();
|
}
|
template <class OTHER>
|
explicit MyContainer(
|
BSLS_COMPILERFEATURES_FORWARD_REF(OTHER) value,
|
bslma::Allocator *basicAllocator);
|
// Create a container with an element constructed by (perfectly)
|
// forwarding the specified 'value' and that uses the specified
|
// 'basicAllocator' to supply memory. If 'basicAllocator' is 0,
|
// the currently installed default allocator is used. Note that
|
// this constructor participates in overload resolution only if
|
// 'OTHER' is implicitly convertible to 'TYPE'.
|
MyContainer(const MyContainer& original,
|
bslma::Allocator *basicAllocator = 0);
|
// Create a container having the same value as the specified
|
// 'original' object. Optionally specify a 'basicAllocator' used
|
// to supply memory. If 'basicAllocator' is 0, the currently
|
// installed default allocator is used.
|
~MyContainer();
|
// Destroy this object.
|
// MANIPULATORS
|
MyContainer& operator=(const TYPE& rhs);
|
MyContainer& operator=(const MyContainer& rhs);
|
// Assign to this object the value of the specified 'rhs' object,
|
// and return a reference providing modifiable access to this
|
// object.
|
TYPE& front()
|
// Return a non-'const' reference to the element contained in this
|
// object.
|
{
|
return *d_value_p;
|
}
|
// ACCESSORS
|
const TYPE& front() const
|
// Return a 'const' reference to the element contained in this
|
// object.
|
{
|
return *d_value_p;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.