public member function
<unordered_set>
std::unordered_multiset::operator= copy (1)unordered_multiset& operator= ( const unordered_multiset& ums );move (2)
unordered_multiset& operator= ( unordered_multiset&& ums );initializer list (3)
unordered_multiset& operator= ( intitializer_list<value_type> il );
Assign content
Assigns ums (or il) as the new content for the container.The elements contained in the object before the call are destroyed, and replaced by those in unordered_multiset ums or initializer list il, if any.
The first version (1) performs a copy assignment, which copies all the elements of ums into the container object (with ums preserving its contents).
The second version (2) performs a move assignment, which transfer ownership of the contents of ums to the object. No copies occur: the content is lost by ums.
The third version (3) assigns the contents of the initializer list il as the elements of the container object.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// unordered_multiset::operator=
#include <iostream>
#include <string>
#include <unordered_set>
template<class T>
T cmerge (T a, T b) {
T t(a); t.insert(b.begin(),b.end()); return t;
}
int main ()
{
std::unordered_multiset<std::string> first, second, third;
first = {"red","green","blue"}; // init list
second = {"red","yellow","blue"}; // init list
third = cmerge (first, second); // move
first = third; // copy
std::cout << "first contains:";
for (const std::string& x: first) std::cout << " " << x;
std::cout << std::endl;
return 0;
}
first contains: blue blue red red yellow green
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