检索在使用于顺序元素值比较对象的副本设置。
value_compare value_comp( ) const;
返回值
返回设置的使用对其元素,是模板参数 Traits的函数对象。
有关 Traits 的更多信息 set Class 请参见主题。
备注
存储的对象定义成员函数:
bool operator(const Key&_xVal,const Key&;yVal);
后者返回 true,如果 _xVal 之前和与 _yVal 不相等按排序顺序。
请注意 value_compare 和 key_compare 是模板参数的 Traits同义词。两个类型为设置和多个集选件类提供,它们用于映射和基于选件类的兼容性是相同的,因此,它们是不同的。
示例
// set_value_comp.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
int main( )
{
using namespace std;
set <int, less<int> > s1;
set <int, less<int> >::value_compare vc1 = s1.value_comp( );
bool result1 = vc1( 2, 3 );
if( result1 == true )
{
cout << "vc1( 2,3 ) returns value of true, "
<< "where vc1 is the function object of s1."
<< endl;
}
else
{
cout << "vc1( 2,3 ) returns value of false, "
<< "where vc1 is the function object of s1."
<< endl;
}
set <int, greater<int> > s2;
set<int, greater<int> >::value_compare vc2 = s2.value_comp( );
bool result2 = vc2( 2, 3 );
if( result2 == true )
{
cout << "vc2( 2,3 ) returns value of true, "
<< "where vc2 is the function object of s2."
<< endl;
}
else
{
cout << "vc2( 2,3 ) returns value of false, "
<< "where vc2 is the function object of s2."
<< endl;
}
}
要求
标头: <set>
命名空间: std