A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/deque/deque/max_size/ below:

public member function

<deque>

std::deque::max_size
size_type max_size() const;
size_type max_size() const noexcept;

Return maximum size

Returns the maximum number of elements that the deque container can hold.

This is the maximum potential size the container can reach due to known system or library implementation limitations, but the container is by no means guaranteed to be able to reach that size: it can still fail to allocate storage at any point before that size is reached.



Parameters none

Return Value The maximum number of elements a deque container can hold as content.

Member type size_type is an unsigned integral type.



Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// deque::max_size
#include <iostream>
#include <deque>

int main ()
{
  unsigned int i;
  std::deque<int> mydeque;

  std::cout << "Enter number of elements: ";
  std::cin >> i;

  if (i<mydeque.max_size()) mydeque.resize(i);
  else std::cout << "That size exceeds the limit.\n";

  return 0;
}

Here, member max_size is used to check beforehand whether the requested size will be allowed by resize.

Complexity Constant.

Iterator validity No changes.

Data races The container is accessed.
No contained elements are accessed: concurrently accessing or modifying them is safe.

Exception safetyNo-throw guarantee: this member function never throws exceptions.

See also
deque::size
Return size (public member function)
deque::resize
Change size (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4