2 * Copyright 2002, The libsigc++ Development Team
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _SIGC_TYPE_TRAIT_H_
20 #define _SIGC_TYPE_TRAIT_H_
22 #include <sigc++config.h> //To get SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
27 template <class T_type
>
32 typedef const T_type
& take
;
33 typedef T_type
* pointer
;
36 template <class T_type
, int N
>
37 struct type_trait
<T_type
[N
]>
40 typedef T_type
*& pass
;
41 typedef const T_type
*& take
;
42 typedef T_type
** pointer
;
45 template <class T_type
>
46 struct type_trait
<T_type
&>
51 typedef T_type
* pointer
;
54 template <class T_type
>
55 struct type_trait
<const T_type
&>
57 typedef const T_type type
;
58 typedef const T_type
& pass
;
59 typedef const T_type
& take
;
60 typedef const T_type
* pointer
;
64 struct type_trait
<void>
69 typedef void* pointer
;
75 * Compile-time determination of base-class relationship in C++
76 * (adapted to match the syntax of boost's type_traits library).
78 * Use this to provide a template specialization for a set of types.
81 * template < class T_thing, bool Tval_derives_from_something = sigc::is_base_and_derived<Something, T_thing>::value >
84 * //Standard implementation.
87 * //Specialization for T_things that derive from Something (Tval_derives_from_something is true)
88 * template <class T_thing>
89 * class TheTemplate<T_thing, true>
92 thing.method_that_is_in_something();
95 template <class T_base
, class T_derived
>
96 struct is_base_and_derived
103 #ifndef SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
105 //Allow the internal inner class to access the other (big) inner
106 //class. The Tru64 compiler needs this. murrayc.
107 friend struct internal_class
;
109 //Certain compilers, notably GCC 3.2, require these functions to be inside an inner class.
110 struct internal_class
112 static big
is_base_class_(...);
113 static char is_base_class_(typename type_trait
<T_base
>::pointer
);
117 static const bool value
=
118 sizeof(internal_class::is_base_class_(reinterpret_cast<typename type_trait
<T_derived
>::pointer
>(0))) ==
121 #else //SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
123 //The AIX xlC compiler does not like these 2 functions being in the inner class.
124 //It says "The incomplete type "test" must not be used as a qualifier.
125 //It does not seem necessary anyway. murrayc.
126 static big
is_base_class_(...);
127 static char is_base_class_(typename type_trait
<T_base
>::pointer
);
130 static const bool value
=
131 sizeof(is_base_class_(reinterpret_cast<typename type_trait
<T_derived
>::pointer
>(0))) ==
134 #endif //SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
136 void avoid_gcc3_warning_(); //Not implemented. g++ 3.3.5 (but not 3.3.4, and not 3.4) warn that there are no public methods, even though there is a public variable.
139 template <class T_base
>
140 struct is_base_and_derived
<T_base
, T_base
>
142 static const bool value
= true;
145 } /* namespace sigc */
147 #endif /* _SIGC_TYPE_TRAIT_H_ */