GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
lo-traits.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2009-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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::*)
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
static const bool value
Definition: lo-traits.h:59
is false
Definition: cellfun.cc:400
With real return the complex result
Definition: data.cc:3260
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