Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
type_inspection.hpp
Go to the documentation of this file.
1/*
2 Copyright 2008 Adobe Systems Incorporated
3 Distributed under the Boost Software License - Version 1.0 (see the accompanying file LICENSE
4 or a copy at https://stlab.github.io/adobe_source_libraries/licenses.html)
5*/
6
7/**************************************************************************************************/
8
9
10#ifndef ADOBE_TYPE_INSPECTION_HPP
11#define ADOBE_TYPE_INSPECTION_HPP
12
13
14namespace adobe {
15
16
17namespace detail {
18struct yes_struct {
19 char a;
20};
21struct no_struct {
22 yes_struct a[2];
23};
24} // namespace detail
25
40#define ADOBE_HAS_TYPE_IMPL(TypeInQuestion) \
41 template <typename C##TypeInQuestion> \
42 struct has_type##TypeInQuestion { \
43 template <typename T##TypeInQuestion> \
44 static adobe::detail::yes_struct SFINAE(typename T##TypeInQuestion::TypeInQuestion*); \
45 template <typename> \
46 static adobe::detail::no_struct SFINAE(...); \
47 static const bool value = \
48 sizeof(SFINAE<C##TypeInQuestion>(0)) == sizeof(adobe::detail::yes_struct); \
49 }
50
70#define ADOBE_HAS_TYPE(C, TypeInQuestion) has_type##TypeInQuestion<C>::value
71
72
78// one of the most important types to look for is 'type', so let's just implement that one here
79template <typename T>
82
83 static const bool value = ADOBE_HAS_TYPE(T, type);
84};
85
86template <typename T, typename Default>
88 template <bool condition, typename IFtype, typename ELSEtype>
89 struct if_has_type {
90 typedef typename IFtype::type type;
91 };
92 template <typename IFtype, typename ELSEtype>
93 struct if_has_type<false, IFtype, ELSEtype> {
94 typedef ELSEtype type;
95 };
96 typedef typename if_has_type<has_type_type<T>::value, T, Default>::type type;
97};
98
99
118#if _MSC_VER <= 1400
119#define ADOBE_HAS_MEMBER_IMPL(Member) \
120 template <class Class> \
121 struct has_member##Member { \
122 __if_exists(Class::Member) { static const bool value = true; } \
123 __if_not_exists(Class::Member) { static const bool value = false; } \
124 }
125#else
126
127namespace detail {
128template <size_t>
129struct member_test_helper {};
130} // namespace detail
131
132#define ADOBE_HAS_MEMBER_IMPL(MemberInQuestion) \
133 template <class Class> \
134 struct has_member##MemberInQuestion { \
135 template <class T##MemberInQuestion> \
136 static adobe::detail::yes_struct SFINAE( \
137 adobe::detail::member_test_helper<sizeof(&T##MemberInQuestion::MemberInQuestion)>*); \
138 template <class> \
139 static adobe::detail::no_struct SFINAE(...); \
140 static const bool value = sizeof(SFINAE<Class>(0)) == sizeof(adobe::detail::yes_struct); \
141 }
142#endif
143
163#define ADOBE_HAS_MEMBER(C, MemberInQuestion) has_member##MemberInQuestion<C>::value
164
165
181#define ADOBE_HAS_TEMPLATE1_IMPL(TemplateInQuestion) \
182 template <typename C##TemplateInQuestion> \
183 struct has_template1##TemplateInQuestion { \
184 template <typename T##TemplateInQuestion> \
185 static adobe::detail::yes_struct \
186 SFINAE(typename T##TemplateInQuestion::template TemplateInQuestion<int>*); \
187 template <typename> \
188 static adobe::detail::no_struct SFINAE(...); \
189 static const bool value = \
190 sizeof(SFINAE<C##TemplateInQuestion>(0)) == sizeof(adobe::detail::yes_struct); \
191 }
192
219#define ADOBE_HAS_TEMPLATE1(C, TemplateInQuestion) has_template1##TemplateInQuestion<C>::value
220
221
223// 2 Arg case
224//
225#define ADOBE_HAS_TEMPLATE2_IMPL(TemplateInQuestion) \
226 template <typename C##TemplateInQuestion> \
227 struct has_template2##TemplateInQuestion { \
228 template <typename T##TemplateInQuestion> \
229 static adobe::detail::yes_struct \
230 SFINAE(typename T##TemplateInQuestion::template TemplateInQuestion<int, int>*); \
231 template <typename> \
232 static adobe::detail::no_struct SFINAE(...); \
233 static const bool value = \
234 sizeof(SFINAE<C##TemplateInQuestion>(0)) == sizeof(adobe::detail::yes_struct); \
235 }
236
237#define ADOBE_HAS_TEMPLATE2(C, TemplateInQuestion) has_template2##TemplateInQuestion<C>::value
238
239#define ADOBE_HAS_TEMPLATE3_IMPL(TemplateInQuestion) \
240 template <typename C##TemplateInQuestion> \
241 struct has_template3##TemplateInQuestion { \
242 template <typename T##TemplateInQuestion> \
243 static adobe::detail::yes_struct \
244 SFINAE(typename T##TemplateInQuestion::template TemplateInQuestion<int, int, int>*); \
245 template <typename> \
246 static adobe::detail::no_struct SFINAE(...); \
247 static const bool value = \
248 sizeof(SFINAE<C##TemplateInQuestion>(0)) == sizeof(adobe::detail::yes_struct); \
249 }
250
251#define ADOBE_HAS_TEMPLATE3(C, TemplateInQuestion) has_template3##TemplateInQuestion<C>::value
252
253
254} // namespace adobe
255
256#endif // include guard
#define ADOBE_HAS_TYPE(C, TypeInQuestion)
returns true iff C has an internal type named 'TypeInQuestion'. ie returns true iff C::TypeInQuestion...
is T::type a valid type (or a compile error?)
static const bool value
if_has_type< has_type_type< T >::value, T, Default >::type type