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