I have a populated std::array with meaningful data and a std::array with 0s. I wish to assign the array of 6 to the array of 8. What is the idiomatic way of doing this in c++?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use
std::copyif the destination array is larger than the source one:If the destination array is shorter, then you’ll have to copy up to a certain point. I mean, you can still do this using
std::copy, but you’ll have to do something like:This works for both cases: