emplace(): This function is available in the File: unordered_set.h
Syntax:
template<class... _Args> std::pair<std::__detail::_Node_iterator<int, true, false>, bool> std::unordered_set<int>::emplace(_Args &&...__args).
This functions takes one argument as its parameter. This function attempts to build and insert an element into the unordered_set. This function inserts a new element in the unordered_set if its value is unique.
Note: If inserted, this effectively increases the container size by one.
Parameters: One parameter is required for this function.
__args – Arguments used to generate an element.
Returns:
A pair, of which the first element is an iterator that points to the possibly inserted element, and the second is a bool that is true if the element was actually inserted. This function attempts to build and insert an element into the unordered_set.
Note: Insertion requires amortized constant time.
File: unordered_set.h
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){unordered_set<int> st = {9, 4};st.emplace(10);cout << st.size() << "\n";return 0;}
Output:
3
No comments:
Post a Comment