Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
is_a.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_METAL_IS_A_HH
27 # define MLN_METAL_IS_A_HH
28 
32 
33 # include <mln/metal/bool.hh>
34 
35 
44 # define mlc_is_a(T, M) mln::metal::is_a<T, M>
45 
46 
47 // Allows to write somthing like "mlc_is_a(T<P1,P2>, M)" without
48 // getting trouble with the preprocessor due to the 1st comma.
49 # define mlc_is_a__1comma(Tleft, Tright, M) mln::metal::is_a< Tleft,Tright , M >
50 
51 
52 
53 namespace mln
54 {
55 
56  namespace metal
57  {
58 
59  namespace internal
60  {
61 
62  typedef char yes_;
63  struct no_ { char dummy[2]; };
64 
65  template <typename T>
66  struct make_
67  {
68  static T* ptr();
69  };
70 
71  template <typename T>
72  struct make_< T& >
73  {
74  static T* ptr();
75  };
76 
77  template <typename T, template <class> class M>
78  struct helper_is_a_
79  {
80 
81  template<class V>
82  static yes_ selector(M<V>*);
83  static no_ selector(...);
84  };
85 
86  } // end of namespace mln::metal::internal
87 
88 
89 
93  //
94  template <typename T, template <class> class M>
95  struct is_a : bool_<( sizeof( internal::helper_is_a_< T, M >::selector(internal::make_< T >::ptr()) )
96  ==
97  sizeof( internal::yes_ ) )>
98  {};
99 
100  template <typename T, template <class> class M>
101  struct is_a< const T, M > : is_a< T, M >::eval
102  {};
103 
104  template <typename T, template <class> class M>
105  struct is_a< T&, M > : is_a< T, M >::eval
106  {};
107 
108  template <typename T, template <class> class M>
109  struct is_a< const T&, M > : is_a< T, M >::eval
110  {};
111 
112 
113  } // end of namespace mln::metal
114 
115 } // end of namespace mln
116 
117 
118 #endif // ! MLN_METAL_IS_A_HH