stdcpp/tsrc/Boost_test/ptr_container/src/indirect_fun.cpp
author William Roberts <williamr@symbian.org>
Thu, 22 Jul 2010 16:48:56 +0100
branchGCC_SURGE
changeset 45 4b03adbd26ca
parent 0 e4d67989cc36
permissions -rw-r--r--
Catchup to latest Symbian^4

//
// Boost.Pointer Container
//
//  Copyright Thorsten Ottosen 2003-2005. Use, modification and
//  distribution is subject to the Boost Software License, Version
//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see http://www.boost.org/libs/ptr_container/
//
 
#include <boost/ptr_container/indirect_fun.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/assign/list_inserter.hpp> 
#include <boost/test/test_tools.hpp>
#include <algorithm>
#include <functional>
#include <string>

bool lesser_than( const std::string& l, const std::string& r )
{
    return l < r;
}


void test_fun()
{
    using namespace boost;
    ptr_vector<std::string> vec;

    indirect_fun< std::less<std::string> > fun;

    std::string* ptr1  = new std::string("bar");
    std::string* ptr2  = new std::string("foo");
    BOOST_CHECK( fun( ptr1, ptr2 ) == true );
    
    void*       vptr1  = ptr1;
    void*       vptr2  = ptr2;
    
    void_ptr_indirect_fun< std::less<std::string>, std::string> cast_fun;
    BOOST_CHECK( cast_fun( vptr1, vptr2 ) == true );
    
    assign::push_back( vec )( new std::string("aa") )
                            ( new std::string("bb") )
                            ( new std::string("dd") )
                            ( new std::string("cc") )
                            ( new std::string("a") );
                              
    std::sort( vec.begin().base(), vec.end().base(), cast_fun );
    BOOST_CHECK( vec[0] == "a" );
    BOOST_CHECK( vec[4] == "dd" );

    std::sort( vec.begin().base(), vec.end().base(), 
               make_void_ptr_indirect_fun<std::string>( &lesser_than ) );
    BOOST_CHECK( vec[1] == "aa" );
    BOOST_CHECK( vec[2] == "bb" );    

    void* iptr1 = new int(2);
    void* iptr2 = new int(3);

    void_ptr_indirect_fun<std::less<int>, int> int_cast_fun;
    BOOST_CHECK( int_cast_fun(iptr1,iptr2) );
    
}



#include <boost/test/included/test_exec_monitor.hpp>
int test_main(int,char *[])
{
  
  test_fun();
  return 0;
}