Vous êtes sur la page 1sur 19

class template

<utility>
std::pair
template <class T1, class T2> struct pair;
Pair of values
This class couples together a pair of values, which may be of different types (T1 and T2). The individual values can be accessed through its
public members first and second.
Pairs are a particular case of tuple.
Template parameters
T1
Type of member first, aliased as first_type.
T2
Type of member second, aliased as second_type.
Member types
member type
first_type

definition
The first template parameter (T1)

notes
Type of member first.

second_type

The second template parameter (T2)

Type of member second.

Member variables
member variable

definition

first

The first value in the pair

second

The second value in the pair

Member functions
(constructor)
Construct pair (public member function )
pair::operator=
Assign contents (public member function )
pair::swap
Swap contents (public member function )
Non-member function overloads
relational operators (pair)
Relational operators for pair (function template )
swap (pair)
Exchanges the contents of two pairs (function template )
get (pair)
Get element (tuple interface) (function template )
Non-member class specializations
tuple_element<pair>
Tuple element type for pair (class template specialization )
tuple_size<pair>
Tuple traits for pair (class template specialization )
See also
make_pair
Construct pair object (function template )
piecewise_construct
Piecewise construct constant (constant )
function template
<utility>
std::make_pair

C++98

C++11

template <class T1, class T2>


pair<T1,T2> make_pair (T1 x, T2 y);
Construct pair object
Constructs a pair object with its first element set to x and its second element set to y.
The template types can be implicitly deduced from the arguments passed to make_pair.
pair objects can be constructed from other pair objects containing different types, if the respective types are
implicitly convertible.

C++98

C++11

The behavior of this function template is the same as if defined as:


1 template <class T1,class T2>
2 pair<T1,T2> make_pair (T1 x, T2 y)
3 {
4
return ( pair<T1,T2>(x,y) );
5 }
Parameters
x, y
Values for the members first and second, respectively, of the pair object being constructed.
Return value
A pair object whose elements first and second are set to x and y respectivelly.
The template parameters can be implicitly deduced.
Example
1 // make_pair example
2 #include <utility>
// std::pair
3 #include <iostream>
// std::cout
4
5 int main () {
6 std::pair <int,int> foo;
7 std::pair <int,int> bar;
8
9 foo = std::make_pair (10,20);
10 bar = std::make_pair (10.5,'A'); // ok: implicit conversion from
11 pair<double,char>
12
13 std::cout << "foo: " << foo.first << ", " << foo.second << '\n';
14 std::cout << "bar: " << bar.first << ", " << bar.second << '\n';
15
16 return 0;
}
Output:
Data
races

foo: 10, 20
bar: 10, 65

Edit & Run

If either (or both) T1 or T2 is an rvalue reference type of a type supporting move semantics, its corresponding
argument is modified.
Exception safety
The function provides the same level of guarantees to each object as provided by the corresponding element
constructor.
Construct pair (public member function )
function template
<utility>
std::get (pair)

lvalue (1)

template <size_t I, class T1, class T2>


typename tuple_element< I, pair<T1,T2> >::type&

rvalue (2)

template <size_t I, class T1, class T2>


typename tuple_element< I, pair<T1,T2> >::type&& get (pair<T1,T2>&& pr) noexcept;

const (3)

get (pair<T1,T2>&

pr) noexcept;

template <size_t I, class T1, class T2>


const typename tuple_element< I, pair<T1,T2> >::type&
get (const pair<T1,T2>& pr) noexcept;

Get element (tuple interface)


Returns a reference to member first if I is 0, or a reference to member second if I is 1.
This overload of tuple's homonym function get is provided so that pair objects can be treated as a tuples. For
that purpose, header <utility> also overloads tuple_size and tuple_element types with the appropriate
members defined.
Template parameters
I
Position of an element in the pair, with 0 identifying member first, and 1 identifying member second.
size_t is an unsigned integral type.
T1, T2
Type of the elements in the pair.
Function parameters
pr
A pair object.
Return value
A reference to a member of the pair.
For rvalue pair objects (2), the function returns an rvalue reference (as if forward was used).
Example
1
2
3
4
5

6
7
8
9
10
11
12
13
14
// accessing pairs with get
#include <utility>
// std::pair, std::get
#include <iostream>
// std::cout
int main () {
std::pair <int,char> foo (10,'x');
std::get<0>(foo) = 50;
std::cout << "foo contains: ";
std::cout << std::get<0>(foo) << " and " << std::get<1>(foo) << '\n';
return 0;
}
Edit & Run
Output:
foo contains: 50 and x
Data races
One of the members of pr is potentially accessed or modified by the caller. Concurrently accessing the other is
safe.
Exception safety
No-throw guarantee: this function never throws exceptions.

header
<list>
List header
Header that defines the list container class:
Classes
list
List (class template )
Functions
begin
Iterator to beginning (function template )
end
Iterator to end (function template )
function template
<iterator> <array> <deque> <forward_list> <list> <map> <regex> <set> <string> <unordered_map>
<unordered_set> <vector>
std::begin

C++11

C++14
container (1) template <class Container>
auto begin (Container& cont) -> decltype
(cont.begin());
template <class Container>
auto begin (const Container& cont) -> decltype
(cont.begin());
array (2) template <class T, size_t N>
T* begin (T(&arr)[N]);

Iterator to beginning
Returns an iterator pointing to the first element in the sequence:
(1) Container
The function returns cont.begin().
(2) Array
The function returns the array-to-pointer conversion of its argument.
If the sequence is empty, the returned value shall not be dereferenced.
These function templates are defined in multiple headers: Each of these headers includes the generic templates for all container and array
types and not simply a specific overload. The headers
are: <iterator>, <array>, <deque>,<forward_list>, <list>, map, <regex>, <set>, <string>, <unordered_map>, <
unordered_set> and <vector>.
Conversely, begin is overloaded (with a different definition) in headers <initializer_list> and <valarray>.
Parameters

cont
An object of a class type for which member begin is defined.
arr
An array.
Return Value
For (1), the same as returned by cont.begin().
For (2), a pointer to the first element in the array.
Example
1 // std::begin / std::end example
2 #include <iostream>
// std::cout
3 #include <vector>
// std::vector, std::begin, std::end
4
5 int main () {
6 int foo[] = {10,20,30,40,50};
7 std::vector<int> bar;
8
9 // iterate foo: inserting into bar
10 for (auto it = std::begin(foo); it!=std::end(foo); ++it)
11
bar.push_back(*it);
12
13 // iterate bar: print contents:
14 std::cout << "bar contains:";
15 for (auto it = std::begin(bar); it!=std::end(bar); ++it)
16
std::cout << ' ' << *it;
17 std::cout << '\n';
18
19 return 0;
20 }
Output:
bar contains: 10 20 30 40 50

Edit & Run

Data races
The argument is accessed but not modified.
None of the elements in the sequence are accessed by the call, but the iterator returned can be used to access or modify them.
Exception safety
Provides the same level of guarantees as the operation performed on the argument (for standard containers and arrays this is a no-throw
guarantee).
function template
<iterator> <array> <deque> <forward_list> <list> <map> <regex> <set> <string> <unordered_map>
<unordered_set> <vector>
std::end

C++11

C++14

container (1)

array (2)

template <class Container>


auto end (Container& cont) -> decltype (cont.end());
template <class Container>
auto end (const Container& cont) -> decltype (cont.end());
template <class T, size_t N>
T* end (T(&arr)[N]);

Iterator to end
Returns an iterator pointing to the past-the-end element in the sequence:

(1) Container
The function returns cont.end().
(2) Array
The function returns arr+N.
If the sequence is empty, the returned value compares equal to the one returned by begin with the same argument.
These function templates are defined in multiple headers: Each of these headers includes the generic templates for all container and array
types and not simply a specific overload. The headers
are: <iterator>, <array>, <deque>,<forward_list>, <list>, map, <regex>, <set>, <string>, <unordered_map>, <
unordered_set> and <vector>.
Conversely, end is overloaded (with a different definition) in headers <initializer_list> and <valarray>.
Parameters
cont
An object of a class type for which member end is defined.
arr
An array.
Return Value
For (1), the same as returned by cont.end().
For (2), a pointer to the element that would follow the last element in the array.
Example
1 // std::begin / std::end example
2 #include <iostream>
// std::cout
3 #include <vector>
// std::vector, std::begin, std::end
4
5 int main () {
6 int foo[] = {10,20,30,40,50};
7 std::vector<int> bar;
8
9 // iterate foo: inserting into bar
10 for (auto it = std::begin(foo); it!=std::end(foo); ++it)
11
bar.push_back(*it);
12
13 // iterate bar: print contents:
14 std::cout << "bar contains:";
15 for (auto it = std::begin(bar); it!=std::end(bar); ++it)
16
std::cout << ' ' << *it;
17 std::cout << '\n';
18
19 return 0;
20 }
Output:
bar contains: 10 20 30 40 50

Edit & Run

Data races
The argument is accessed but not modified.
None of the elements in the sequence are accessed by the call, but the iterator returned can be used to access or modify them.
Exception safety
Provides the same level of guarantees as the operation performed on the argument (for standard containers and arrays this is a no-throw
guarantee).

class template
<queue>
std::queue
template <class T, class Container = deque<T> > class queue;
FIFO queue
queues are a type of container adaptor, specifically designed to operate in a FIFO context (first-in first-out), where elements are inserted into
one end of the container and extracted from the other.
queues are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as
its underlying container, providing a specific set of member functions to access its elements. Elements are pushed into the "back" of the
specific container and popped from its "front".
The underlying container may be one of the standard container class template or some other specifically designed container class. This
underlying container shall support at least the following operations:

empty

size

front

back

push_back

pop_front

The standard container classes deque and list fulfill these requirements. By default, if no container class is specified for a
particular queue class instantiation, the standard container deque is used.

Template parameters
T
Type of the elements.
Aliased as member type queue::value_type.
Container
Type of the internal underlying container object where the elements are stored.
Its value_type shall be T.
Aliased as member type queue::container_type.
Member types

C++98

C++11

member type
value_type

definition
The first template parameter (T)

notes
Type of the elements

container_type

The second template parameter (Container)

Type of the underlying container

size_type

an unsigned integral type

usually the same as size_t

Member functions
(constructor)
Construct queue (public member function )
empty
Test whether container is empty (public member function )
size
Return size (public member function )
front
Access next element (public member function )
back
Access last element (public member function )
push
Insert element (public member function )
emplace
Construct and insert element (public member function )
pop
Remove next element (public member function )
swap
Swap contents (public member function )

Non-member function overloads


relational operators
Relational operators for queue (function )
swap (queue)
Exchange contents of queues (public member function )

Non-member class specializations


uses_allocator<queue>
Uses allocator for queue (class template )
std::stack
template <class T, class Container = deque<T> > class stack;
LIFO stack
Stacks are a type of container adaptor, specifically designed to operate in a LIFO context (last-in first-out), where elements are inserted and
extracted only from one end of the container.
stacks are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as
its underlying container, providing a specific set of member functions to access its elements. Elements arepushed/popped from the "back" of
the specific container, which is known as the top of the stack.
The underlying container may be any of the standard container class templates or some other specifically designed container class. The
container shall support the following operations:

empty

size

back

push_back

pop_back

The standard container classes vector, deque and list fulfill these requirements. By default, if no container class is specified for a
particular stack class instantiation, the standard container deque is used.

Template parameters
T
Type of the elements.
Aliased as member type stack::value_type.
Container
Type of the internal underlying container object where the elements are stored.
Its value_type shall be T.
Aliased as member type stack::container_type.
Member types

C++98

C++11

member type
value_type

definition
The first template parameter (T)

Type of the elements

container_type

The second template parameter (Container)

Type of the underlying container

size_type

an unsigned integral type

usually the same as size_t

Member functions
(constructor)
Construct stack (public member function )
empty
Test whether container is empty (public member function )
size
Return size (public member function )
top
Access next element (public member function )
push
Insert element (public member function )
emplace
Construct and insert element (public member function )
pop
Remove top element (public member function )
swap
Swap contents (public member function )

Non-member function overloads


relational operators
Relational operators for stack (function )
swap (stack)
Exchange contents of stacks (public member function )

Non-member class specializations


uses_allocator<stack>
Uses allocator for stack (class template )

notes

std::set
template < class T,
class Compare = less<T>,
class Alloc = allocator<T>
> class set;
Set

// set::key_type/value_type
// set::key_compare/value_compare
// set::allocator_type

Sets are containers that store unique elements following a specific order.
In a set, the value of an element also identifies it (the value is itself the key, of type T), and each value must be unique. The value of the
elements in a set cannot be modified once in the container (the elements are always const), but they can be inserted or removed from the
container.
Internally, the elements in a set are always sorted following a specific strict weak ordering criterion indicated by its internal comparison
object (of type Compare).
set containers are generally slower than unordered_set containers to access individual elements by their key, but they allow the direct
iteration on subsets based on their order.
Sets are typically implemented as binary search trees.
Container properties
Associative
Elements in associative containers are referenced by their key and not by their absolute position in the container.
Ordered
The elements in the container follow a strict order at all times. All inserted elements are given a position in this order.
Set
The value of an element is also the key used to identify it.
Unique keys
No two elements in the container can have equivalent keys.
Allocator-aware
The container uses an allocator object to dynamically handle its storage needs.
Template parameters
T
Type of the elements. Each element in a set container is also uniquely identified by this value (each value is itself also the
element's key).
Aliased as member types set::key_type and set::value_type.
Compare
A binary predicate that takes two arguments of the same type as the elements and returns a bool. The expressioncomp(a,b),
where comp is an object of this type and a and b are key values, shall return true if a is considered to go before b in the strict
weak ordering the function defines.
The set object uses this expression to determine both the order the elements follow in the container and whether two element keys
are equivalent (by comparing them reflexively: they are equivalent if !comp(a,b) && !comp(b,a)). No two elements in
a set container can be equivalent.
This can be a function pointer or a function object (see constructor for an example). This defaults to less<T>, which returns the
same as applying the less-than operator (a<b).
Aliased as member types set::key_compare and set::value_compare.
Alloc
Type of the allocator object used to define the storage allocation model. By default, the allocator class template is used, which
defines the simplest memory allocation model and is value-independent.
Aliased as member type set::allocator_type.
Member types

C++98

C++11

member type
key_type

definition
The first template parameter (T)

notes

value_type

The first template parameter (T)

key_compare

The second template parameter (Compare)

defaults to: less<key_type>

value_compare

The second template parameter (Compare)

defaults to: less<value_type>

allocator_type

The third template parameter (Alloc)

defaults
to:allocator<value_type>

reference

allocator_type::reference

for the
default allocator:value_type&

const_reference

allocator_type::const_reference

for the
default allocator: const
value_type&

pointer

allocator_type::pointer

for the
default allocator:value_type*

const_pointer

allocator_type::const_pointer

for the
default allocator: const
value_type*

iterator

a bidirectional iterator to value_type

convertible
to const_iterator

a bidirectional iterator to const value_type


reverse_iterator
reverse_iterator<iterator>
const_reverse_iterator reverse_iterator<const_iterator>
const_iterator

difference_type

a signed integral type, identical


usually the same as ptrdiff_t
to:iterator_traits<iterator>::difference_type

size_type

an unsigned integral type that can represent any nonusually the same as size_t
negative value of difference_type

Member functions
(constructor)
Construct set (public member function )
(destructor)
Set destructor (public member function )
operator=
Copy container content (public member function )
Iterators:
begin
Return iterator to beginning (public member function )
end
Return iterator to end (public member function )
rbegin
Return reverse iterator to reverse beginning (public member function )
rend
Return reverse iterator to reverse end (public member function )
cbegin
Return const_iterator to beginning (public member function )
cend
Return const_iterator to end (public member function )
crbegin
Return const_reverse_iterator to reverse beginning (public member function )
crend
Return const_reverse_iterator to reverse end (public member function )
Capacity:
empty

Test whether container is empty (public member function )


size
Return container size (public member function )
max_size
Return maximum size (public member function )
Modifiers:
insert
Insert element (public member function )
erase
Erase elements (public member function )
swap
Swap content (public member function )
clear
Clear content (public member function )
emplace
Construct and insert element (public member function )
emplace_hint
Construct and insert element with hint (public member function )
Observers:
key_comp
Return comparison object (public member function )
value_comp
Return comparison object (public member function )
Operations:
find
Get iterator to element (public member function )
count
Count elements with a specific value (public member function )
lower_bound
Return iterator to lower bound (public member function )
upper_bound
Return iterator to upper bound (public member function )
equal_range
Get range of equal elements (public member function )
Allocator:
get_allocator
Get allocator (public member function )

class template
std::map
template < class Key,
class T,
class Compare = less<Key>,
class Alloc = allocator<pair<const Key,T> >
> class map;
Map

<map>
//
//
//
//

map::key_type
map::mapped_type
map::key_compare
map::allocator_type

Maps are associative containers that store elements formed by a combination of a key value and a mapped value, following a specific order.
In a map, the key values are generally used to sort and uniquely identify the elements, while the mapped values store the content associated
to this key. The types of key and mapped value may differ, and are grouped together in member typevalue_type, which is a pair type
combining both:
typedef pair<const Key, T> value_type;

Internally, the elements in a map are always sorted by its key following a specific strict weak ordering criterion indicated by its
internal comparison object (of type Compare).
map containers are generally slower than unordered_map containers to access individual elements by their key, but they allow the direct
iteration on subsets based on their order.
The mapped values in a map can be accessed directly by their corresponding key using the bracket operator ((operator[]).
Maps are typically implemented as binary search trees.

Container properties
Associative
Elements in associative containers are referenced by their key and not by their absolute position in the container.
Ordered
The elements in the container follow a strict order at all times. All inserted elements are given a position in this order.
Map
Each element associates a key to a mapped value: Keys are meant to identify the elements whose main content is the mapped value.
Unique keys
No two elements in the container can have equivalent keys.
Allocator-aware
The container uses an allocator object to dynamically handle its storage needs.
Template parameters
Key
Type of the keys. Each element in a map is uniquely identified by its key value.
Aliased as member type map::key_type.
T
Type of the mapped value. Each element in a map stores some data as its mapped value.
Aliased as member type map::mapped_type.
Compare
A binary predicate that takes two element keys as arguments and returns a bool. The expression comp(a,b), where comp is an
object of this type and a and b are key values, shall return true if a is considered to go before bin the strict weak ordering the
function defines.
The map object uses this expression to determine both the order the elements follow in the container and whether two element keys
are equivalent (by comparing them reflexively: they are equivalent if !comp(a,b) && !comp(b,a)). No two elements in
a map container can have equivalent keys.
This can be a function pointer or a function object (see constructor for an example). This defaults to less<T>, which returns the
same as applying the less-than operator (a<b).
Aliased as member type map::key_compare.
Alloc

Type of the allocator object used to define the storage allocation model. By default, the allocator class template is used, which
defines the simplest memory allocation model and is value-independent.
Aliased as member type map::allocator_type.
Member types

C++98

C++11

member type
key_type

definition
The first template parameter (Key)

notes

mapped_type
value_type

The second template parameter (T)


pair<const key_type,mapped_type>

key_compare

The third template parameter (Compare)

defaults to: less<key_type>

value_compare

Nested function class to compare elements

allocator_type

The fourth template parameter (Alloc)

see value_comp
defaults
to:allocator<value_type>

reference

allocator_type::reference

for the
default allocator:value_type&

const_reference

allocator_type::const_reference

for the
default allocator: const
value_type&

pointer

allocator_type::pointer

for the
default allocator:value_type*

const_pointer

allocator_type::const_pointer

for the
default allocator: const
value_type*

iterator

a bidirectional iterator to value_type

convertible
to const_iterator

a bidirectional iterator to const value_type


reverse_iterator
reverse_iterator<iterator>
const_reverse_iterator reverse_iterator<const_iterator>
const_iterator

difference_type

a signed integral type, identical


usually the same as ptrdiff_t
to:iterator_traits<iterator>::difference_type

size_type

an unsigned integral type that can represent any nonusually the same as size_t
negative value of difference_type

Member functions
(constructor)
Construct map (public member function )
(destructor)
Map destructor (public member function )
operator=
Copy container content (public member function )
Iterators:
begin
Return iterator to beginning (public member function )
end
Return iterator to end (public member function )
rbegin

Return reverse iterator to reverse beginning (public member function )


rend
Return reverse iterator to reverse end (public member function )
cbegin
Return const_iterator to beginning (public member function )
cend
Return const_iterator to end (public member function )
crbegin
Return const_reverse_iterator to reverse beginning (public member function )
crend
Return const_reverse_iterator to reverse end (public member function )
Capacity:
empty
Test whether container is empty (public member function )
size
Return container size (public member function )
max_size
Return maximum size (public member function )
Element access:
operator[]
Access element (public member function )
at
Access element (public member function )
Modifiers:
insert
Insert elements (public member function )
erase
Erase elements (public member function )
swap
Swap content (public member function )
clear
Clear content (public member function )
emplace
Construct and insert element (public member function )
emplace_hint
Construct and insert element with hint (public member function )
Observers:
key_comp
Return key comparison object (public member function )
value_comp
Return value comparison object (public member function )
Operations:
find
Get iterator to element (public member function )
count
Count elements with a specific key (public member function )
lower_bound
Return iterator to lower bound (public member function )

upper_bound
Return iterator to upper bound (public member function )
equal_range
Get range of equal elements (public member function )
Allocator:
get_allocator
Get allocator (public member function )
public member function
<map>
std::map::map

C++98

C++11

C++14

empty (1)

range (2)

copy (3)

explicit map (const key_compare& comp = key_compare(),


const allocator_type& alloc = allocator_type());
template <class InputIterator>
map (InputIterator first, InputIterator last,
const key_compare& comp = key_compare(),
const allocator_type& alloc = allocator_type());
map (const map& x);

Construct map
Constructs a map container object, initializing its contents depending on the constructor version used:

C++98

C++11

(1) empty container constructor (default constructor)


Constructs an empty container, with no elements.
(2) range constructor
Constructs a container with as many elements as the range [first,last), with each element constructed from its
corresponding element in that range.
(3) copy constructor
Constructs a container with a copy of each of the elements in x.
The container keeps an internal copy of alloc and comp, which are used to allocate storage and to sort the elements throughout its lifetime.
The copy constructor (3) creates a container that keeps and uses copies of x's allocator and comparison object.
The storage for the elements is allocated using this internal allocator.
The elements are sorted according to the comparison object. If more than one element with equivalent keys is passed to the constructor, only
the first one is preserved.
Parameters
comp
Binary predicate that, taking two element keys as argument, returns true if the first argument goes before the second argument in
the strict weak ordering it defines, and false otherwise.
This shall be a function pointer or a function object.
Member type key_compare is the internal comparison object type used by the container, defined in map as an alias of its third

template parameter (Compare).


If key_compare uses the default less (which has no state), this parameter is not relevant.
alloc
Allocator object.
The container keeps and uses an internal copy of this allocator.
Member type allocator_type is the internal allocator type used by the container, defined in map as an alias of its fourth
template parameter (Alloc).
If allocator_type is an instantiation of the default allocator (which has no state), this parameter is not relevant.
first, last
Input iterators to the initial and final positions in a range. The range used is [first,last), which includes all the elements
between first and last, including the element pointed by first but not the element pointed by last.
The function template argument InputIterator shall be an input iterator type that points to elements of a type from
which value_type objects can be constructed (in map, value_type is an alias of pair<const key_type,
mapped_type>)
x
Another map object of the same type (with the same class template arguments Key, T, Compare and Alloc), whose contents are
either copied or acquired.
il
An initializer_list object.
These objects are automatically constructed from initializer list declarators.
Member type value_type is the type of the elements in the container, defined in map as an alias of pair<const
key_type, mapped_type> (see map types).
Example
1 // constructing maps
2 #include <iostream>
3 #include <map>
4
5 bool fncomp (char lhs, char rhs) {return lhs<rhs;}
6
7 struct classcomp {
8 bool operator() (const char& lhs, const char& rhs) const
9 {return lhs<rhs;}
10 };
11
12 int main ()
13 {
14 std::map<char,int> first;
15
16 first['a']=10;
17 first['b']=30;
18 first['c']=50;
19 first['d']=70;
20
21 std::map<char,int> second (first.begin(),first.end());
22
23 std::map<char,int> third (second);
24
25 std::map<char,int,classcomp> fourth;
// class as Compare
26
27 bool(*fn_pt)(char,char) = fncomp;
28 std::map<char,int,bool(*)(char,char)> fifth (fn_pt); // function pointer as
29 Compare
30
31 return 0;
}

The code does not produce any output, but demonstrates some ways in which a map container can be constructed.
Complexity

Edit & Run

Constant for the empty constructors (1), and for the move constructors (4) (unless alloc is different from x's allocator).
For all other cases, linear in the distance between the iterators (copy constructions) if the elements are already sorted according to the same
criterion. For unsorted sequences, linearithmic (N*logN) in that distance (sorting,copy constructions).
Iterator validity
The move constructors (4), invalidate all iterators, pointers and references related to x if the elements are moved.
Data races
All copied elements are accessed.
The move constructors (4) modify x.
Exception safety
Strong guarantee: no effects in case an exception is thrown.
If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if the range specified
by [first,last) is not valid, it causes undefined behavior.
See also
map::operator=
Copy container content (public member function )
map::insert
Insert elements (public member function )

Vous aimerez peut-être aussi