目录

operator<

描述 (Description)

C ++函数std::map::operator《测试第一个映射是否小于其他映射。

运算符

声明 (Declaration)

以下是std :: map :: operator

C++98

template <class Key, class T, class Compare, class Alloc>
bool operator< ( const map<Key,T,Compare,Alloc>& m1,
                  const map<Key,T,Compare,Alloc>& m2);

参数 (Parameters)

  • m1 - 第一个地图对象。

  • m2 - 第二个地图对象。

返回值

如果第一个map小于秒,则返回true,否则返回false。

异常 (Exceptions)

此函数不会抛出异常。

时间复杂

线性即O(n)

例子 (Example)

以下示例显示了std :: map :: operator

#include <iostream>
#include <map>
using namespace std;
int main(void) {
   map<char, int> m1;
   map<char, int> m2;
   m2.emplace('a', 1);
   if (m1 < m2)
      cout << "Map m1 is less than m2." << endl;
   m1 = m2;
   if (!(m1 < m2))
      cout << "Map m1 is not less than m2." << endl;
   return 0;
}

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

Map m1 is less than m2.
Map m1 is not less than m2.
↑回到顶部↑
WIKI教程 @2018