mercredi 1 février 2017

stack_array in C++ Core Guidelines

The C++ Core Guidelines mention something called a stack_array. Its usage looks like:

const int n = 7;
int m = 9;

void f()
{
    std::array<int, n> a1;
    stack_array<int> a2(m);  // A stack-allocated array.
                             // The number of elements are determined
                             // at construction and fixed thereafter.
    // ...
}

But how can such a class be implemented? How can we dynamically determine the stack size at run time?

Aucun commentaire:

Enregistrer un commentaire