Mercurial > octave-nkf
comparison liboctave/lo-traits.h @ 8726:0f6683a8150a
some comments for lo-traits.h
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 12 Feb 2009 03:03:59 -0500 |
parents | d5af326a3ede |
children | e793865ede63 |
comparison
equal
deleted
inserted
replaced
8725:d5af326a3ede | 8726:0f6683a8150a |
---|---|
21 */ | 21 */ |
22 | 22 |
23 #if !defined (octave_liboctave_traits_h) | 23 #if !defined (octave_liboctave_traits_h) |
24 #define octave_liboctave_traits_h 1 | 24 #define octave_liboctave_traits_h 1 |
25 | 25 |
26 // Ideas for these classes taken from C++ Templates, The Complete | |
27 // Guide by David Vandevoorde and Nicolai M. Josuttis, Addison-Wesley | |
28 // (2003). | |
29 | |
30 // Select a type based on the value of a constant expression. | |
31 | |
26 template <bool cond, typename T1, typename T2> | 32 template <bool cond, typename T1, typename T2> |
27 class if_then_else; | 33 class if_then_else; |
28 | 34 |
29 template<typename T1, typename T2> | 35 template<typename T1, typename T2> |
30 class if_then_else<true, T1, T2> | 36 class if_then_else<true, T1, T2> |
39 { | 45 { |
40 public: | 46 public: |
41 | 47 |
42 typedef T2 result; | 48 typedef T2 result; |
43 }; | 49 }; |
50 | |
51 // Determine whether a template paramter is a class type. | |
44 | 52 |
45 template<typename T1> | 53 template<typename T1> |
46 class is_class_type | 54 class is_class_type |
47 { | 55 { |
48 private: | 56 private: |
60 | 68 |
61 enum { yes = sizeof (is_class_type_test<T1> (0)) == 1 }; | 69 enum { yes = sizeof (is_class_type_test<T1> (0)) == 1 }; |
62 enum { no = ! yes }; | 70 enum { no = ! yes }; |
63 }; | 71 }; |
64 | 72 |
73 // Define typename ref_param<T>::type as T const& if T is a class | |
74 // type. Otherwise, define it to be T. | |
75 | |
65 template<typename T> | 76 template<typename T> |
66 class ref_param | 77 class ref_param |
67 { | 78 { |
68 public: | 79 public: |
69 | 80 |