lightxbulb
lightxbulb

Reputation: 1321

Copy static array in constructor

Is there a compile time expression to copy an array in an object constructor? What does the default constructor use? I want something like this:

struct A
{
    int arr[100];
    // I want something like this:
    A(const A& arg) : arr{arg.arr...} {}
    // what I use at the moment (a compile time loop):
    A(const A& arg)
    {
        static_for<0, N>([&](auto i) { arr[i] = arg.arr[i]; });
    }
};

I do not want to use std::array, and I have some debug info in the copy ctor, so I cannot rely on the default one.

Upvotes: 1

Views: 337

Answers (1)

darune
darune

Reputation: 11000

AFAIK there is only the loop based solution for now if I understand correctly how you framed the question - at least as of now

From there is constexpr version of copy_n

Other users should just use a proper container: std::array

Upvotes: 5

Related Questions