BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslalg_arraydestructionprimitives

Typedefs

typedef bslalg::ArrayDestructionPrimitives bslalg_ArrayDestructionPrimitives
 This alias is defined for backward compatibility.
 

Detailed Description

Outline

Purpose

Provide primitive algorithms that destroy arrays.

Classes

See also
bslma_destructionutil, bslma_constructionutil

Description

This component provides utilities to destroy arrays with a uniform interface, but selecting a different implementation according to the traits possessed by the underlying type.

The traits under consideration by this component are:

Trait Note
----- -------------------------------------
bslmf::IsBitwiseCopyable Expressed in English as "TYPE has the
bit-wise copyable trait", or "TYPE is
bit-wise copyable", this trait also
implies that destructor calls can be
elided with no effect on observable
behavior.
Definition bslmf_isbitwisecopyable.h:298

Usage

TBD: maybe fix up usage example to show with allocator In this section we show intended use of this component. Note that this component is for use by the bslstl package. Other clients should use the STL algorithms (in header <algorithm> and <memory>).

Example 1: Destroy Arrays of int and Integer Wrapper Objects

In this example, we will use bslalg::ArrayDestructionPrimitives to destroy both an array of integer scalars and an array of MyInteger objects. Calling the destroy method on an array of integers is a no-op while calling the destroy method on an array of objects of MyInteger class invokes the destructor of each of the objects in the array.

First, we define a MyInteger class that contains an integer value:

/// This class represents an integer value.
class MyInteger {
int d_intValue; // integer value
public:
// CREATORS
/// Create a `MyInteger` object having integer value `0`.
MyInteger();
/// Create a `MyInteger` object having the specified `value`.
explicit MyInteger(int value);
/// Destroy this object.
~MyInteger();
// ACCESSORS
/// Return the integer value contained in this object.
int getValue() const;
};

Then, we create an array of objects, myIntegers, of type MyInteger (note that we bsls::ObjectBuffer to allow us to safely invoke the destructor explicitly):

MyInteger *myIntegers = &arrayBuffer[0].object();
for (int i = 0;i < 5; ++i) {
new (myIntegers + i) MyInteger(i);
}
Definition bsls_objectbuffer.h:276
TYPE & object()
Definition bsls_objectbuffer.h:351

Now, we define a primitive integer array:

int scalarIntegers[] = { 0, 1, 2, 3, 4 };

Finally, we use the uniform bslalg::ArrayDestructionPrimitives:destroy method to destroy both myIntegers and scalarIntegers:

bslalg::ArrayDestructionPrimitives::destroy(myIntegers, myIntegers + 5);
scalarIntegers + 5);
static void destroy(TARGET_TYPE *begin, TARGET_TYPE *end, ALLOCATOR allocator, bsl::true_type)
Definition bslalg_arraydestructionprimitives.h:232

Typedef Documentation

◆ bslalg_ArrayDestructionPrimitives