array_view icon indicating copy to clipboard operation
array_view copied to clipboard

Why is it not copy constructible / assignable?

Open aurelienrb opened this issue 8 years ago • 2 comments

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

aurelienrb avatar Jan 08 '17 23:01 aurelienrb

Also ran into this problem. Would be great if we could re-use array views.

Cyken-Zeraux avatar Apr 20 '17 19:04 Cyken-Zeraux

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.

rhysd avatar Apr 21 '17 01:04 rhysd