GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • TUTORIALS
  • REFERENCE
  • ARTICLES
  • FORUM
  • C library:
  • <cassert> (assert.h)
  • <cctype> (ctype.h)
  • <cerrno> (errno.h)
  • <cfenv> (fenv.h)
  • <cfloat> (float.h)
  • <cinttypes> (inttypes.h)
  • <ciso646> (iso646.h)
  • <climits> (limits.h)
  • <clocale> (locale.h)

This view

  • Original page
  • New address

GeezerVison is showing cplusplus.com — std::less

  • TUTORIALS
  • REFERENCE
  • ARTICLES
  • FORUM

C++

  • Tutorials
  • Reference
  • Articles
  • Forum

Reference

  • C library:

    • <cassert> (assert.h)
    • <cctype> (ctype.h)
    • <cerrno> (errno.h)
    • C++11
      <cfenv> (fenv.h)
    • <cfloat> (float.h)
    • C++11
      <cinttypes> (inttypes.h)
    • <ciso646> (iso646.h)
    • <climits> (limits.h)
    • <clocale> (locale.h)
    • <cmath> (math.h)
    • <csetjmp> (setjmp.h)
    • <csignal> (signal.h)
    • <cstdarg> (stdarg.h)
    • C++11
      <cstdbool> (stdbool.h)
    • <cstddef> (stddef.h)
    • C++11
      <cstdint> (stdint.h)
    • <cstdio> (stdio.h)
    • <cstdlib> (stdlib.h)
    • <cstring> (string.h)
    • C++11
      <ctgmath> (tgmath.h)
    • <ctime> (time.h)
    • C++11
      <cuchar> (uchar.h)
    • <cwchar> (wchar.h)
    • <cwctype> (wctype.h)
  • Containers:

    • C++11
      <array>
    • <deque>
    • C++11
      <forward_list>
    • <list>
    • <map>
    • <queue>
    • <set>
    • <stack>
    • C++11
      <unordered_map>
    • C++11
      <unordered_set>
    • <vector>
  • Input/Output:

    • <fstream>
    • <iomanip>
    • <ios>
    • <iosfwd>
    • <iostream>
    • <istream>
    • <ostream>
    • <sstream>
    • <streambuf>
  • Multi-threading:

    • C++11
      <atomic>
    • C++11
      <condition_variable>
    • C++11
      <future>
    • C++11
      <mutex>
    • C++11
      <thread>
  • Other:

    • <algorithm>
    • <bitset>
    • C++11
      <chrono>
    • C++11
      <codecvt>
    • <complex>
    • <exception>
    • <functional>
    • C++11
      <initializer_list>
    • <iterator>
    • <limits>
    • <locale>
    • <memory>
    • <new>
    • <numeric>
    • C++11
      <random>
    • C++11
      <ratio>
    • C++11
      <regex>
    • <stdexcept>
    • <string>
    • C++11
      <system_error>
    • C++11
      <tuple>
    • C++11
      <type_traits>
    • C++11
      <typeindex>
    • <typeinfo>
    • <utility>
    • <valarray>

<functional>

  • functions

    • C++11
      bind
    • C++11
      cref
    • C++11
      mem_fn
    • not1
    • not2
    • C++11
      ref
  • wrapper classes

    • binary_negate
    • C++11
      function
    • C++11
      reference_wrapper
    • unary_negate
  • operator classes

    • C++11
      bit_and
    • C++11
      bit_or
    • C++11
      bit_xor
    • divides
    • equal_to
    • greater
    • greater_equal
    • less
    • less_equal
    • logical_and
    • logical_not
    • logical_or
    • minus
    • modulus
    • multiplies
    • negate
    • not_equal_to
    • plus
  • other classes

    • C++11
      bad_function_call
    • C++11
      hash
    • C++11
      is_bind_expression
    • C++11
      is_placeholder
  • namespaces

    • C++11
      placeholders
  • deprecated

    • binary_function
    • bind1st
    • bind2nd
    • binder1st
    • binder2nd
    • const_mem_fun_ref_t
    • const_mem_fun_t
    • const_mem_fun1_ref_t
    • const_mem_fun1_t
    • mem_fun
    • mem_fun_ref
    • mem_fun_ref_t
    • mem_fun_t
    • mem_fun1_ref_t
    • mem_fun1_t
    • pointer_to_binary_function
    • pointer_to_unary_function
    • ptr_fun
    • unary_function
  • Reference
  • <functional>
  • 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:

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;}
};
1
2
3
4
5
6
template <class T> struct less {
  bool operator() (const T& x, const T& y) const {return x<y;}
  typedef T first_argument_type;
  typedef T second_argument_type;
  typedef bool result_type;
};

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;
}

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)
Home page | Privacy policy
© cplusplus.com, 2000-2026 - All rights reserved - v3.3.4s
Spotted an error? contact us
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.