C++ boost::unordered_set::emplace














































C++ boost::unordered_set::emplace



Description:-

boost::unordered_set::emplace
function is used to inserts a new element in the unordered_set
if its value is unique. This new element is constructed in
place using args as the arguments for the element's
constructor.


Syntax:-

setname.emplace(arg);


parameters:-

Arguments passed to the constructor of the a new element to be inserted


sample code:-


#include<iostream>

#include<string>

#include<unordered_set>

int main ()

{
     std::unordered_set<std::string> cset;   // Declaration of the unordered_set



       cset.emplace("sachin");                         // inserting the element into set

       cset.emplace("rahul");                          // inserting the element into set

      cset.emplace("dhawan");                      // inserting the element into set



      std::cout<< "cset contains:";

    for(const std::string& x: cset) std::cout << " " <<x;



    std::cout<< std::endl;

      return 0;


}


output : cset contains : dhawan sachin rahul










Comments