unary_function and function object
<p>function object , it' my first time that i seeing them  , and just found an example about it and how it's work </p>

<pre><code>//function object example
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
using namespace std;
//simple function object that prints the passed argument
class PrintSomething
{
public:
void operator() (int elem) const
{
cout&lt;&lt;elem&lt;&lt;' ';
}
}
;
int main()
{
vector&lt;int&gt; vec;
//insert elements from 1 to 10
for(int i=1; i&lt;=10; ++i)
vec.push_back(i);
//print all elements
for_each (vec.begin(), vec.end(), //range
PrintSomething()); //operation
cout&lt;&lt;endl;
}
</code></pre>

<p>output : 0 1 2 3 4 5 6 7 8 9</p>

<p>to be honest with you , i understand the syntax of the function object but this example don't give me a serious issue to use this technique , <strong><em>so my question is when i should use function object ?</em></strong></p>

<p>and by Accidentally i found <code>unary_function</code> and i found an example about it (<code>unary_function</code>) and the examples  look same match :</p>

<pre><code>// unary_function example
#include &lt;iostream&gt;
#include &lt;functional&gt;
using namespace std;

struct IsOdd : public unary_function&lt;int,bool&gt; {
  bool operator() (int number) {return (number%2==1);}
};

int main () {
  IsOdd IsOdd_object;
  IsOdd::argument_type input;
  IsOdd::result_type result;

  cout &lt;&lt; "Please enter a number: ";
  cin &gt;&gt; input;

  result = IsOdd_object (input);

  cout &lt;&lt; "Number " &lt;&lt; input &lt;&lt; " is " &lt;&lt; (result?"odd":"even") &lt;&lt; ".\n";

  return 0;
}

outputs :
 Please enter a number: 2
Number 2 is even.
</code></pre>

<p>is this mean that <code>unary_function</code> is <strong><em>template</em></strong> function object with specific arguments number?
and i can define my own function object or just use <code>unary_function</code>in my classes .</p>

<p>and thank you !</p>
