public member function
<deque>
std::deque::atreference at (size_type n);const_reference at (size_type n) const;
Access element
Returns a reference to the element at position n in the deque container object.The function automatically checks whether n is within the bounds of valid elements in the container, throwing an out_of_range exception if it is not (i.e., if n is greater or equal than its size). This is in contrast with member operator[], that does not check against bounds.
The difference between this member function and member operator function operator[] is that deque::at signals if the requested position is out of range by throwing an out_of_range exception.
If the deque object is const-qualified, the function returns a const_reference. Otherwise, it returns a reference.
Member types reference and const_reference are the reference types to the elements of the container (see deque member types).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// deque::at
#include <iostream>
#include <deque>
int main ()
{
std::deque<unsigned> mydeque (10); // 10 zero-initialized unsigneds
// assign some values:
for (unsigned i=0; i<mydeque.size(); i++)
mydeque.at(i)=i;
std::cout << "mydeque contains:";
for (unsigned i=0; i<mydeque.size(); i++)
std::cout << ' ' << mydeque.at(i);
std::cout << '\n';
return 0;
}
mydeque contains: 0 1 2 3 4 5 6 7 8 9
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