<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
greater [C++ Reference]
</title>
<meta name="generator" content="DokuWiki Release 2009-12-25c "Lemming"" />
<meta name="robots" content="index,follow" />
<meta name="date" content="2010-03-17T15:51:12-0700" />
<meta name="keywords" content="stl,functional,greater" />
<link rel="search" type="application/opensearchdescription+xml" href="/wiki/lib/exe/opensearch.php" title="C++ Reference" />
<link rel="start" href="/wiki/" />
<link rel="contents" href="/wiki/stl/functional/greater?do=index" title="Index" />
<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="/wiki/feed.php" />
<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="/wiki/feed.php?mode=list&ns=stl:functional" />
<link rel="edit" title="Edit this page" href="/wiki/stl/functional/greater?do=edit" />
<link rel="alternate" type="text/html" title="Plain HTML" href="/wiki/_export/xhtml/stl/functional/greater" />
<link rel="alternate" type="text/plain" title="Wiki Markup" href="/wiki/_export/raw/stl/functional/greater" />
<link rel="canonical" href="http://www.cppreference.com/wiki/stl/functional/greater" />
<link rel="stylesheet" media="all" type="text/css" href="/wiki/lib/exe/css.php?s=all&t=custom1&tseed=1272971091" />
<link rel="stylesheet" media="screen" type="text/css" href="/wiki/lib/exe/css.php?t=custom1&tseed=1272971091" />
<link rel="stylesheet" media="print" type="text/css" href="/wiki/lib/exe/css.php?s=print&t=custom1&tseed=1272971091" />
<script type="text/javascript" charset="utf-8" ><!--//--><![CDATA[//><!--
var NS='stl:functional';var JSINFO = {"id":"stl:functional:greater","namespace":"stl:functional"};
//--><!]]></script>
<script type="text/javascript" charset="utf-8" src="/wiki/lib/exe/js.php?tseed=1272971091" ></script>
<link rel="shortcut icon" href="/wiki/lib/tpl/custom1/images/favicon.png" />
</head>
<body>
<div class="dokuwiki">
<div class="stylehead">
<div class="breadcrumbs">
<span class="bchead">You are here: </span><a href="../../start.html" title="start">C++ Reference</a> » <a href="../../stl/start.html" title="stl:start">C++ Standard Template Library</a> » <a href="../../stl/functional/start.html" title="stl:functional:start">The <functional> header file</a> » <a href="../../stl/functional/greater.html" title="stl:functional:greater">greater</a> </div>
</div>
<div class="page">
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
<!-- wikipage start -->
<h1><a name="greater" id="greater">greater</a></h1>
<div class="level1">
</div>
<h5><a name="template_class_t_struct_greater" id="template_class_t_struct_greater">template <class T> struct greater;</a></h5>
<div class="level5">
<p>
Function object class for greater-than inequality comparison
</p>
<p>
This class defines function objects for the “greater than” inequality comparison operation.
</p>
<p>
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 regular function call, and therefore it can be used in templates instead of a pointer to a function.
</p>
<p>
greater has its operator() member defined such that it returns true if its first argument compares greater than the second one using operator>, and false otherwise.
</p>
<p>
This class is derived from binary_function and is defined as:
</p>
<pre class="code">template <class T> struct greater : binary_function <T,T,bool> {
bool operator() (const T& x, const T& y) const
{return x>y;}
};</pre>
<p>
Objects of this class can be used with some standard algorithms such as sort, merge or lower_bound.
</p>
</div>
<h3><a name="members" id="members">**Members**</a></h3>
<div class="level3">
<p>
T operator() (const T& x, const T& y)
Member function returning the result of the comparison x>y.
</p>
</div>
<h4><a name="greater_example" id="greater_example">// greater example</a></h4>
<div class="level4">
<pre class="c code c++" style="font-family:monospace;"><span class="co2">#include <iostream></span>
<span class="co2">#include <functional></span>
<span class="co2">#include <algorithm></span>
using namespace std<span class="sy0">;</span>
<span class="kw4">int</span> main <span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span>
<span class="kw4">int</span> numbers<span class="br0">[</span><span class="br0">]</span><span class="sy0">=</span><span class="br0">{</span>20<span class="sy0">,</span>40<span class="sy0">,</span>50<span class="sy0">,</span>10<span class="sy0">,</span>30<span class="br0">}</span><span class="sy0">;</span>
sort <span class="br0">(</span>numbers<span class="sy0">,</span> numbers<span class="sy0">+</span>5<span class="sy0">,</span> greater<span class="sy0"><</span>int<span class="sy0">></span><span class="br0">(</span><span class="br0">)</span> <span class="br0">)</span><span class="sy0">;</span>
<span class="kw1">for</span> <span class="br0">(</span><span class="kw4">int</span> i<span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span> i<span class="sy0"><</span><span class="nu0">5</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">)</span>
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/cout.html"><span class="kw3">cout</span></a> <span class="sy0"><<</span> numbers<span class="br0">[</span>i<span class="br0">]</span> <span class="sy0"><<</span> <span class="st0">" "</span><span class="sy0">;</span>
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/cout.html"><span class="kw3">cout</span></a> <span class="sy0"><<</span> endl<span class="sy0">;</span>
<span class="kw1">return</span> <span class="nu0">0</span><span class="sy0">;</span>
<span class="br0">}</span></pre>
<p>
Output:
</p>
<pre class="c code c++" style="font-family:monospace;"><span class="nu0">50</span> <span class="nu0">40</span> <span class="nu0">30</span> <span class="nu0">20</span> <span class="nu0">10</span></pre>
</div>
<!-- wikipage stop -->
</div>
<div class="clearer"> </div>
<div class="stylefoot">
<div class="meta">
<div class="user">
</div>
<!--
<div class="doc">
stl/functional/greater.txt · Last modified: 03/17/2010 15:51 by 81.63.116.197 </div>
-->
</div>
</div></div></body>
</html>