std::less

http://www.cplusplus.com/reference/functional/less/?kw=less

 

You were redirected to cplusplus.com/less || See search results for: "less"

class template

<functional>

std::less

template <class T> struct less;

Function object class for less-than inequality comparison

Binary function object class whose call returns whether the its first argument compares less than the second (as returned by operator <).

Generically, function objects are instances of a class with member function operator() defined. This member function allows the object to be used with the same syntax as a function call.

It is defined with the same behavior as:

  • C++98
  • C++11
  •  
1
2
3
template <class T> struct less : binary_function <T,T,bool> {
  bool operator() (const T& x, const T& y) const {return x<y;}
};
 



Objects of this class can be used on standard algorithms such as sort, merge or lower_bound.

 

Template parameters

T

Type of the arguments to compare by the functional call.
The type shall support the operation (operator<).

 

Member types

member typedefinitionnotes
first_argument_typeTType of the first argument in member operator()
second_argument_typeTType of the second argument in member operator()
result_typeboolType returned by member operator()

 

Member functions

bool operator() (const T& x, const T& y)

Member function returning whether the first argument compares less than the second (x<y).

 

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// less example
#include <iostream>     // std::cout
#include <functional>   // std::less
#include <algorithm>    // std::sort, std::includes

int main () {
  int foo[]={10,20,5,15,25};
  int bar[]={15,10,20};
  std::sort (foo, foo+5, std::less<int>());  // 5 10 15 20 25
  std::sort (bar, bar+3, std::less<int>());  //   10 15 20
  if (std::includes (foo, foo+5, bar, bar+3, std::less<int>()))
    std::cout << "foo includes bar.\n";
  return 0;
}

Edit & Run



Output:

foo includes bar.

 

See also

equal_to

Function object class for equality comparison (class template )

not_equal_to

Function object class for non-equality comparison (class template )

greater

Function object class for greater-than inequality comparison (class template )

greater_equal

Function object class for greater-than-or-equal-to comparison (class template )

less_equal

Function object class for less-than-or-equal-to comparison (class template )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值