The syntax std::unique_ptr<T[]> can be used describe the (templated) type of a unique_ptr whose underlying raw pointer is pointing to an array of Ts. I'm wondering what the syntax T[] means generally. Does it get used outside of smart pointers? Is it possible for e.g. vector<T[]> to ever be useful?
Add a comment
|
1 Answer
It means "array of unknown bound of T". You might see such a type in function signatures:
void f(int arr[]);
In a declaration of an array defined elsewhere:
extern int arr[];
And obviously, as a type parameter to a template like unique_ptr (or, some time in the future, shared_ptr too). It's an incomplete type, so its usefulness can be rather limited.
vector<T[]> is unlikely to be useful. If you don't know how many elements are in the array, then how could you have a container of them?
1 Comment
Johan Lundberg
It surprisingly possible to have an std::vector<int[]> but it seems impossible to use, and the copy semantics would not work.