目录

swap

描述 (Description)

它通过ust的内容交换容器的内容,ust是另一个包含相同类型元素的unordered_set对象。 尺寸可能不同。

声明 (Declaration)

以下是std :: unordered_set :: swap的声明。

C++11

void swap ( unordered_set& ust );

参数 (Parameters)

ust - 另一个un order set。

返回值

没有

异常 (Exceptions)

如果任何元素比较对象抛出异常,则抛出异常。

请注意,无效参数会导致未定义的行为。

时间复杂

恒定时间。

例子 (Example)

以下示例显示了std :: unordered_set :: swap的用法。

#include <iostream>
#include <string>
#include <unordered_set>
int main () {
   std::unordered_set<std::string>
      first = {"sai","ram","krishna"},
      second  = {"tutorials","point",".com"};
   first.swap(second);
   std::cout << "first:";
   for (const std::string& x: first) std::cout << " " << x;
   std::cout << std::endl;
   std::cout << "second:";
   for (const std::string& x: second) std::cout << " " << x;
   std::cout << std::endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

first: .com tutorials point
second: sai krishna ram
↑回到顶部↑
WIKI教程 @2018