VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stdgreater-in-c-with-examples/

⇱ std::greater in C++ with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

std::greater in C++ with Examples

Last Updated : 12 Jul, 2025
The std::greater is a functional object which is used for performing comparisons. It is defined as a Function object class for the greater-than inequality comparison. This can be used for changing the functionality of the given function. This can also be used with various standard algorithms such as sort, priority queue, etc. Header File:
#include <functional.h>
Template Class:
template <class T> struct greater;
Parameter: T is a type of the arguments to compare by the functional call. Return Value: It returns boolean variable as shown below:
  • True: If two element say(a & b) such that a > b.
  • False: If a < b.
Below is the illustration of std::greater in C++: Program 1:
Output:
90 80 70 60 50 40 30 20 10
Program 2:
Output:
The priority queue gquiz is : 1 5 10 20 30
Comment
Article Tags:
Article Tags: