Aggregate initialization creates an aggregate object from a brace-enclosed sequence of member initializers. Unlike an initializer list, the values may have different types and must follow member order. section 5.1.1
For a simple Card aggregate with an int followed by a Suit:
- Card card{2, Suit::Clubs}; initializes both members in declaration order. section 5.1.1
- Card card{2}; initializes the value and default-initializes the remaining suit member. section 5.1.1
- Card card{Suit::Clubs}; is not valid because omitted initializers may occur at the end, not at the beginning. section 5.1.1
- Using Suit::Clubs makes the construction clearer and less error-prone than supplying two integers. section 5.1.1
Initializing a deck
A fixed-size array can initialize selected elements with aggregate initialization: std::array<Card, 52> deck{Card{FaceValue(2), Suit::Hearts}}; places a two of hearts first and default-constructs the remaining cards. section 5.1.5
std::array<Card, 52> deck{Card{FaceValue(2), Suit::Hearts}};
Inspect a complete aggregate initializer that seeds an array with one card while leaving the remaining elements default-constructed. section 5.1.5
