Const boost :: array <T, N> or boost :: array <const T, N>?

What is the difference between the two? Which one would you prefer if you need an array of fixed-size constant values?

const boost::array<int, 2> x = {0, 1};
boost::array<const int, 2> y = {0, 1};

Thank.

+5
source share
3 answers

The second method will allow you to copy it to a new non-constant array

boost::array<const int, 2> y = {0, 1};
boost::array<int, 2> y1 = y; // error!

Since I would expect that to work, I will probably go with the first option. Passing a second template, expecting that boost::array<T, N>it will not allow these templates to change their parameter (even if it is a copy). The first will be β€œjust working,” since the parameter will be of type boost::array<int, 2>.

+6
source

.

assign const array, , . array<const T>, assign.

, const array C-. , , , array<const T>.

+2

A const int int . array<int,2>, array<const int, 2>. int , . array<const MyClass, 2> -const .
const array<MyClass, 2> , -, . , , , , operator[].

0

All Articles