less 구조체
해당 인수에서 보다 적은 작업 (operator<) 을 수행하는 이진 조건부 입니다.
template<class Type = void>
struct less : public binary_function <Type, Type, bool>
{
bool operator()(
const Type& Left,
const Type& Right
) const;
};
// specialized transparent functor for operator<
template<>
struct less<void>
{
template<class Type1, class Type2>
auto operator()(Type1&& Left, Type2&& Right) const
-> decltype(std::forward<Type1>(Left)
< std::forward<Type2>(Right));
};
매개 변수
Type, Type1, Type2
유추 또는 지정된 형식의 피연산자를 사용하는 operator< 를 지원하는 모든 형식입니다.Left
보다 작은 연산의 왼쪽 피연산자입니다. 특수화 되지 않은 템플릿은 Type 형식의 lvalue 참조 인수를 취합니다. 특수화 되지 않은 템플릿은 암시된 Type1 형식의 lvalue 및 rvalue 참조 인수 형식의 전달을 완벽히 수행합니다.Right
보다 작은 연산의 오른쪽 피연산자 입니다. 특수화 되지 않은 템플릿은 Type 형식의 lvalue 참조 인수를 취합니다. 특수화 되지 않은 템플릿은 암시된 Type2 형식의 lvalue 및 rvalue 참조 인수 형식의 전달을 완벽히 수행합니다.
반환 값
Left < Right의 결과입니다. 특수화 된 템플릿은 operator< 으로 반환되는 형식의 결과 전달을 완벽히 수행합니다.
설명
이진 술부 less<Type> 는 Type 형식의 요소 값의 집합을 엄격한 순서로 동일 클래스에 제공하고, 이것은 이 형식이 정렬된 표준 수학 요구 사항이 충족 하는 경우에만 적용됩니다. 포인터 형식에 대한 특수화는 서로 대해 고유한 값의 모든 요소를 정렬 하는 요소의 전체 순서를 생성 합니다.
예제
// functional_less.cpp
// compile with: /EHsc
#include <vector>
#include <algorithm>
#include <functional>
#include <iostream>
struct MyStruct {
MyStruct(int i) : m_i(i){}
bool operator < (const MyStruct & rhs) const {
return m_i < rhs.m_i;
}
int m_i;
};
int main() {
using namespace std;
vector <MyStruct> v1;
vector <MyStruct>::iterator Iter1;
vector <MyStruct>::reverse_iterator rIter1;
int i;
for ( i = 0 ; i < 7 ; i++ )
v1.push_back( MyStruct(rand()));
cout << "Original vector v1 = ( " ;
for ( Iter1 = v1.begin() ; Iter1 != v1.end() ; Iter1++ )
cout << Iter1->m_i << " ";
cout << ")" << endl;
// To sort in ascending order,
sort( v1.begin( ), v1.end( ), less<MyStruct>());
cout << "Sorted vector v1 = ( " ;
for ( Iter1 = v1.begin() ; Iter1 != v1.end() ; Iter1++ )
cout << Iter1->m_i << " ";
cout << ")" << endl;
}
Output
Original vector v1 = ( 41 18467 6334 26500 19169 15724 11478 )
Sorted vector v1 = ( 41 6334 11478 15724 18467 19169 26500 )
요구 사항
헤더: <기능>
네임스페이스: std