Reputation: 4062
I am looking for the equivalent of .NET fixed size arrays in C++ and am having real trouble finding this information by Googling it. std::array
imitates Pascal by having the length embedded directly in its type. std::vector
is good, but passes around 3 pointers on the stack where I'd prefer just one.
Also rather than iterator based arrays, since I am working on a C++ backend for a functional language I'd prefer it to be size based so as too match the arrays in the .NET and the Cython backends.
Should I implement my own array class instead?
Edit: What I am asking for is a flexible array (such as this one) as a part of a library.
Upvotes: 0
Views: 1207
Reputation: 29985
You can use unique_ptr
:
#include <memory>
int main() {
// note brackets vvvv
std::unique_ptr<int[]> arr{ new int[42] };
arr[0] = 13;
// ...
}
Upvotes: 1