BDE 4.14.0 Production release
|
Provide an STL compliant array.
Canonical header: bsl_array.h
This component defines a single class template, bsl::array
, implementing the standard container std::array
, holding a non-resizable array of values of a template parameter type where the size is specified as the second template parameter.
An instantiation of array
is a value-semantic type whose salient attributes are its size and the sequence of values the array contains. If array
is instantiated with a value type that is not value-semantic, then the array will not retain all of its value-semantic qualities. In particular, if a value type cannot be tested for equality, then an array
containing objects of that type will fail to compile the equality comparison operator. Similarly, if an array
is instantiated with a type that does not have a copy-constructor, then the array
will not be copyable.
An array meets most the requirements of a container with random access iterators in the C++ standard [array]. The array
implemented here follows the C++11 standard when compiled with a C++11 compiler and follows the C++03 standard otherwise.
An array lacks certain requirements of a sequential container. Array lacks insert
, erase
, emplace
, and clear
, as these functions would require modifying the size of the array.
An array also meets the requirements of an aggregate. This means that an array has: no user-declared constructors, no private or protected non-static data members, no base classes, and no virtual functions. An array can be constructed using aggregate initialization. Refer to the section [del.init.aggr] in the C++ standard for more detailed information.
This section describes the run-time complexity of operations on instances of array
:
The comparison operator performs a bit-wise comparison for floating point types (float
and double
), which produces results for NaN, +0, and -0 values that do not meet the guarantees provided by the standard. The bslmf::IsBitwiseEqualityComparable
trait for double
and float
types returns true
which is incorrect because a comparison with a NaN value is always false
, and -0 and +0 are equal.
Addressing this issue, i.e., updating bslmf::IsBitwiseEqualityComparable
to return false
for floating point types, could potentially destabilize production software so the change (for the moment) has not been made.
In this section we show intended use of this component.
Suppose we want to define a function that will return an array of float
s. If a raw array were used, the size would need to be tracked separately because raw arrays decay to pointers when passed as function arguments, or returned by-value. bsl::array
does not decay, and so provides a simple solution to this problem.
Create a bsl::array object containing three values set to the specified f1
, f2
, f3
.
Use the createPoint function to generate three arrays of floats. The arrays are returned by copy and the size()
member function is used to access the size of the arrays that could not be done with a raw array.