Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
compose.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_FUN_COMPOSE_HH
27 # define MLN_FUN_COMPOSE_HH
28 
29 # include <mln/fun/binary.hh>
30 # include <mln/fun/composition.hh>
31 # include <mln/fun/param.hh>
32 
33 namespace mln
34 {
35  // Composition
36  namespace fun
37  {
38  struct compose : binary<compose> {};
39 
40  namespace internal
41  {
42 
43  template <template <class> class CatF, typename F, template <class> class CatG, typename G>
44  struct compose_helper;
45 
46  }
47 
48  template <template <class> class CatF, typename F,
49  template <class> class CatG, typename G>
50  struct parameter< internal::compose_helper<CatF, F, CatG, G> >
51  {
52  typedef typename internal::composition<CatF, F, CatG, G>::exact_type result;
53  typedef typename result::param param;
54  };
55 
56  namespace internal
57  {
58 
59  template <template <class> class CatF, typename F, template <class> class CatG, typename G>
60  struct compose_helper
61  {
62  typedef F argument1;
63  typedef G argument2;
64 
65  typedef typename composition<CatF, F, CatG, G>::exact_type result;
66  typedef mln_trait_fun_param(result) param;
67 
68  static result read(const F& f, const G& g)
69  {
70  return result(param(f, g));
71  }
72  };
73 
74  } // end of namespace mln::fun::internal
75 
76  } // end of namespace mln::fun
77 
78  namespace trait
79  {
80 
81  namespace next
82  {
83 
84  // All kinds of supported compositions (meta : unary) with (meta or not : unary or binary)
85  template <typename F, typename G>
86  struct set_binary_< mln::fun::compose, mln::Meta_Function_v2v, F, mln::Meta_Function_v2v, G>
87  {
88  typedef mln::fun::internal::compose_helper<mln::Meta_Function_v2v, F, mln::Meta_Function_v2v, G> ret;
89  };
90 
91  template <typename F, typename G>
92  struct set_binary_< mln::fun::compose, mln::Meta_Function_v2v, F, mln::Meta_Function_vv2v, G>
93  {
94  typedef mln::fun::internal::compose_helper<mln::Meta_Function_v2v, F, mln::Meta_Function_vv2v, G> ret;
95  };
96 
97  template <typename F, typename G>
98  struct set_binary_< mln::fun::compose, mln::Meta_Function_v2v, F, mln::Function_v2v, G>
99  {
100  typedef mln::fun::internal::compose_helper<mln::Meta_Function_v2v, F, mln::Function_v2v, G> ret;
101  };
102 
103  template <typename F, typename G>
104  struct set_binary_< mln::fun::compose, mln::Meta_Function_v2v, F, mln::Function_vv2v, G>
105  {
106  typedef mln::fun::internal::compose_helper<mln::Meta_Function_v2v, F, mln::Function_vv2v, G> ret;
107  };
108 
109  } // end of namespace mln::trait::next
110 
111  } // end of namespace mln::trait
112 
113 } // end of namespace mln
114 
115 #endif // ! MLN_FUN_COMPOSE_HH