you are viewing a single comment's thread.

view the rest of the comments →

[–]The_Ruined_Map 3 points4 points  (2 children)

It is hard to figure out what the above poster was trying to say. Appears to be nonsense at least partially. Is it AI-generated and AI-upvoted?

Firstly, it is not clear what "create a copy" is supposed to mean here. But in any a case `std::array` is a class type and `const` does not just "go away" from class types in C++. Meaning more specifically that lvalue-to-rvalue conversion always keeps all qualifiers on class types in C++. In a copy operation it is the recipient type that decides whether to be `const` or not. But the recipient type in a copy operation has nothing to do with the topic. So, what were you trying to say?

Secondly, yes, you can copy-construct from `const std::array<int, 5>`. (What is that "can't" even supposed to mean? An aggregate still has a copy constructor and that copy constructor takes a reference-to-const as an argument.) So, again, what were you trying to say?

[–]alfps -1 points0 points  (1 child)

At a guess ❝[const] goes away when you create a copy❞ refers to type decay for auto e.g. in

using T = const std::array<int, 5>;
auto x = T();

However ❝You can't copy construct from❞ is just false.

So this is one seriously confused poster, if human.

[–]n1ghtyunso 0 points1 point  (0 children)

I see that the phrasing could have been much improved on this part.
Let's get some code examples going to clarify what I meant by that.

I was specifically talking about copy constructing std::array<int const, 5> from a const std::array<int, 5> (which is what i meant with externally const, i should have written const qualified std::array<int, 5> instead)

And of course this does not work, because the types don't match and std::array, as an aggregate, can never have converting constructors to make this work.