example_handcrafted.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef EXAMPLE_HANDCRAFTED_HPP
  2. #define EXAMPLE_HANDCRAFTED_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <double_number.hpp>
  8. #include <boost/mpl/int.hpp>
  9. #include <boost/mpl/times.hpp>
  10. #include <boost/mpl/eval_if.hpp>
  11. #include <boost/mpl/minus.hpp>
  12. #include <boost/mpl/plus.hpp>
  13. #include <boost/mpl/less.hpp>
  14. typedef boost::mpl::int_<11> val;
  15. struct fib
  16. {
  17. typedef fib type;
  18. template <class N>
  19. struct impl;
  20. template <class N>
  21. struct apply :
  22. boost::mpl::eval_if<
  23. typename boost::mpl::less<N, boost::mpl::int_<2> >::type,
  24. boost::mpl::int_<1>,
  25. impl<N>
  26. >
  27. {};
  28. };
  29. template <class N>
  30. struct fib::impl :
  31. boost::mpl::plus<
  32. typename fib::apply<
  33. typename boost::mpl::minus<N, boost::mpl::int_<1> >::type
  34. >::type,
  35. typename fib::apply<
  36. typename boost::mpl::minus<N, boost::mpl::int_<2> >::type
  37. >::type
  38. >
  39. {};
  40. struct fact
  41. {
  42. typedef fact type;
  43. template <class N>
  44. struct impl;
  45. template <class N>
  46. struct apply :
  47. boost::mpl::eval_if<
  48. typename boost::mpl::less<N, boost::mpl::int_<1> >::type,
  49. boost::mpl::int_<1>,
  50. impl<N>
  51. >
  52. {};
  53. };
  54. template <class N>
  55. struct fact::impl :
  56. boost::mpl::times<
  57. N,
  58. typename fact::apply<
  59. typename boost::mpl::minus<N, boost::mpl::int_<1> >::type
  60. >::type
  61. >
  62. {};
  63. struct times4
  64. {
  65. typedef times4 type;
  66. template <class N>
  67. struct apply : double_number<typename double_number<N>::type> {};
  68. };
  69. struct times11
  70. {
  71. typedef times11 type;
  72. template <class N>
  73. struct apply : boost::mpl::times<N, val> {};
  74. };
  75. #endif