hash_set::lower_bound

说明说明

此 API 已过时。另一种方法是 unordered_set Class

返回迭代器到一 hash_set 的第一个元素与等于或大于指定的键的键。

const_iterator lower_bound(
   const Key& _Key
) const;
iterator lower_bound(
   const Key& _Key
);

参数

  • _Key
    参数键与一个元素的排序关键字进行比较从要搜索的 hash_set 的。

返回值

解决一个元素位置。hash_set 的密钥等于或大于参数键或解决成功最后一个元素的位置。hash_set 的 迭代器const_iterator,如果与未作为项中。

备注

在 Visual C++ .NET 2003 中,<hash_map><hash_set> 标头文件的成员中不再标准,命名空间,而是将 stdext 命名空间。有关更多信息,请参见 stdext 命名空间

示例

// hash_set_lower_bound.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_set <int> hs1;
   hash_set <int> :: const_iterator hs1_AcIter, hs1_RcIter;
   
   hs1.insert( 10 );
   hs1.insert( 20 );
   hs1.insert( 30 );

   hs1_RcIter = hs1.lower_bound( 20 );
   cout << "The element of hash_set hs1 with a key of 20 is: "
        << *hs1_RcIter << "." << endl;

   hs1_RcIter = hs1.lower_bound( 40 );

   // If no match is found for the key, end( ) is returned
   if ( hs1_RcIter == hs1.end( ) )
      cout << "The hash_set hs1 doesn't have an element "
           << "with a key of 40." << endl;
   else
      cout << "The element of hash_set hs1 with a key of 40 is: "
           << *hs1_RcIter << "." << endl;

   // An element at a specific ___location in the hash_set can be found 
   // by using a dereferenced iterator that addresses the ___location
   hs1_AcIter = hs1.end( );
   hs1_AcIter--;
   hs1_RcIter = hs1.lower_bound( *hs1_AcIter );
   cout << "The element of hs1 with a key matching "
        << "that of the last element is: "
        << *hs1_RcIter << "." << endl;
}
  
  
  

要求

标头: <hash_set>

命名空间: stdext

请参见

参考

hash_set Class

标准模板库