about max_size() function for vectors

What is the inner function for max_size() for vectors ?
Here i have this code:


1
2
3

size_t max_size() const noexcept { return std::numeric_limits<size_t>::max() / sizeof(value_type); }


why is std::numeric_limits defined on size_t only and not for double , int , float ?

can i write something like this:


1
2
3

double max_size() const noexcept { return std::numeric_limits<double>::max() / sizeof(value_type); }



> max_size() for vectors ?

max_size() for a container returns the theoretical maximum number of elements that the container can hold.


> can i write something like this: double max_size() const noexcept

No, if the container conforms to the requirements of a standard library compatible container.
It must return the size_type of the container; the size_type must be an unsigned integer type capable of holding the maximum theoretical value for the size() of the container.
Last edited on
Topic archived. No new replies allowed.