Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an array of any type always an aggregate?

class A 
{
public:
    A(){}

private:
    int i;
};

A a[8];

The C++11 standard 8.5.1.1 says:

"An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no brace-or-equalinitializers for non-static data members (9.2), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3)."

As a is an array, is a an aggregate? I think not, but the standard says yes.

like image 248
xmllmx Avatar asked Dec 20 '12 15:12

xmllmx


People also ask

Is an array an aggregate?

5.5.The most common aggregate data type is an array. An array contains zero or more values of the same data type, such as characters, integers, floating point numbers, or fixed point numbers. An array may also be contain values of another aggregate data type. Every element in an array must have the same type.

What are the 3 types of arrays?

There are three different kinds of arrays: indexed arrays, multidimensional arrays, and associative arrays.

What is array and types of array?

An array type is a user-defined data type consisting of an ordered set of elements of a single data type. An ordinary array type has a defined upper bound on the number of elements and uses the ordinal position as the array index.

What is array and its types in data structure?

What Are Arrays in Data Structures? An array is a linear data structure that collects elements of the same data type and stores them in contiguous and adjacent memory locations. Arrays work on an index system starting from 0 to (n-1), where n is the size of the array.


1 Answers

Yes, A[8] is an aggregate type, even though A is not.

The notion of aggregate is not transitive, unlike some other related notions (such as "trivially copyable").

Loosely speaking, being an aggregate only impacts the type's initialization, and thus it does not need to be transitive. You can say A a[2] = { A('x', true), A(1, 2, 3) }; without needing to put restrictions on the nature of A. By contrast, notions like trivial copyability relate to a class's memory layout and thus by their very nature must be transitive.

like image 50
Kerrek SB Avatar answered Oct 19 '22 00:10

Kerrek SB