I have understood that you were asking: what is the size of the memory occupied by the ensemble of the element of an array<value_type,N> arr
, that is between arr.begin()
and arr.end()
?
The answer is sizeof(value_type)*N
, this is stated in the standard, but it needs some processing to get to this conclusion.
In the C++ standard [dcl.array] (this is about (c-)array not std::array
):
An object of array type contains a contiguously allocated non-empty set of N subobjects of type T.
in [expr.add] (here also term array refers to (c-)array):
When an expression that has integral type is added to or subtracted from a pointer, the result has the type
of the pointer operand. If the expression P points to element x[i] of an array object x with n elements, 86
the expressions P + J and J + P (where J has the value j) point to the (possibly-hypothetical) element
x[i + j] if 0 ≤ i + j ≤ n; otherwise, the behavior is undefined. Likewise, the expression P - J points to the
(possibly-hypothetical) element x[i − j] if 0 ≤ i − j ≤ n; otherwise, the behavior is undefined.
And in [array.data] (here the term array refers to std::array
):
constexpr T* data() noexcept;
constexpr const T* data() const noexcept;
Returns: A pointer such that data() == addressof(front()), and [data(), data() + size()) is
a valid range.
So data()
return a valid range to the element of the std::array
, this range is iterable using a pointer to the value_type, so it follows pointer arithmetic which follows rule for (c-)array indexing, and elements of a (c-)array are contiguous. Q.E.D.
sizeof arr
? – Orthochromaticsizeof(arr)
– Actualizesizeof(my_raw_array)
. – Angele