@@ -576,7 +576,7 @@ Item martha { "Martha", 30 };
576
576
Item george { "George", 40 };
577
577
```
578
578
579
- Move the data into a container e.g. `constexpr std::array `, not a vector or map.
579
+ Move the data into a container e.g. `constexpr std::initializer_list `, not a vector or map.
580
580
581
581
Container elements are typically value, array, pair, tuple, or a defined struct.
582
582
Pair and tuple should only be used for very short lived data, such as this case:
@@ -585,13 +585,11 @@ Pair and tuple should only be used for very short lived data, such as this case:
585
585
```cpp
586
586
using Pair = std::pair<std::string_view, size_t>;
587
587
588
- constexpr auto numItems {3};
589
-
590
- constexpr std::array<Pair, numItems> items {{
588
+ constexpr std::initializer_list<Pair> items {
591
589
{ "Fred", 20 },
592
590
{ "Martha", 30 },
593
591
{ "George", 40 }
594
- }} ;
592
+ };
595
593
```
596
594
{% endraw %}
597
595
@@ -604,13 +602,11 @@ struct Button {
604
602
size_t width;
605
603
};
606
604
607
- constexpr auto numButtons {3};
608
-
609
- constexpr std::array<Button, numButtons> buttonDefs {{
605
+ constexpr std::initializer_list<Button> buttonDefs {
610
606
{ "Go", 25, 25 },
611
607
{ "Get set", 20, 20 },
612
608
{ "On your marks", 15, 15 }
613
- }} ;
609
+ };
614
610
```
615
611
{% endraw %}
616
612
When in doubt, use a struct - it is better to have good names than not.
0 commit comments