A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FSTL_Basics%2Fpredicate</id>
		<title>C++/STL Basics/predicate - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FSTL_Basics%2Fpredicate"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/STL_Basics/predicate&amp;action=history"/>
		<updated>2026-04-09T23:30:22Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/STL_Basics/predicate&amp;diff=904&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/STL_Basics/predicate&amp;diff=904&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B/STL_Basics/predicate&amp;diff=905&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B/STL_Basics/predicate&amp;diff=905&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:08Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Convenience function for the compose_f_gx adapter==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;functional&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
/* PRINT_ELEMENTS()&lt;br /&gt;
 * - prints optional C-string optcstr followed by&lt;br /&gt;
 * - all elements of the collection coll&lt;br /&gt;
 * - separated by spaces&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
inline void PRINT_ELEMENTS (const T&amp;amp; coll, const char* optcstr=&amp;quot;&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
    typename T::const_iterator pos;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; optcstr;&lt;br /&gt;
    for (pos=coll.begin(); pos!=coll.end(); ++pos) {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; *pos &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/* class for the compose_f_gx adapter&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;class OP1, class OP2&amp;gt;&lt;br /&gt;
class compose_f_gx_t&lt;br /&gt;
 : public std::unary_function&amp;lt;typename OP2::argument_type,&lt;br /&gt;
                              typename OP1::result_type&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
    OP1 op1;    // process: op1(op2(x))&lt;br /&gt;
    OP2 op2;&lt;br /&gt;
  public:&lt;br /&gt;
    // constructor&lt;br /&gt;
    compose_f_gx_t(const OP1&amp;amp; o1, const OP2&amp;amp; o2)&lt;br /&gt;
     : op1(o1), op2(o2) {&lt;br /&gt;
    }&lt;br /&gt;
    // function call&lt;br /&gt;
    typename OP1::result_type&lt;br /&gt;
    operator()(const typename OP2::argument_type&amp;amp; x) const {&lt;br /&gt;
        return op1(op2(x));&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
/* convenience function for the compose_f_gx adapter&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;class OP1, class OP2&amp;gt;&lt;br /&gt;
inline compose_f_gx_t&amp;lt;OP1,OP2&amp;gt;&lt;br /&gt;
compose_f_gx (const OP1&amp;amp; o1, const OP2&amp;amp; o2) {&lt;br /&gt;
    return compose_f_gx_t&amp;lt;OP1,OP2&amp;gt;(o1,o2);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    vector&amp;lt;int&amp;gt; coll;&lt;br /&gt;
    // insert elements from 1 to 9&lt;br /&gt;
    for (int i=1; i&amp;lt;=9; ++i) {&lt;br /&gt;
        coll.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    PRINT_ELEMENTS(coll);&lt;br /&gt;
    // for each element add 10 and multiply by 5&lt;br /&gt;
    transform (coll.begin(),coll.end(),&lt;br /&gt;
               ostream_iterator&amp;lt;int&amp;gt;(cout,&amp;quot; &amp;quot;),&lt;br /&gt;
               compose_f_gx(bind2nd(multiplies&amp;lt;int&amp;gt;(),5),&lt;br /&gt;
                            bind2nd(plus&amp;lt;int&amp;gt;(),10)));&lt;br /&gt;
    cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
1 2 3 4 5 6 7 8 9&lt;br /&gt;
55 60 65 70 75 80 85 90 95&lt;br /&gt;
 */        &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convenience function for the compose_f_gx_hx adapter==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
#include &amp;lt;functional&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
/* PRINT_ELEMENTS()&lt;br /&gt;
 * - prints optional C-string optcstr followed by&lt;br /&gt;
 * - all elements of the collection coll&lt;br /&gt;
 * - separated by spaces&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;class T&amp;gt;&lt;br /&gt;
inline void PRINT_ELEMENTS (const T&amp;amp; coll, const char* optcstr=&amp;quot;&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
    typename T::const_iterator pos;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; optcstr;&lt;br /&gt;
    for (pos=coll.begin(); pos!=coll.end(); ++pos) {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; *pos &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/* class for the compose_f_gx_hx adapter&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;class OP1, class OP2, class OP3&amp;gt;&lt;br /&gt;
class compose_f_gx_hx_t&lt;br /&gt;
 : public std::unary_function&amp;lt;typename OP2::argument_type,&lt;br /&gt;
                              typename OP1::result_type&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
    OP1 op1;    // process: op1(op2(x),op3(x))&lt;br /&gt;
    OP2 op2;&lt;br /&gt;
    OP3 op3;&lt;br /&gt;
  public:&lt;br /&gt;
    // constructor&lt;br /&gt;
    compose_f_gx_hx_t (const OP1&amp;amp; o1, const OP2&amp;amp; o2, const OP3&amp;amp; o3)&lt;br /&gt;
     : op1(o1), op2(o2), op3(o3) {&lt;br /&gt;
    }&lt;br /&gt;
    // function call&lt;br /&gt;
    typename OP1::result_type&lt;br /&gt;
    operator()(const typename OP2::argument_type&amp;amp; x) const {&lt;br /&gt;
        return op1(op2(x),op3(x));&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
/* convenience function for the compose_f_gx_hx adapter&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;class OP1, class OP2, class OP3&amp;gt;&lt;br /&gt;
inline compose_f_gx_hx_t&amp;lt;OP1,OP2,OP3&amp;gt;&lt;br /&gt;
compose_f_gx_hx (const OP1&amp;amp; o1, const OP2&amp;amp; o2, const OP3&amp;amp; o3) {&lt;br /&gt;
    return compose_f_gx_hx_t&amp;lt;OP1,OP2,OP3&amp;gt;(o1,o2,o3);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    vector&amp;lt;int&amp;gt; coll;&lt;br /&gt;
    // insert elements from 1 to 9&lt;br /&gt;
    for (int i=1; i&amp;lt;=9; ++i) {&lt;br /&gt;
        coll.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    PRINT_ELEMENTS(coll);&lt;br /&gt;
    // remove all elements that are greater than four and less than seven&lt;br /&gt;
    // - retain new end&lt;br /&gt;
    vector&amp;lt;int&amp;gt;::iterator pos;&lt;br /&gt;
    pos = remove_if (coll.begin(),coll.end(),&lt;br /&gt;
                     compose_f_gx_hx(logical_and&amp;lt;bool&amp;gt;(),&lt;br /&gt;
                                     bind2nd(greater&amp;lt;int&amp;gt;(),4),&lt;br /&gt;
                                     bind2nd(less&amp;lt;int&amp;gt;(),7)));&lt;br /&gt;
    // remove &amp;quot;&amp;quot;removed&amp;quot;&amp;quot; elements in coll&lt;br /&gt;
    coll.erase(pos,coll.end());&lt;br /&gt;
    PRINT_ELEMENTS(coll);&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
1 2 3 4 5 6 7 8 9&lt;br /&gt;
1 2 3 4 7 8 9&lt;br /&gt;
 */        &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Convenience function for the compose_f_gx_hy adapter==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;functional&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;cctype&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;functional&amp;gt;&lt;br /&gt;
/* class for the compose_f_gx_hy adapter&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;class OP1, class OP2, class OP3&amp;gt;&lt;br /&gt;
class compose_f_gx_hy_t&lt;br /&gt;
 : public std::binary_function&amp;lt;typename OP2::argument_type,&lt;br /&gt;
                               typename OP3::argument_type,&lt;br /&gt;
                               typename OP1::result_type&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  private:&lt;br /&gt;
    OP1 op1;    // process: op1(op2(x),op3(y))&lt;br /&gt;
    OP2 op2;&lt;br /&gt;
    OP3 op3;&lt;br /&gt;
  public:&lt;br /&gt;
    // constructor&lt;br /&gt;
    compose_f_gx_hy_t (const OP1&amp;amp; o1, const OP2&amp;amp; o2, const OP3&amp;amp; o3)&lt;br /&gt;
     : op1(o1), op2(o2), op3(o3) {&lt;br /&gt;
    }&lt;br /&gt;
    // function call&lt;br /&gt;
    typename OP1::result_type&lt;br /&gt;
    operator()(const typename OP2::argument_type&amp;amp; x,&lt;br /&gt;
               const typename OP3::argument_type&amp;amp; y) const {&lt;br /&gt;
        return op1(op2(x),op3(y));&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
/* convenience function for the compose_f_gx_hy adapter&lt;br /&gt;
 */&lt;br /&gt;
template &amp;lt;class OP1, class OP2, class OP3&amp;gt;&lt;br /&gt;
inline compose_f_gx_hy_t&amp;lt;OP1,OP2,OP3&amp;gt;&lt;br /&gt;
compose_f_gx_hy (const OP1&amp;amp; o1, const OP2&amp;amp; o2, const OP3&amp;amp; o3) {&lt;br /&gt;
    return compose_f_gx_hy_t&amp;lt;OP1,OP2,OP3&amp;gt;(o1,o2,o3);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    string s(&amp;quot;Internationalization&amp;quot;);&lt;br /&gt;
    string sub(&amp;quot;Nation&amp;quot;);&lt;br /&gt;
    // search substring case insensitive&lt;br /&gt;
    string::iterator pos;&lt;br /&gt;
    pos = search (s.begin(),s.end(),           // string to search in&lt;br /&gt;
                  sub.begin(),sub.end(),       // substring to search&lt;br /&gt;
                  compose_f_gx_hy(equal_to&amp;lt;int&amp;gt;(), // compar. criterion&lt;br /&gt;
                                  ptr_fun(::toupper),&lt;br /&gt;
                                  ptr_fun(::toupper)));&lt;br /&gt;
    if (pos != s.end()) {&lt;br /&gt;
        cout &amp;lt;&amp;lt; &amp;quot;\&amp;quot;&amp;quot; &amp;lt;&amp;lt; sub &amp;lt;&amp;lt; &amp;quot;\&amp;quot; is part of \&amp;quot;&amp;quot; &amp;lt;&amp;lt; s &amp;lt;&amp;lt; &amp;quot;\&amp;quot;&amp;quot;&lt;br /&gt;
             &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 /* &lt;br /&gt;
&amp;quot;Nation&amp;quot; is part of &amp;quot;Internationalization&amp;quot;&lt;br /&gt;
 */       &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create your own unary function==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;list&amp;gt;&lt;br /&gt;
#include &amp;lt;functional&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class reciprocal: unary_function&amp;lt;double, double&amp;gt; {&lt;br /&gt;
public:&lt;br /&gt;
  result_type operator()(argument_type i)&lt;br /&gt;
  { &lt;br /&gt;
    return (result_type) 1.0/i;&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  list&amp;lt;double&amp;gt; vals;&lt;br /&gt;
  for(int i=1; i&amp;lt;10; i++) vals.push_back((double)i);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Original contents of vals:\n&amp;quot;;&lt;br /&gt;
  list&amp;lt;double&amp;gt;::iterator p = vals.begin();&lt;br /&gt;
  while(p != vals.end()) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; *p &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    p++;&lt;br /&gt;
  }&lt;br /&gt;
  cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
 &lt;br /&gt;
  // use reciprocal function object&lt;br /&gt;
  p = transform(vals.begin(), vals.end(),&lt;br /&gt;
                vals.begin(),&lt;br /&gt;
                reciprocal()); // call function object&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Transformed contents of vals:\n&amp;quot;;&lt;br /&gt;
  p = vals.begin();&lt;br /&gt;
  while(p != vals.end()) {&lt;br /&gt;
    cout &amp;lt;&amp;lt; *p &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    p++;&lt;br /&gt;
  }&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
 /* &lt;br /&gt;
Original contents of vals:&lt;br /&gt;
1 2 3 4 5 6 7 8 9&lt;br /&gt;
Transformed contents of vals:&lt;br /&gt;
1 0.5 0.333333 0.25 0.2 0.166667 0.142857 0.125 0.111111&lt;br /&gt;
 */       &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Function object to process the mean value==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
// function object to process the mean value&lt;br /&gt;
class MeanValue {&lt;br /&gt;
  private:&lt;br /&gt;
    long num;    // number of elements&lt;br /&gt;
    long sum;    // sum of all element values&lt;br /&gt;
  public:&lt;br /&gt;
    // constructor&lt;br /&gt;
    MeanValue () : num(0), sum(0) {&lt;br /&gt;
    }&lt;br /&gt;
    // &amp;quot;&amp;quot;function call&amp;quot;&amp;quot;&lt;br /&gt;
    // - process one more element of the sequence&lt;br /&gt;
    void operator() (int elem) {&lt;br /&gt;
        num++;          // increment count&lt;br /&gt;
        sum += elem;    // add value&lt;br /&gt;
    }&lt;br /&gt;
    // return mean value&lt;br /&gt;
    double value () {&lt;br /&gt;
        return static_cast&amp;lt;double&amp;gt;(sum) / static_cast&amp;lt;double&amp;gt;(num);&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    vector&amp;lt;int&amp;gt; coll;&lt;br /&gt;
    // insert elments from 1 to 8&lt;br /&gt;
    for (int i=1; i&amp;lt;=8; ++i) {&lt;br /&gt;
        coll.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    // process and print mean value&lt;br /&gt;
    MeanValue mv = for_each (coll.begin(), coll.end(),  // range&lt;br /&gt;
                             MeanValue());              // operation&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;mean value: &amp;quot; &amp;lt;&amp;lt; mv.value() &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
 /* &lt;br /&gt;
mean value: 4.5&lt;br /&gt;
 */       &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Illustrating the use of an adaptor for pointers to functions==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
//Revised from&lt;br /&gt;
//STL Tutorial and Reference Guide C++ Programming with the Standard Template Library, 2nd Edition&lt;br /&gt;
//by David R. Musser (Author), Atul Saini (Author)&lt;br /&gt;
//# Publisher: Addison-Wesley Pub (Sd) (March 1996)&lt;br /&gt;
//# Language: English&lt;br /&gt;
//# ISBN-10: 0201633981&lt;br /&gt;
//# ISBN-13: 978-0201633986&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;set&amp;gt;&lt;br /&gt;
using namespace std; &lt;br /&gt;
bool less1(const string&amp;amp; x, const string&amp;amp; y)&lt;br /&gt;
{&lt;br /&gt;
  return x &amp;lt; y;&lt;br /&gt;
}&lt;br /&gt;
bool greater1(const string&amp;amp; x, const string&amp;amp; y)&lt;br /&gt;
{&lt;br /&gt;
  return x &amp;gt; y;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  typedef set&amp;lt;string, pointer_to_binary_function&amp;lt;const string&amp;amp;, const string&amp;amp;,bool&amp;gt; &amp;gt;  set_type1;&lt;br /&gt;
  set_type1 set1(ptr_fun(less1));&lt;br /&gt;
  set1.insert(&amp;quot;the&amp;quot;);&lt;br /&gt;
  set1.insert(&amp;quot;quick&amp;quot;);&lt;br /&gt;
  set1.insert(&amp;quot;brown&amp;quot;);&lt;br /&gt;
  set1.insert(&amp;quot;fox&amp;quot;);&lt;br /&gt;
  set_type1::iterator i;&lt;br /&gt;
  for (i = set1.begin(); i != set1.end(); ++i) &lt;br /&gt;
    cout &amp;lt;&amp;lt; *i &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
  &lt;br /&gt;
  set_type1 set2(ptr_fun(greater1));&lt;br /&gt;
  set2.insert(&amp;quot;the&amp;quot;);&lt;br /&gt;
  set2.insert(&amp;quot;quick&amp;quot;);&lt;br /&gt;
  set2.insert(&amp;quot;brown&amp;quot;);&lt;br /&gt;
  set2.insert(&amp;quot;fox&amp;quot;);&lt;br /&gt;
  for (i = set2.begin(); i != set2.end(); ++i) &lt;br /&gt;
    cout &amp;lt;&amp;lt; *i &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
brown fox quick the&lt;br /&gt;
the quick fox brown&lt;br /&gt;
 */&lt;br /&gt;
        &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==use generic function as predicate==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;C++ Templates - The Complete Guide&amp;quot;&lt;br /&gt;
 * by David Vandevoorde and Nicolai M. Josuttis, Addison-Wesley, 2002&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright David Vandevoorde and Nicolai M. Josuttis 2002.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
template &amp;lt;typename T, int VAL&amp;gt;&lt;br /&gt;
T addValue (T const&amp;amp; x)&lt;br /&gt;
{&lt;br /&gt;
    return x + VAL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void call_addValue()&lt;br /&gt;
{&lt;br /&gt;
    addValue&amp;lt;int,5&amp;gt;(42);&lt;br /&gt;
}&lt;br /&gt;
template &amp;lt;typename IT, typename OP&amp;gt;&lt;br /&gt;
void transform (IT beg, IT end, IT to, OP op)&lt;br /&gt;
{&lt;br /&gt;
    while (beg != end) {&lt;br /&gt;
        *to++ = op(*beg++);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    call_addValue();&lt;br /&gt;
    int m[] = { 1, 2, 3, 4, 5, 6 };&lt;br /&gt;
    transform (m, m+6,&lt;br /&gt;
               m,&lt;br /&gt;
               (int(*)(int const&amp;amp;))    // cast necessary&lt;br /&gt;
               addValue&amp;lt;int,5&amp;gt;);&lt;br /&gt;
    for(int i=0;i&amp;lt;6;i++){&lt;br /&gt;
       cout &amp;lt;&amp;lt; m[i] &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
6 7 8 9 10 11&lt;br /&gt;
 */&lt;br /&gt;
        &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use predicate, which returns whether an integer is a prime number, with a list==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;list&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdlib&amp;gt;      // for abs()&lt;br /&gt;
using namespace std;&lt;br /&gt;
// predicate, which returns whether an integer is a prime number&lt;br /&gt;
bool isPrime (int number)&lt;br /&gt;
{&lt;br /&gt;
    // ignore negative sign&lt;br /&gt;
    number = abs(number);&lt;br /&gt;
    // 0 and 1 are no prime numbers&lt;br /&gt;
    if (number == 0 || number == 1) {&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
        &lt;br /&gt;
    // find divisor that divides without a remainder&lt;br /&gt;
    int divisor;&lt;br /&gt;
    for (divisor = number/2; numberdivisor != 0; --divisor) {&lt;br /&gt;
        ;&lt;br /&gt;
    }&lt;br /&gt;
    // if no divisor greater than 1 is found, it is a prime number&lt;br /&gt;
    return divisor == 1;&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    list&amp;lt;int&amp;gt; coll;&lt;br /&gt;
    // insert elements from 24 to 30&lt;br /&gt;
    for (int i=24; i&amp;lt;=30; ++i) {&lt;br /&gt;
        coll.push_back(i);&lt;br /&gt;
    }&lt;br /&gt;
    // search for prime number&lt;br /&gt;
    list&amp;lt;int&amp;gt;::iterator pos;&lt;br /&gt;
    pos = find_if (coll.begin(), coll.end(),    // range&lt;br /&gt;
                   isPrime);                    // predicate&lt;br /&gt;
    if (pos != coll.end()) {&lt;br /&gt;
        // found&lt;br /&gt;
        cout &amp;lt;&amp;lt; *pos &amp;lt;&amp;lt; &amp;quot; is first prime number found&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
    else {&lt;br /&gt;
        // not found&lt;br /&gt;
        cout &amp;lt;&amp;lt; &amp;quot;no prime number found&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
/* &lt;br /&gt;
29 is first prime number found&lt;br /&gt;
 */        &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>