Is there any practical difference between std::array<const T, N>
and const std::array<T, N>
?
It looks that non-const array holding const elements is still not able to be swapped; assignment operator is not working either.
When should I prefer one over the other one?
#include <array>
std::array<const int, 5> array_of_const = {1,2,3,4,5};
std::array<const int, 5> array_of_const2 = {1,2,3,4,5};
const std::array<int, 5> const_array = {1,2,3,4,5};
const std::array<int, 5> const_array2 = {1,2,3,4,5};
int main()
{
// Assignment doesn't work for either
array_of_const = array_of_const2;
const_array = const_array2;
// Swapping doesn't work for either
array_of_const.swap(array_of_const2);
const_array.swap(const_array2);
// Indexing...
array_of_const[0] = 0;
const_array[0] = 0;
return 0;
};
[language-lawyer]
is not added by OP actually