aimstil  5.0.5
templateTools.h
Go to the documentation of this file.
1 #ifndef TIL_TEMPLATE_TOOLS_H
2 #define TIL_TEMPLATE_TOOLS_H
3 
7 
8 // includes from BOOST library
9 #include "boost/type_traits.hpp"
10 
11 // includes from TIL library
12 #include "til/til_common.h"
13 
15 #define TIL_FOR_ALL_NUMERIC_TYPES(macro) \
16  macro(bool) \
17  macro(unsigned char) \
18  macro(char) \
19  macro(unsigned short) \
20  macro(short) \
21  macro(int) \
22  macro(unsigned int) \
23  macro(long) \
24  macro(unsigned long) \
25  macro(float) \
26  macro(double) \
27  macro(long double) \
28 
29 
30 namespace til
31 {
32 
33  //------------------------------------------------------------------------------------------------
34 
35  //-------------------------//
36  // true_type, false_type //
37  //-------------------------//
38 
39  struct true_type { static bool const value = true; };
40  struct false_type { static bool const value = false; };
41 
42  //------------------------------------------------------------------------------------------------
43 
44  //-------------//
45  // bool_type //
46  //-------------//
47 
48  template < bool B >
49  struct bool_type : public false_type {};
50  template < >
51  struct bool_type<true> : public true_type {};
52 
53  //------------------------------------------------------------------------------------------------
54 
55  //-----------//
56  // type_if //
57  //-----------//
58 
60  template < bool B, typename TypeIfTrue, typename TypeIfFalse >
61  struct type_if { typedef TypeIfTrue type; };
62  template < typename TypeIfTrue, typename TypeIfFalse >
63  struct type_if<false, TypeIfTrue, TypeIfFalse> { typedef TypeIfFalse type; };
64 
65 
66  //------------------------------------------------------------------------------------------------
67 
68  //-----------//
69  // is_same //
70  //-----------//
71 
72  template < typename T1, typename T2 >
73  struct is_same : public false_type {};
74  template < typename T >
75  struct is_same<T,T> : public true_type {};
76 
77 
78  //------------------------------------------------------------------------------------------------
79 
80  //--------------//
81  // naked_type //
82  //--------------//
83 
84  template < typename T >
85  struct naked_type : public boost::remove_const<typename boost::remove_reference<T>::type> {};
86 
87  //------------------------------------------------------------------------------------------------
88 
91  template < typename T1, typename T2 >
93  : public is_same
94  <
95  typename naked_type<T1>::type,
96  typename naked_type<T2>::type
97  >
98  {};
99 
100  //------------------------------------------------------------------------------------------------
101 
102  //-----------------//
103  // is_same_naked //
104  //-----------------//
105 
106  template < typename T1, typename T2 >
107  struct is_same_naked : public boost::is_same<typename naked_type<T1>::type, typename naked_type<T2>::type> {};
108 
109  //------------------------------------------------------------------------------------------------
110 
111 
112  //-------------------------//
113  // enable_if, disable_if //
114  //-------------------------//
115 
116 
118  template <bool B, class T = void>
119  struct enable_if_c {
120  typedef T type;
121  };
122  template <class T>
123  struct enable_if_c<false, T> {};
124  template <class Cond, class T = void>
125  struct enable_if : public enable_if_c<Cond::value, T> {};
126 
127  template <bool B, class T = void>
128  struct disable_if_c {
129  typedef T type;
130  };
131  template <class T>
132  struct disable_if_c<true, T> {};
133  template <class Cond, class T = void>
134  struct disable_if : public disable_if_c<Cond::value, T> {};
135 
136 
137  //------------------------------------------------------------------------------------------------
138 
139  /*
140  //---------------//
141  // int_to_type //
142  //---------------//
143 
145  template <int N>
146  struct int_to_type
147  {
148  static int const value = N;
149  };
150  */
151 
152  //------------------------------------------------------------------------------------------------
153 
154  //--------//
155  // prec //
156  //--------//
157 
159  template < typename T >
160  struct prec { typedef T type; };
161 
162  //------------------------------------------------------------------------------------------------
163 
164  //--------//
165  // check //
166  //--------//
167 
170 
171  template < bool b >
172  struct check { typedef typename enable_if_c<b>::type type; };
173 
174 } // namespace til
175 
176 
177 #endif
enable_if_c< b >::type type
Fails to compile if b is false.
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
General macros, definitions and functions.
Test whether two types are basically the same as far as rvalue goes, i.e are the same modulo possible...
Definition: templateTools.h:92
static bool const value
Definition: templateTools.h:39
Template to choose between one type or the other depending on some condition.
Definition: templateTools.h:61
TypeIfTrue type
Definition: templateTools.h:61
A dummy class used to pass a precision type for computations to some functions.
Template tool to enable a template specialization under some condition.