public member function
<set>
std::set::emplace_hinttemplate <class... Args> iterator emplace_hint (const_iterator position, Args&&... args);
Construct and insert element with hint
Inserts a new element in the set, if unique, with a hint on the insertion position. This new element is constructed in place using args as the arguments for its construction.The insertion only takes place if no other element in the container is equivalent to the one being emplaced (elements in a set container are unique).
If inserted, this effectively increases the container size by one.
The value in position is used as a hint on the insertion point. The element will nevertheless be inserted at its corresponding position following the order described by its internal comparison object, but this hint is used by the function to begin its search for the insertion point, speeding up the process considerably when the actual insertion point is either position or close to it.
The element is constructed in-place by calling allocator_traits::construct with args forwarded.
Otherwise, it returns an iterator to the equivalent element within the container.
Member type iterator is a bidirectional iterator type that points to an element.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// set::emplace_hint
#include <iostream>
#include <set>
#include <string>
int main ()
{
std::set<std::string> myset;
auto it = myset.cbegin();
myset.emplace_hint (it,"alpha");
it = myset.emplace_hint (myset.cend(),"omega");
it = myset.emplace_hint (it,"epsilon");
it = myset.emplace_hint (it,"beta");
std::cout << "myset contains:";
for (const std::string& x: myset)
std::cout << ' ' << x;
std::cout << '\n';
return 0;
}
Output:
myset contains: alpha beta epsilon omega
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