epoc32/include/stdapis/boost/functional.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/functional.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,548 @@
     1.4 +// ------------------------------------------------------------------------------
     1.5 +// Copyright (c) 2000 Cadenza New Zealand Ltd
     1.6 +// Distributed under the Boost Software License, Version 1.0. (See accompany-
     1.7 +// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     1.8 +// ------------------------------------------------------------------------------
     1.9 +// Boost functional.hpp header file
    1.10 +// See http://www.boost.org/libs/functional for documentation.
    1.11 +// ------------------------------------------------------------------------------
    1.12 +// $Id: functional.hpp,v 1.4.20.1 2006/12/02 14:17:26 andreas_huber69 Exp $
    1.13 +// ------------------------------------------------------------------------------
    1.14 +
    1.15 +#ifndef BOOST_FUNCTIONAL_HPP
    1.16 +#define BOOST_FUNCTIONAL_HPP
    1.17 +
    1.18 +#include <boost/config.hpp>
    1.19 +#include <boost/call_traits.hpp>
    1.20 +#include <functional>
    1.21 +
    1.22 +namespace boost
    1.23 +{
    1.24 +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
    1.25 +    // --------------------------------------------------------------------------
    1.26 +    // The following traits classes allow us to avoid the need for ptr_fun
    1.27 +    // because the types of arguments and the result of a function can be 
    1.28 +    // deduced.
    1.29 +    //
    1.30 +    // In addition to the standard types defined in unary_function and 
    1.31 +    // binary_function, we add
    1.32 +    //
    1.33 +    // - function_type, the type of the function or function object itself.
    1.34 +    //
    1.35 +    // - param_type, the type that should be used for passing the function or
    1.36 +    //   function object as an argument.
    1.37 +    // --------------------------------------------------------------------------
    1.38 +    namespace detail
    1.39 +    {
    1.40 +        template <class Operation>
    1.41 +        struct unary_traits_imp;
    1.42 +        
    1.43 +        template <class Operation>
    1.44 +        struct unary_traits_imp<Operation*>
    1.45 +        {
    1.46 +            typedef Operation                         function_type;
    1.47 +            typedef const function_type &             param_type;
    1.48 +            typedef typename Operation::result_type   result_type;
    1.49 +            typedef typename Operation::argument_type argument_type;
    1.50 +        };
    1.51 +
    1.52 +        template <class R, class A>
    1.53 +        struct unary_traits_imp<R(*)(A)>
    1.54 +        {
    1.55 +            typedef R (*function_type)(A);
    1.56 +            typedef R (*param_type)(A);
    1.57 +            typedef R result_type;
    1.58 +            typedef A argument_type;
    1.59 +        };
    1.60 +
    1.61 +        template <class Operation>
    1.62 +        struct binary_traits_imp;
    1.63 +
    1.64 +        template <class Operation>
    1.65 +        struct binary_traits_imp<Operation*>
    1.66 +        {
    1.67 +            typedef Operation                                function_type;
    1.68 +            typedef const function_type &                    param_type;
    1.69 +            typedef typename Operation::result_type          result_type;
    1.70 +            typedef typename Operation::first_argument_type  first_argument_type;
    1.71 +            typedef typename Operation::second_argument_type second_argument_type;
    1.72 +        };
    1.73 +        
    1.74 +        template <class R, class A1, class A2>
    1.75 +        struct binary_traits_imp<R(*)(A1,A2)>
    1.76 +        {
    1.77 +            typedef R (*function_type)(A1,A2);
    1.78 +            typedef R (*param_type)(A1,A2);
    1.79 +            typedef R result_type;
    1.80 +            typedef A1 first_argument_type;
    1.81 +            typedef A2 second_argument_type;
    1.82 +        };
    1.83 +    } // namespace detail
    1.84 +    
    1.85 +    template <class Operation>
    1.86 +    struct unary_traits
    1.87 +    {
    1.88 +        typedef typename detail::unary_traits_imp<Operation*>::function_type function_type;
    1.89 +        typedef typename detail::unary_traits_imp<Operation*>::param_type    param_type;
    1.90 +        typedef typename detail::unary_traits_imp<Operation*>::result_type   result_type;
    1.91 +        typedef typename detail::unary_traits_imp<Operation*>::argument_type argument_type;
    1.92 +    }; 
    1.93 +
    1.94 +    template <class R, class A>
    1.95 +    struct unary_traits<R(*)(A)>
    1.96 +    {
    1.97 +        typedef R (*function_type)(A);
    1.98 +        typedef R (*param_type)(A);
    1.99 +        typedef R result_type;
   1.100 +        typedef A argument_type;
   1.101 +    };
   1.102 +
   1.103 +    template <class Operation>
   1.104 +    struct binary_traits
   1.105 +    {
   1.106 +        typedef typename detail::binary_traits_imp<Operation*>::function_type        function_type;
   1.107 +        typedef typename detail::binary_traits_imp<Operation*>::param_type           param_type;
   1.108 +        typedef typename detail::binary_traits_imp<Operation*>::result_type          result_type;
   1.109 +        typedef typename detail::binary_traits_imp<Operation*>::first_argument_type  first_argument_type;
   1.110 +        typedef typename detail::binary_traits_imp<Operation*>::second_argument_type second_argument_type;
   1.111 +    };
   1.112 +    
   1.113 +    template <class R, class A1, class A2>
   1.114 +    struct binary_traits<R(*)(A1,A2)>
   1.115 +    {
   1.116 +        typedef R (*function_type)(A1,A2);
   1.117 +        typedef R (*param_type)(A1,A2);
   1.118 +        typedef R result_type;
   1.119 +        typedef A1 first_argument_type;
   1.120 +        typedef A2 second_argument_type;
   1.121 +    };
   1.122 +#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.123 +    // --------------------------------------------------------------------------
   1.124 +    // If we have no partial specialisation available, decay to a situation
   1.125 +    // that is no worse than in the Standard, i.e., ptr_fun will be required.
   1.126 +    // --------------------------------------------------------------------------
   1.127 +
   1.128 +    template <class Operation>
   1.129 +    struct unary_traits
   1.130 +    {
   1.131 +        typedef Operation                         function_type;
   1.132 +        typedef const Operation&                  param_type;
   1.133 +        typedef typename Operation::result_type   result_type;
   1.134 +        typedef typename Operation::argument_type argument_type;
   1.135 +    }; 
   1.136 +    
   1.137 +    template <class Operation>
   1.138 +    struct binary_traits
   1.139 +    {
   1.140 +        typedef Operation                                function_type;
   1.141 +        typedef const Operation &                        param_type;
   1.142 +        typedef typename Operation::result_type          result_type;
   1.143 +        typedef typename Operation::first_argument_type  first_argument_type;
   1.144 +        typedef typename Operation::second_argument_type second_argument_type;
   1.145 +    };    
   1.146 +#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.147 +    
   1.148 +    // --------------------------------------------------------------------------
   1.149 +    // unary_negate, not1
   1.150 +    // --------------------------------------------------------------------------
   1.151 +    template <class Predicate>
   1.152 +    class unary_negate
   1.153 +        : public std::unary_function<typename unary_traits<Predicate>::argument_type,bool>
   1.154 +    {
   1.155 +      public:
   1.156 +        explicit unary_negate(typename unary_traits<Predicate>::param_type x)
   1.157 +            :
   1.158 +            pred(x)
   1.159 +        {}
   1.160 +        bool operator()(typename call_traits<typename unary_traits<Predicate>::argument_type>::param_type x) const
   1.161 +        {
   1.162 +            return !pred(x);
   1.163 +        }
   1.164 +      private:
   1.165 +        typename unary_traits<Predicate>::function_type pred;
   1.166 +    };
   1.167 +
   1.168 +    template <class Predicate>
   1.169 +    unary_negate<Predicate> not1(const Predicate &pred)
   1.170 +    {
   1.171 +        // The cast is to placate Borland C++Builder in certain circumstances.
   1.172 +        // I don't think it should be necessary.
   1.173 +        return unary_negate<Predicate>((typename unary_traits<Predicate>::param_type)pred);
   1.174 +    }
   1.175 +
   1.176 +    template <class Predicate>
   1.177 +    unary_negate<Predicate> not1(Predicate &pred)
   1.178 +    {
   1.179 +        return unary_negate<Predicate>(pred);
   1.180 +    }
   1.181 +
   1.182 +    // --------------------------------------------------------------------------
   1.183 +    // binary_negate, not2
   1.184 +    // --------------------------------------------------------------------------
   1.185 +    template <class Predicate>
   1.186 +    class binary_negate
   1.187 +        : public std::binary_function<typename binary_traits<Predicate>::first_argument_type,
   1.188 +                                      typename binary_traits<Predicate>::second_argument_type,
   1.189 +                                      bool>
   1.190 +    {
   1.191 +      public:
   1.192 +        explicit binary_negate(typename binary_traits<Predicate>::param_type x)
   1.193 +            :
   1.194 +            pred(x)
   1.195 +        {}
   1.196 +        bool operator()(typename call_traits<typename binary_traits<Predicate>::first_argument_type>::param_type x,
   1.197 +                        typename call_traits<typename binary_traits<Predicate>::second_argument_type>::param_type y) const
   1.198 +        {
   1.199 +            return !pred(x,y);
   1.200 +        }
   1.201 +      private:
   1.202 +        typename binary_traits<Predicate>::function_type pred;
   1.203 +    };
   1.204 +
   1.205 +    template <class Predicate>
   1.206 +    binary_negate<Predicate> not2(const Predicate &pred)
   1.207 +    {
   1.208 +        // The cast is to placate Borland C++Builder in certain circumstances.
   1.209 +        // I don't think it should be necessary.
   1.210 +        return binary_negate<Predicate>((typename binary_traits<Predicate>::param_type)pred);
   1.211 +    }
   1.212 +
   1.213 +    template <class Predicate>
   1.214 +    binary_negate<Predicate> not2(Predicate &pred)
   1.215 +    {
   1.216 +        return binary_negate<Predicate>(pred);
   1.217 +    }
   1.218 +        
   1.219 +    // --------------------------------------------------------------------------
   1.220 +    // binder1st, bind1st
   1.221 +    // --------------------------------------------------------------------------
   1.222 +    template <class Operation>
   1.223 +    class binder1st
   1.224 +        : public std::unary_function<typename binary_traits<Operation>::second_argument_type,
   1.225 +                                     typename binary_traits<Operation>::result_type>
   1.226 +    {       
   1.227 +      public:
   1.228 +        binder1st(typename binary_traits<Operation>::param_type x,
   1.229 +                  typename call_traits<typename binary_traits<Operation>::first_argument_type>::param_type y)
   1.230 +            :
   1.231 +            op(x), value(y)
   1.232 +        {}
   1.233 +        
   1.234 +        typename binary_traits<Operation>::result_type
   1.235 +        operator()(typename call_traits<typename binary_traits<Operation>::second_argument_type>::param_type x) const
   1.236 +        {
   1.237 +            return op(value, x);
   1.238 +        }
   1.239 +        
   1.240 +      protected:
   1.241 +        typename binary_traits<Operation>::function_type op;
   1.242 +        typename binary_traits<Operation>::first_argument_type value;
   1.243 +    };
   1.244 +
   1.245 +    template <class Operation>
   1.246 +    inline binder1st<Operation> bind1st(const Operation &op,
   1.247 +                                        typename call_traits<
   1.248 +                                                    typename binary_traits<Operation>::first_argument_type
   1.249 +                                        >::param_type x)
   1.250 +    {
   1.251 +        // The cast is to placate Borland C++Builder in certain circumstances.
   1.252 +        // I don't think it should be necessary.
   1.253 +        return binder1st<Operation>((typename binary_traits<Operation>::param_type)op, x);
   1.254 +    }
   1.255 +
   1.256 +    template <class Operation>
   1.257 +    inline binder1st<Operation> bind1st(Operation &op,
   1.258 +                                        typename call_traits<
   1.259 +                                                    typename binary_traits<Operation>::first_argument_type
   1.260 +                                        >::param_type x)
   1.261 +    {
   1.262 +        return binder1st<Operation>(op, x);
   1.263 +    }
   1.264 +
   1.265 +    // --------------------------------------------------------------------------
   1.266 +    // binder2nd, bind2nd
   1.267 +    // --------------------------------------------------------------------------
   1.268 +    template <class Operation>
   1.269 +    class binder2nd
   1.270 +        : public std::unary_function<typename binary_traits<Operation>::first_argument_type,
   1.271 +                                     typename binary_traits<Operation>::result_type>
   1.272 +    {
   1.273 +      public:
   1.274 +        binder2nd(typename binary_traits<Operation>::param_type x,
   1.275 +                  typename call_traits<typename binary_traits<Operation>::second_argument_type>::param_type y)
   1.276 +            :
   1.277 +            op(x), value(y)
   1.278 +        {}
   1.279 +        
   1.280 +        typename binary_traits<Operation>::result_type
   1.281 +        operator()(typename call_traits<typename binary_traits<Operation>::first_argument_type>::param_type x) const
   1.282 +        {
   1.283 +            return op(x, value);
   1.284 +        }               
   1.285 +        
   1.286 +      protected:
   1.287 +        typename binary_traits<Operation>::function_type op;
   1.288 +        typename binary_traits<Operation>::second_argument_type value;
   1.289 +    };
   1.290 +
   1.291 +    template <class Operation>
   1.292 +    inline binder2nd<Operation> bind2nd(const Operation &op,
   1.293 +                                        typename call_traits<
   1.294 +                                                    typename binary_traits<Operation>::second_argument_type
   1.295 +                                        >::param_type x)
   1.296 +    {
   1.297 +        // The cast is to placate Borland C++Builder in certain circumstances.
   1.298 +        // I don't think it should be necessary.
   1.299 +        return binder2nd<Operation>((typename binary_traits<Operation>::param_type)op, x);
   1.300 +    }
   1.301 +
   1.302 +    template <class Operation>
   1.303 +    inline binder2nd<Operation> bind2nd(Operation &op,
   1.304 +                                        typename call_traits<
   1.305 +                                                    typename binary_traits<Operation>::second_argument_type
   1.306 +                                        >::param_type x)
   1.307 +    {
   1.308 +        return binder2nd<Operation>(op, x);
   1.309 +    }
   1.310 +
   1.311 +    // --------------------------------------------------------------------------
   1.312 +    // mem_fun, etc
   1.313 +    // --------------------------------------------------------------------------
   1.314 +    template <class S, class T>
   1.315 +    class mem_fun_t : public std::unary_function<T*, S>
   1.316 +    {
   1.317 +      public:
   1.318 +        explicit mem_fun_t(S (T::*p)())
   1.319 +            :
   1.320 +            ptr(p)
   1.321 +        {}
   1.322 +        S operator()(T* p) const
   1.323 +        {
   1.324 +            return (p->*ptr)();
   1.325 +        }
   1.326 +      private:
   1.327 +        S (T::*ptr)();
   1.328 +    };
   1.329 +
   1.330 +    template <class S, class T, class A>
   1.331 +    class mem_fun1_t : public std::binary_function<T*, A, S>
   1.332 +    {
   1.333 +      public:   
   1.334 +        explicit mem_fun1_t(S (T::*p)(A))
   1.335 +            :
   1.336 +            ptr(p)
   1.337 +        {}
   1.338 +        S operator()(T* p, typename call_traits<A>::param_type x) const
   1.339 +        {
   1.340 +            return (p->*ptr)(x);
   1.341 +        }
   1.342 +      private:
   1.343 +        S (T::*ptr)(A);
   1.344 +    };
   1.345 +
   1.346 +    template <class S, class T>
   1.347 +    class const_mem_fun_t : public std::unary_function<const T*, S>
   1.348 +    {
   1.349 +      public:
   1.350 +        explicit const_mem_fun_t(S (T::*p)() const)
   1.351 +            :
   1.352 +            ptr(p)
   1.353 +        {}
   1.354 +        S operator()(const T* p) const
   1.355 +        {
   1.356 +            return (p->*ptr)();
   1.357 +        }
   1.358 +      private:
   1.359 +        S (T::*ptr)() const;        
   1.360 +    };
   1.361 +
   1.362 +    template <class S, class T, class A>
   1.363 +    class const_mem_fun1_t : public std::binary_function<const T*, A, S>
   1.364 +    {
   1.365 +      public:
   1.366 +        explicit const_mem_fun1_t(S (T::*p)(A) const)
   1.367 +            :
   1.368 +            ptr(p)
   1.369 +        {}
   1.370 +        S operator()(const T* p, typename call_traits<A>::param_type x) const
   1.371 +        {
   1.372 +            return (p->*ptr)(x);
   1.373 +        }
   1.374 +      private:
   1.375 +        S (T::*ptr)(A) const;
   1.376 +    };
   1.377 +    
   1.378 +    template<class S, class T>
   1.379 +    inline mem_fun_t<S,T> mem_fun(S (T::*f)())
   1.380 +    {
   1.381 +        return mem_fun_t<S,T>(f);
   1.382 +    }
   1.383 +    
   1.384 +    template<class S, class T, class A>
   1.385 +    inline mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A))
   1.386 +    {
   1.387 +        return mem_fun1_t<S,T,A>(f);
   1.388 +    }
   1.389 +
   1.390 +#ifndef BOOST_NO_POINTER_TO_MEMBER_CONST
   1.391 +    template<class S, class T>
   1.392 +    inline const_mem_fun_t<S,T> mem_fun(S (T::*f)() const)
   1.393 +    {
   1.394 +        return const_mem_fun_t<S,T>(f);
   1.395 +    }
   1.396 +    
   1.397 +    template<class S, class T, class A>
   1.398 +    inline const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const)
   1.399 +    {
   1.400 +        return const_mem_fun1_t<S,T,A>(f);
   1.401 +    }
   1.402 +#endif // BOOST_NO_POINTER_TO_MEMBER_CONST
   1.403 +
   1.404 +    // --------------------------------------------------------------------------
   1.405 +    // mem_fun_ref, etc
   1.406 +    // --------------------------------------------------------------------------
   1.407 +    template <class S, class T>
   1.408 +    class mem_fun_ref_t : public std::unary_function<T&, S>
   1.409 +    {
   1.410 +      public:
   1.411 +        explicit mem_fun_ref_t(S (T::*p)())
   1.412 +            :
   1.413 +            ptr(p)
   1.414 +        {}
   1.415 +        S operator()(T& p) const
   1.416 +        {
   1.417 +            return (p.*ptr)();
   1.418 +        }
   1.419 +      private:
   1.420 +        S (T::*ptr)();
   1.421 +    };
   1.422 +
   1.423 +    template <class S, class T, class A>
   1.424 +    class mem_fun1_ref_t : public std::binary_function<T&, A, S>
   1.425 +    {
   1.426 +      public:
   1.427 +        explicit mem_fun1_ref_t(S (T::*p)(A))
   1.428 +            :
   1.429 +            ptr(p)
   1.430 +        {}
   1.431 +        S operator()(T& p, typename call_traits<A>::param_type x) const
   1.432 +        {
   1.433 +            return (p.*ptr)(x);
   1.434 +        }
   1.435 +      private:
   1.436 +        S (T::*ptr)(A);
   1.437 +    };
   1.438 +    
   1.439 +    template <class S, class T>
   1.440 +    class const_mem_fun_ref_t : public std::unary_function<const T&, S>
   1.441 +    {
   1.442 +      public:
   1.443 +        explicit const_mem_fun_ref_t(S (T::*p)() const)
   1.444 +            :
   1.445 +            ptr(p)
   1.446 +        {}
   1.447 +        
   1.448 +        S operator()(const T &p) const
   1.449 +        {
   1.450 +            return (p.*ptr)();
   1.451 +        }
   1.452 +      private:
   1.453 +        S (T::*ptr)() const;
   1.454 +    };
   1.455 +
   1.456 +    template <class S, class T, class A>
   1.457 +    class const_mem_fun1_ref_t : public std::binary_function<const T&, A, S>
   1.458 +    {
   1.459 +      public:
   1.460 +        explicit const_mem_fun1_ref_t(S (T::*p)(A) const)
   1.461 +            :
   1.462 +            ptr(p)
   1.463 +        {}
   1.464 +
   1.465 +        S operator()(const T& p, typename call_traits<A>::param_type x) const
   1.466 +        {
   1.467 +            return (p.*ptr)(x);
   1.468 +        }
   1.469 +      private:
   1.470 +        S (T::*ptr)(A) const;
   1.471 +    };
   1.472 +    
   1.473 +    template<class S, class T>
   1.474 +    inline mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)())
   1.475 +    {
   1.476 +        return mem_fun_ref_t<S,T>(f);
   1.477 +    }
   1.478 +
   1.479 +    template<class S, class T, class A>
   1.480 +    inline mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A))
   1.481 +    {
   1.482 +        return mem_fun1_ref_t<S,T,A>(f);
   1.483 +    }
   1.484 +
   1.485 +#ifndef BOOST_NO_POINTER_TO_MEMBER_CONST
   1.486 +    template<class S, class T>
   1.487 +    inline const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const)
   1.488 +    {
   1.489 +        return const_mem_fun_ref_t<S,T>(f);
   1.490 +    }
   1.491 +
   1.492 +    template<class S, class T, class A>
   1.493 +    inline const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const)
   1.494 +    {
   1.495 +        return const_mem_fun1_ref_t<S,T,A>(f);
   1.496 +    }   
   1.497 +#endif // BOOST_NO_POINTER_TO_MEMBER_CONST
   1.498 +
   1.499 +    // --------------------------------------------------------------------------
   1.500 +    // ptr_fun
   1.501 +    // --------------------------------------------------------------------------
   1.502 +    template <class Arg, class Result>
   1.503 +    class pointer_to_unary_function : public std::unary_function<Arg,Result>
   1.504 +    {
   1.505 +      public:
   1.506 +        explicit pointer_to_unary_function(Result (*f)(Arg))
   1.507 +            :
   1.508 +            func(f)
   1.509 +        {}
   1.510 +
   1.511 +        Result operator()(typename call_traits<Arg>::param_type x) const
   1.512 +        {
   1.513 +            return func(x);
   1.514 +        }
   1.515 +        
   1.516 +      private:
   1.517 +        Result (*func)(Arg);
   1.518 +    };
   1.519 +
   1.520 +    template <class Arg, class Result>
   1.521 +    inline pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg))
   1.522 +    {
   1.523 +        return pointer_to_unary_function<Arg,Result>(f);
   1.524 +    }
   1.525 +
   1.526 +    template <class Arg1, class Arg2, class Result>
   1.527 +    class pointer_to_binary_function : public std::binary_function<Arg1,Arg2,Result>
   1.528 +    {
   1.529 +      public:
   1.530 +        explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2))
   1.531 +            :
   1.532 +            func(f)
   1.533 +        {}
   1.534 +        
   1.535 +        Result operator()(typename call_traits<Arg1>::param_type x, typename call_traits<Arg2>::param_type y) const
   1.536 +        {
   1.537 +            return func(x,y);
   1.538 +        }
   1.539 +        
   1.540 +      private:
   1.541 +        Result (*func)(Arg1, Arg2);
   1.542 +    };
   1.543 +
   1.544 +    template <class Arg1, class Arg2, class Result>
   1.545 +    inline pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1, Arg2))
   1.546 +    {
   1.547 +        return pointer_to_binary_function<Arg1,Arg2,Result>(f);
   1.548 +    }
   1.549 +} // namespace boost
   1.550 +
   1.551 +#endif