8725
|
1 /* |
|
2 |
|
3 Copyright (C) 2009 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_liboctave_traits_h) |
|
24 #define octave_liboctave_traits_h 1 |
|
25 |
|
26 template <bool cond, typename T1, typename T2> |
|
27 class if_then_else; |
|
28 |
|
29 template<typename T1, typename T2> |
|
30 class if_then_else<true, T1, T2> |
|
31 { |
|
32 public: |
|
33 |
|
34 typedef T1 result; |
|
35 }; |
|
36 |
|
37 template<typename T1, typename T2> |
|
38 class if_then_else<false, T1, T2> |
|
39 { |
|
40 public: |
|
41 |
|
42 typedef T2 result; |
|
43 }; |
|
44 |
|
45 template<typename T1> |
|
46 class is_class_type |
|
47 { |
|
48 private: |
|
49 |
|
50 typedef char one; |
|
51 typedef struct { char c[2]; } two; |
|
52 |
|
53 // Classes can have pointers to members. |
|
54 template<typename T2> static one is_class_type_test (int T2::*); |
|
55 |
|
56 // Catch everything else. |
|
57 template<typename T2> static two is_class_type_test (...); |
|
58 |
|
59 public: |
|
60 |
|
61 enum { yes = sizeof (is_class_type_test<T1> (0)) == 1 }; |
|
62 enum { no = ! yes }; |
|
63 }; |
|
64 |
|
65 template<typename T> |
|
66 class ref_param |
|
67 { |
|
68 public: |
|
69 |
|
70 typedef typename if_then_else<is_class_type<T>::no, T, T const&>::result type; |
|
71 }; |
|
72 |
|
73 #endif |
|
74 |
|
75 /* |
|
76 ;;; Local Variables: *** |
|
77 ;;; mode: C *** |
|
78 ;;; page-delimiter: "^/\\*" *** |
|
79 ;;; End: *** |
|
80 */ |