Merge multiple sets elements in a single set

后端 未结 4 1267
一整个雨季
一整个雨季 2020-12-24 00:09

I would like to know if there is any std library or boost tool to easily merge the contents of multiple sets into a single one.

In my case I have some sets of ints w

4条回答
  •  情歌与酒
    2020-12-24 00:58

    Looks like you are asking for std::set_union.

    Example:

    #include 
    #include 
    
    std::set s1; 
    std::set s2; 
    std::set s3;
    
    // Fill s1 and s2 
    
    std::set_union(std::begin(s1), std::end(s1),
                   std::begin(s2), std::end(s2),                  
                   std::inserter(s3, std::begin(s3)));
    
    // s3 now contains the union of s1 and s2
    

提交回复
热议问题