Given this struct:
struct Foo {
std::array<int, 8> bar;
}
How can I get the number of elements of the bar array if I don't have an instance of Foo?
|
You may use
|
|||||
|
|
Despite the good answer of @Jarod42, here is another possible solution based on
|
|||||||||||||||||
|
|
You could give
Now you know the size of bar from |
|||
|
|
|
You could do it the same as for legacy arrays:
|
|||||||||||||||||||||
|
|
Use:
|
|||||||||||||||||
|
|
You can use like:
|
|||||||||||||||||||||
|
std::arraydoesn't shrink or grow. It will always be 8 constructed objects. – StoryTeller 21 hours agostd::array<int, 8>you ever have a container with 8 elements; you can set the value of 4 of this elements (after the initialization) but the other 4 are present with initial value – max66 20 hours ago