What is difference between these two? Which one you would prefer when you need a fixed size array of constant values?
const boost::array<int, 2> x = {0, 1};
boost::array<const int, 2> y = {0, 1};
Thanks.
The second one will prevent that you copy it to a new non-const array
boost::array<const int, 2> y = {0, 1};
boost::array<int, 2> y1 = y; // error!
Since I would expect that to work, I would probably go with the first option. Passing the second one to templates that expect a boost::array<T, N>
will prevent those templates from modifying their parameter (even if it's a copy). The first one would "just work", since the parameter would have the type boost::array<int, 2>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With