GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lo-traits.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2009-2017 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_lo_traits_h)
24 #define octave_lo_traits_h 1
25 
26 #include "octave-config.h"
27 
28 // Ideas for these classes taken from C++ Templates, The Complete
29 // Guide by David Vandevoorde and Nicolai M. Josuttis, Addison-Wesley
30 // (2003).
31 
32 // Select a type based on the value of a constant expression.
33 
34 template <bool cond, typename T1, typename T2>
36 
37 template <typename T1, typename T2>
38 class if_then_else<true, T1, T2>
39 {
40 public:
41 
42  typedef T1 result;
43 };
44 
45 template <typename T1, typename T2>
46 class if_then_else<false, T1, T2>
47 {
48 public:
49 
50  typedef T2 result;
51 };
52 
53 // Determine whether two types are equal.
54 template <typename T1, typename T2>
56 {
57 public:
58 
59  static const bool value = false;
60 };
61 
62 template <typename T>
63 class equal_types <T, T>
64 {
65 public:
66 
67  static const bool value = true;
68 };
69 
70 // Determine whether a type is an instance of a template.
71 
72 template <template <typename> class Template, typename T>
74 {
75 public:
76 
77  static const bool value = false;
78 };
79 
80 template <template <typename> class Template, typename T>
81 class is_instance <Template, Template<T> >
82 {
83 public:
84 
85  static const bool value = true;
86 };
87 
88 // Determine whether a template paramter is a class type.
89 
90 template <typename T1>
92 {
93 private:
94 
95  typedef char one;
96  typedef struct { char c[2]; } two;
97 
98  // Classes can have pointers to members.
99  template <typename T2> static one is_class_type_test (int T2::*);
100 
101  // Catch everything else.
102  template <typename T2> static two is_class_type_test (...);
103 
104 public:
105 
106  enum { yes = sizeof (is_class_type_test<T1> (0)) == 1 };
107  enum { no = ! yes };
108 };
109 
110 // Define typename ref_param<T>::type as T const& if T is a class
111 // type. Otherwise, define it to be T.
112 
113 template <typename T>
115 {
116 public:
117 
118  typedef typename if_then_else<is_class_type<T>::no, T, T const&>::result type;
119 };
120 
121 // Will turn TemplatedClass<T> to T, leave T otherwise.
122 // Useful for stripping wrapper classes, like octave_int.
123 
124 template <template <typename> class TemplatedClass, typename T>
126 {
127 public:
128  typedef T type;
129 };
130 
131 template <template <typename> class TemplatedClass, typename T>
132 class strip_template_param<TemplatedClass, TemplatedClass<T> >
133 {
134 public:
135  typedef T type;
136 };
137 
138 // Will turn TemplatedClass<T> to TemplatedClass<S>, T to S otherwise.
139 // Useful for generic promotions.
140 
141 template <template <typename> class TemplatedClass, typename T, typename S>
143 {
144 public:
145  typedef S type;
146 };
147 
148 template <template <typename> class TemplatedClass, typename T, typename S>
149 class subst_template_param<TemplatedClass, TemplatedClass<T>, S>
150 {
151 public:
152  typedef TemplatedClass<S> type;
153 };
154 
155 #endif
static one is_class_type_test(int T2::*)
static const bool value
Definition: lo-traits.h:59
is false
Definition: cellfun.cc:398
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
With real return the complex result
Definition: data.cc:3375
if_then_else< is_class_type< T >::no, T, T const & >::result type
Definition: lo-traits.h:118
static const bool value
Definition: lo-traits.h:77