ossrv_pub/boost_apis/boost/lambda/numeric.hpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // -- numeric.hpp -- Boost Lambda Library -----------------------------------
       
     2 // Copyright (C) 2002 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
       
     3 // Copyright (C) 2002 Gary Powell (gwpowell@hotmail.com)
       
     4 //
       
     5 // Distributed under the Boost Software License, Version 1.0. (See
       
     6 // accompanying file LICENSE_1_0.txt or copy at
       
     7 // http://www.boost.org/LICENSE_1_0.txt)
       
     8 //
       
     9 // For more information, see http://www.boost.org
       
    10 
       
    11 #ifndef BOOST_LAMBDA_NUMERIC_HPP
       
    12 #define BOOST_LAMBDA_NUMERIC_HPP
       
    13 
       
    14 #include "boost/lambda/core.hpp"
       
    15 
       
    16 #include <numeric>
       
    17 
       
    18 namespace boost {
       
    19   namespace lambda {
       
    20 
       
    21 namespace ll {
       
    22 
       
    23 // accumulate ---------------------------------
       
    24 
       
    25 struct accumulate {
       
    26   
       
    27   template <class Args>
       
    28   struct sig { 
       
    29     typedef typename boost::remove_const<
       
    30         typename boost::tuples::element<3, Args>::type 
       
    31      >::type type; 
       
    32   };
       
    33 
       
    34   template <class A, class B, class C>
       
    35   C
       
    36   operator()(A a, B b, C c) const
       
    37   { return ::std::accumulate(a, b, c); }
       
    38 
       
    39   template <class A, class B, class C, class D>
       
    40   C
       
    41   operator()(A a, B b, C c, D d) const
       
    42   { return ::std::accumulate(a, b, c, d); }
       
    43 };
       
    44 
       
    45 // inner_product ---------------------------------
       
    46 
       
    47 struct inner_product {
       
    48   
       
    49   template <class Args>
       
    50   struct sig { 
       
    51     typedef typename boost::remove_const<
       
    52         typename boost::tuples::element<4, Args>::type 
       
    53      >::type type; 
       
    54   };
       
    55 
       
    56   template <class A, class B, class C, class D>
       
    57   D
       
    58   operator()(A a, B b, C c, D d) const
       
    59   { return ::std::inner_product(a, b, c, d); }
       
    60 
       
    61   template <class A, class B, class C, class D, class E, class F>
       
    62   D
       
    63   operator()(A a, B b, C c, D d, E e, F f) const
       
    64   { return ::std::inner_product(a, b, c, d, e, f); }
       
    65 };
       
    66 
       
    67 
       
    68 // partial_sum ---------------------------------
       
    69 
       
    70 struct partial_sum {
       
    71   
       
    72   template <class Args>
       
    73   struct sig { 
       
    74     typedef typename boost::remove_const<
       
    75         typename boost::tuples::element<3, Args>::type 
       
    76      >::type type; 
       
    77   };
       
    78 
       
    79   template <class A, class B, class C>
       
    80   C
       
    81   operator()(A a, B b, C c) const
       
    82   { return ::std::partial_sum(a, b, c); }
       
    83 
       
    84   template <class A, class B, class C, class D>
       
    85   C
       
    86   operator()(A a, B b, C c, D d) const
       
    87   { return ::std::partial_sum(a, b, c, d); }
       
    88 };
       
    89 
       
    90 // adjacent_difference ---------------------------------
       
    91 
       
    92 struct adjacent_difference {
       
    93   
       
    94   template <class Args>
       
    95   struct sig { 
       
    96     typedef typename boost::remove_const<
       
    97         typename boost::tuples::element<3, Args>::type 
       
    98      >::type type; 
       
    99   };
       
   100 
       
   101   template <class A, class B, class C>
       
   102   C
       
   103   operator()(A a, B b, C c) const
       
   104   { return ::std::adjacent_difference(a, b, c); }
       
   105 
       
   106   template <class A, class B, class C, class D>
       
   107   C
       
   108   operator()(A a, B b, C c, D d) const
       
   109   { return ::std::adjacent_difference(a, b, c, d); }
       
   110 };
       
   111 
       
   112 } // end of ll namespace
       
   113 
       
   114 } // end of lambda namespace
       
   115 } // end of boost namespace
       
   116 
       
   117 
       
   118 
       
   119 #endif