Transform deque with boolean function : transform « deque « C++ Tutorial

Home
C++ Tutorial
1.Language Basics
2.Data Types
3.Operators statements
4.Array
5.Development
6.Exceptions
7.Function
8.Structure
9.Class
10.Operator Overloading
11.Pointer
12.File Stream
13.template
14.STL Introduction
15.string
16.vector
17.list
18.bitset
19.set multiset
20.valarray
21.queue stack
22.deque
23.map multimap
24.STL Algorithms Modifying sequence operations
25.STL Algorithms Non modifying sequence operations
26.STL Algorithms Binary search
27.STL Algorithms Sorting
28.STL Algorithms Merge
29.STL Algorithms Min Max
30.STL Algorithms Iterator
31.STL Algorithms Heap
32.STL Algorithms Helper
C / ANSI-C
C Tutorial
C++
Visual C++ .NET
C++ Tutorial » deque » transform 
22.12.1.Transform deque with boolean function
#include <algorithm>
#include <deque>
#include <iostream>

using namespace std;

bool logical_xorbool a, bool b );

void print_resultconst char* names[]const deque<bool>& print,const char* text );

int main( )
{
   const char* contacts[] ="A""J","S""D""R" };
   const bool salesman1_data[] true, true, false, false, true };
   const bool salesman2_data[] false, false, true, true, true };
   const int num_customers = sizeofsalesman1_data / sizeofsalesman1_data[0] );

   // create deques and initialize with above data
   deque<bool> salesman1salesman1_data,salesman1_data+num_customers );
   deque<bool> salesman2salesman2_data,salesman2_data+num_customers );
   deque<bool> resultnum_customers );

   print_resultcontacts, salesman1,"has been called by Salesman 1" );
   print_resultcontacts, salesman2,"has been called by Salesman 2" );

   // customers called by both salesmen
   transformsalesman1.begin(), salesman1.end(), salesman2.begin(),result.begin(), logical_and<bool>() );
   print_resultcontacts, result,"has been called by both salesmen" );

   // customers called by at least one salesman
   transformsalesman1.begin(), salesman1.end(), salesman2.begin(),result.begin(), logical_or<bool>() );
   print_resultcontacts, result,"has been called by at least one salesman" );

   // customers called by only one salesman
   transformsalesman1.begin(), salesman1.end(), salesman2.begin(),result.begin(), logical_xor );
   print_resultcontacts, result,"has been called by only one salesman" );

   // customers not called by Salesman 1
   transformsalesman1.begin(), salesman1.end(),result.begin(), logical_not<bool>() );
   print_resultcontacts, result,"has not been called by Salesman 1" );
}

inline
bool logical_xorbool a, bool b ) {  
   return a ? !b : b;  
}
void print_resultconst char* names[]const deque<bool>& which,const char* text ){
   fordeque<bool>::size_type i = 0; i < which.size(); ++i )
      ifwhich[i] )
         cout << names[i<< " " << text << endl;
   cout << endl;
}
22.12.transform
22.12.1.Transform deque with boolean function
22.12.2.Checking if One Container Is Less Than or Greater Than Another
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.