numeric.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // -- numeric.hpp -- Boost Lambda Library -----------------------------------
  2. // Copyright (C) 2002 Jaakko Jarvi ([email protected])
  3. // Copyright (C) 2002 Gary Powell ([email protected])
  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. #ifndef BOOST_LAMBDA_NUMERIC_HPP
  11. #define BOOST_LAMBDA_NUMERIC_HPP
  12. #include "boost/lambda/core.hpp"
  13. #include <numeric>
  14. namespace boost {
  15. namespace lambda {
  16. namespace ll {
  17. // accumulate ---------------------------------
  18. struct accumulate {
  19. template <class Args>
  20. struct sig {
  21. typedef typename boost::remove_const<
  22. typename boost::tuples::element<3, Args>::type
  23. >::type type;
  24. };
  25. template <class A, class B, class C>
  26. C
  27. operator()(A a, B b, C c) const
  28. { return ::std::accumulate(a, b, c); }
  29. template <class A, class B, class C, class D>
  30. C
  31. operator()(A a, B b, C c, D d) const
  32. { return ::std::accumulate(a, b, c, d); }
  33. };
  34. // inner_product ---------------------------------
  35. struct inner_product {
  36. template <class Args>
  37. struct sig {
  38. typedef typename boost::remove_const<
  39. typename boost::tuples::element<4, Args>::type
  40. >::type type;
  41. };
  42. template <class A, class B, class C, class D>
  43. D
  44. operator()(A a, B b, C c, D d) const
  45. { return ::std::inner_product(a, b, c, d); }
  46. template <class A, class B, class C, class D, class E, class F>
  47. D
  48. operator()(A a, B b, C c, D d, E e, F f) const
  49. { return ::std::inner_product(a, b, c, d, e, f); }
  50. };
  51. // partial_sum ---------------------------------
  52. struct partial_sum {
  53. template <class Args>
  54. struct sig {
  55. typedef typename boost::remove_const<
  56. typename boost::tuples::element<3, Args>::type
  57. >::type type;
  58. };
  59. template <class A, class B, class C>
  60. C
  61. operator()(A a, B b, C c) const
  62. { return ::std::partial_sum(a, b, c); }
  63. template <class A, class B, class C, class D>
  64. C
  65. operator()(A a, B b, C c, D d) const
  66. { return ::std::partial_sum(a, b, c, d); }
  67. };
  68. // adjacent_difference ---------------------------------
  69. struct adjacent_difference {
  70. template <class Args>
  71. struct sig {
  72. typedef typename boost::remove_const<
  73. typename boost::tuples::element<3, Args>::type
  74. >::type type;
  75. };
  76. template <class A, class B, class C>
  77. C
  78. operator()(A a, B b, C c) const
  79. { return ::std::adjacent_difference(a, b, c); }
  80. template <class A, class B, class C, class D>
  81. C
  82. operator()(A a, B b, C c, D d) const
  83. { return ::std::adjacent_difference(a, b, c, d); }
  84. };
  85. } // end of ll namespace
  86. } // end of lambda namespace
  87. } // end of boost namespace
  88. #endif