Cleanest way to copy a constant size array in c++11

前端 未结 5 1029
孤街浪徒
孤街浪徒 2020-12-13 17:29

I often find myself wanting to copy the contents of arrays that have a constant size, I usually just write something along the lines of:

float a[4] = {0,1,2,         


        
5条回答
  •  误落风尘
    2020-12-13 18:02

    If you use std::array instead of a built-in array (which you should), it becomes very simple. Copying an array is then the same as copying any other object.

    std::array a = {0,1,2,3};
    std::array b = a;
    

提交回复
热议问题