3

I mean something like this:

std::vector<T> v(0);

Is it ok? I don't see any requirements like this in the Standard.

1
  • There's more than one non-default constructor. Commented Jul 11, 2017 at 5:42

1 Answer 1

6

This is well-defined. The standard does not place any restrictions on the value of n passed to this constructor. 0 is a valid value of type size_type (whatever that is).

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

2 Comments

The standard specifies size_type to be an unsigned integer type. In reality this is unsigned long (at least for stdlibc++).
@henri: implementation defined. Msvc in 64 bits mode doesn't, as it would limit the container size to 4 billion.

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.