os/ossrv/ossrv_pub/boost_apis/boost/ptr_container/indirect_fun.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
//
sl@0
     2
// Boost.Pointer Container
sl@0
     3
//
sl@0
     4
//  Copyright Thorsten Ottosen 2003-2005. Use, modification and
sl@0
     5
//  distribution is subject to the Boost Software License, Version
sl@0
     6
//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
sl@0
     7
//  http://www.boost.org/LICENSE_1_0.txt)
sl@0
     8
//
sl@0
     9
// For more information, see http://www.boost.org/libs/ptr_container/
sl@0
    10
//
sl@0
    11
sl@0
    12
#ifndef BOOST_PTR_CONTAINER_INDIRECT_FUN_HPP
sl@0
    13
#define BOOST_PTR_CONTAINER_INDIRECT_FUN_HPP
sl@0
    14
sl@0
    15
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
sl@0
    16
    #pragma once
sl@0
    17
#endif
sl@0
    18
sl@0
    19
#include <boost/config.hpp>
sl@0
    20
sl@0
    21
#ifdef BOOST_NO_SFINAE
sl@0
    22
#else
sl@0
    23
#include <boost/utility/result_of.hpp>
sl@0
    24
#include <boost/pointee.hpp>
sl@0
    25
#endif // BOOST_NO_SFINAE
sl@0
    26
sl@0
    27
#include <boost/assert.hpp>
sl@0
    28
#include <functional>
sl@0
    29
sl@0
    30
sl@0
    31
namespace boost
sl@0
    32
{
sl@0
    33
sl@0
    34
sl@0
    35
    template
sl@0
    36
    < 
sl@0
    37
              class Fun
sl@0
    38
#ifdef BOOST_NO_SFINAE
sl@0
    39
            , class Result = bool
sl@0
    40
#endif        
sl@0
    41
    >
sl@0
    42
    class indirect_fun
sl@0
    43
    {
sl@0
    44
        Fun fun;
sl@0
    45
    public:
sl@0
    46
        indirect_fun() : fun(Fun())
sl@0
    47
        { }
sl@0
    48
        
sl@0
    49
        indirect_fun( Fun f ) : fun(f)
sl@0
    50
        { }
sl@0
    51
    
sl@0
    52
        template< class T >
sl@0
    53
#ifdef BOOST_NO_SFINAE
sl@0
    54
        Result    
sl@0
    55
#else            
sl@0
    56
        BOOST_DEDUCED_TYPENAME result_of< Fun( BOOST_DEDUCED_TYPENAME pointee<T>::type ) >::type 
sl@0
    57
#endif            
sl@0
    58
        operator()( const T& r ) const
sl@0
    59
        { 
sl@0
    60
            return fun( *r );
sl@0
    61
        }
sl@0
    62
    
sl@0
    63
        template< class T, class U >
sl@0
    64
#ifdef BOOST_NO_SFINAE
sl@0
    65
        Result    
sl@0
    66
#else                        
sl@0
    67
        BOOST_DEDUCED_TYPENAME result_of< Fun( BOOST_DEDUCED_TYPENAME pointee<T>::type, 
sl@0
    68
                                               BOOST_DEDUCED_TYPENAME pointee<U>::type ) >::type
sl@0
    69
#endif            
sl@0
    70
        operator()( const T& r, const U& r2 ) const
sl@0
    71
        { 
sl@0
    72
            return fun( *r, *r2 ); 
sl@0
    73
        }
sl@0
    74
    };
sl@0
    75
sl@0
    76
    template< class Fun >
sl@0
    77
    inline indirect_fun<Fun> make_indirect_fun( Fun f )
sl@0
    78
    {
sl@0
    79
        return indirect_fun<Fun>( f );
sl@0
    80
    }
sl@0
    81
sl@0
    82
sl@0
    83
    template
sl@0
    84
    < 
sl@0
    85
        class Fun, 
sl@0
    86
        class Arg1, 
sl@0
    87
        class Arg2 = Arg1 
sl@0
    88
#ifdef BOOST_NO_SFINAE
sl@0
    89
      , class Result = bool   
sl@0
    90
#endif           
sl@0
    91
    >
sl@0
    92
    class void_ptr_indirect_fun
sl@0
    93
    {
sl@0
    94
        Fun fun;
sl@0
    95
    public:
sl@0
    96
        
sl@0
    97
        void_ptr_indirect_fun() : fun(Fun())
sl@0
    98
        { }
sl@0
    99
sl@0
   100
        void_ptr_indirect_fun( Fun f ) : fun(f)
sl@0
   101
        { }
sl@0
   102
#ifdef BOOST_NO_SFINAE
sl@0
   103
        Result    
sl@0
   104
#else            
sl@0
   105
        BOOST_DEDUCED_TYPENAME result_of< Fun( Arg1 ) >::type 
sl@0
   106
#endif            
sl@0
   107
        operator()( const void* r ) const
sl@0
   108
        { 
sl@0
   109
            BOOST_ASSERT( r != 0 );
sl@0
   110
            return fun( * static_cast<const Arg1*>( r ) );
sl@0
   111
        }
sl@0
   112
sl@0
   113
#ifdef BOOST_NO_SFINAE
sl@0
   114
        Result    
sl@0
   115
#else                    
sl@0
   116
        BOOST_DEDUCED_TYPENAME result_of< Fun( Arg1, Arg2 ) >::type 
sl@0
   117
#endif            
sl@0
   118
        operator()( const void* l, const void* r ) const
sl@0
   119
        { 
sl@0
   120
            BOOST_ASSERT( l != 0 && r != 0 );
sl@0
   121
            return fun( * static_cast<const Arg1*>( l ), * static_cast<const Arg2*>( r ) );
sl@0
   122
        }
sl@0
   123
    };
sl@0
   124
sl@0
   125
    template< class Arg, class Fun >
sl@0
   126
    inline void_ptr_indirect_fun<Fun,Arg> make_void_ptr_indirect_fun( Fun f )
sl@0
   127
    {
sl@0
   128
        return void_ptr_indirect_fun<Fun,Arg>( f );
sl@0
   129
    }
sl@0
   130
     
sl@0
   131
} // namespace 'boost'
sl@0
   132
sl@0
   133
#endif