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

前端 未结 5 1020
孤街浪徒
孤街浪徒 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 17:46

    For interested in C++03 (and also C) solution - always use struct containing an array instead of solely array:

    struct s { float arr[5]; };
    

    Structs are copyable by default.

    Its equivalent in C++11 is,already mentioned, std::array;

提交回复
热议问题