stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_mset/src/mset5.cpp
changeset 31 ce057bb09d0b
child 34 5fae379060a7
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17  
       
    18 // STLport regression testsuite component.
       
    19 // To compile as a separate example, please #define MAIN.
       
    20 
       
    21 
       
    22 #include <iostream>
       
    23 #include <set>
       
    24 // #include <algorithm>
       
    25 #include <functional>
       
    26 
       
    27 
       
    28 #ifdef MAIN 
       
    29 #define mset5_test main
       
    30 #endif
       
    31 
       
    32 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
       
    33 using namespace std;
       
    34 #endif
       
    35 
       
    36 static bool less_than(int a_, int b_)
       
    37 {
       
    38   return a_ < b_;
       
    39 }
       
    40  
       
    41 static bool greater_than(int a_, int b_)
       
    42 {
       
    43   return a_ > b_;
       
    44 }
       
    45 
       
    46 int mset5_test(int, char**)
       
    47 {
       
    48   cout<<"Results of mset5_test:"<<endl;
       
    49   int array [] = { 3, 6, 1, 9 };
       
    50   int array1 [4],a =0 , failures = 0;
       
    51    typedef pointer_to_binary_function<int, int, bool> fn_type;
       
    52   typedef __multiset__<int, fn_type, allocator<int> > mset;
       
    53   fn_type f(less_than);
       
    54 
       
    55   mset s1(array+0, array + 4 , f );
       
    56   mset::const_iterator i = s1.begin();
       
    57 
       
    58   cout << "Using less_than: " << endl;
       
    59   
       
    60   while(i != s1.end())
       
    61   {
       
    62   	    cout << *i << endl;
       
    63   	  array1[a] = *i; 
       
    64   	  *i++; 
       
    65   	  a++;
       
    66   }
       
    67   if( array1[0] != 1)
       
    68   failures++;
       
    69   if( array1[1] != 3)
       
    70   failures++;
       
    71   if( array1[2] != 6)
       
    72   failures++;
       
    73   if( array1[3] != 9)
       
    74   failures++;
       
    75   
       
    76   fn_type g(greater_than);
       
    77   mset s2(array, array + 4, g);
       
    78   i = s2.begin();
       
    79   cout << "Using greater_than: " << endl;
       
    80   a=0;
       
    81   while(i != s2.end())
       
    82   {
       
    83   	
       
    84     cout << *i << endl;
       
    85 array1[a] = *i;
       
    86        *i++;
       
    87        a++;
       
    88   }
       
    89   if( array1[0] != 9)
       
    90   failures++;
       
    91   if( array1[1] != 6)
       
    92   failures++;
       
    93   if( array1[2] != 3)
       
    94   failures++;
       
    95   if( array1[3] != 1)
       
    96   failures++;
       
    97   
       
    98   return failures;
       
    99 }
       
   100