stdcpp/tsrc/Stdcpp_test/stlport/auto/stlport_uprbnd/src/uprbnd2.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  
       
    19 // STLport regression testsuite component.
       
    20 // To compile as a separate example, please #define MAIN.
       
    21 
       
    22 #include <algorithm>
       
    23 #include <iostream>
       
    24 #include <cstring>
       
    25 
       
    26 #ifdef MAIN 
       
    27 #define uprbnd2_test main
       
    28 #endif
       
    29 
       
    30 #if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
       
    31 using namespace std;
       
    32 #endif
       
    33 
       
    34 static bool char_str_less(const char* a_, const char* b_)
       
    35 {
       
    36   return strcmp(a_, b_) < 0 ? 1 : 0;
       
    37 }
       
    38 
       
    39 int uprbnd2_test(int, char**)
       
    40 {
       
    41   int x=0;
       
    42   cout<<"Results of uprbnd2_test:"<<endl;
       
    43 
       
    44   char* str [] = { "a", "a", "b", "b", "q", "w", "z" };
       
    45 
       
    46   const unsigned strCt = sizeof(str)/sizeof(str[0]);
       
    47   // DEC C++ generates incorrect template instatiation code 
       
    48   // for "d" so must cast 
       
    49   
       
    50   x=(upper_bound((char**)str,  (char**)str + strCt, (const char *)"d", char_str_less) - str);
       
    51   
       
    52   cout<< "d can be inserted at index: "<<x<<endl;
       
    53   
       
    54   
       
    55   if(4!=x)
       
    56     return 1;   
       
    57   else  
       
    58    return 0;
       
    59 }
       
    60 
       
    61