array_view
array_view copied to clipboard
Why is it not copy constructible / assignable?
Hello,
Reassigning an existing array_view
is forbidden:
array_view& operator=(array_view const&) noexcept = delete;
array_view& operator=(array_view &&) noexcept = delete;
Preventing the following usage:
array_view<int> view;
// ...
std::vector<int> v{ 1, 2, 3 };
view = make_view(v); // error: attempting to reference a deleted function
I wish I could use array_view
the same way I am using string_view
... Is there a reason for that?
Aurelien
Also ran into this problem. Would be great if we could re-use array views.
I can't remember why actually... but I think it's because members of array_view
are const
qualified. array_view
represents fixed length view for various arrays. So its length is fixed with const
. So, when considering assignment, we can't assign length of a1
into length of a2
where a2 = a1
.