0

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?

0

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

1 Comment

It surprisingly possible to have an std::vector<int[]> but it seems impossible to use, and the copy semantics would not work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.