Skip to content

Commit 4723afe

Browse files
author
nitrocaster
committed
Remove references to boost type traits. Close #96.
1 parent 8440c41 commit 4723afe

File tree

1 file changed

+134
-144
lines changed

1 file changed

+134
-144
lines changed

src/Common/object_type_traits.h

Lines changed: 134 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -11,183 +11,173 @@
1111

1212
#include <type_traits>
1313

14-
//#define USE_BOOST
15-
16-
#ifdef USE_BOOST
17-
# include <boost/type_traits/is_base_and_derived.hpp>
18-
# include <boost/type_traits/is_pointer.hpp>
19-
# include <boost/type_traits/remove_pointer.hpp>
20-
# include <boost/type_traits/remove_const.hpp>
21-
namespace object_type_traits = boost;
22-
#else
23-
#define declare_has(a) \
24-
template <typename T>\
25-
struct has_##a {\
26-
template <typename P> static detail::yes select(detail::other<typename P::a>*);\
27-
template <typename P> static detail::no select(...);\
28-
enum { value = sizeof(detail::yes) == sizeof(select<T>(0)) };\
29-
};
14+
#define declare_has(a) \
15+
template <typename T>\
16+
struct has_##a {\
17+
template <typename P> static detail::yes select(detail::other<typename P::a>*);\
18+
template <typename P> static detail::no select(...);\
19+
enum { value = sizeof(detail::yes) == sizeof(select<T>(0)) };\
20+
};
3021

31-
template <bool expression, typename T1, typename T2>
32-
struct _if {
33-
using result = typename std::conditional<expression, T1, T2>::type;
22+
template <bool expression, typename T1, typename T2>
23+
struct _if {
24+
using result = typename std::conditional<expression, T1, T2>::type;
25+
};
26+
27+
template <typename T1, typename T2>
28+
struct is_type {
29+
enum { value = std::is_same<T1,T2>::value, };
30+
};
31+
32+
template <typename T>
33+
struct type {
34+
typedef T result;
35+
};
36+
37+
namespace object_type_traits {
38+
namespace detail {
39+
struct yes {char a[1];};
40+
struct no {char a[2];};
41+
template <typename T> struct other{};
3442
};
3543

36-
template <typename T1, typename T2>
37-
struct is_type {
38-
enum { value = std::is_same<T1,T2>::value, };
44+
template <typename T> struct remove_pointer{
45+
typedef T type;
3946
};
4047

41-
template <typename T>
42-
struct type {
43-
typedef T result;
48+
template <typename T> struct remove_pointer<T*>{
49+
typedef T type;
4450
};
4551

46-
namespace object_type_traits {
47-
namespace detail {
48-
struct yes {char a[1];};
49-
struct no {char a[2];};
50-
template <typename T> struct other{};
51-
};
52+
template <typename T> struct remove_pointer<T* const>{
53+
typedef T type;
54+
};
5255

53-
template <typename T> struct remove_pointer{
54-
typedef T type;
55-
};
56+
template <typename T> struct remove_reference{
57+
typedef T type;
58+
};
5659

57-
template <typename T> struct remove_pointer<T*>{
58-
typedef T type;
59-
};
60+
template <typename T> struct remove_reference<T&>{
61+
typedef T type;
62+
};
6063

61-
template <typename T> struct remove_pointer<T* const>{
62-
typedef T type;
63-
};
64+
template <typename T> struct remove_reference<T const &>{
65+
typedef T type;
66+
};
6467

65-
template <typename T> struct remove_reference{
66-
typedef T type;
67-
};
68+
template <typename T> struct remove_const{
69+
typedef T type;
70+
};
6871

69-
template <typename T> struct remove_reference<T&>{
70-
typedef T type;
71-
};
72+
template <typename T> struct remove_const<T const>{
73+
typedef T type;
74+
};
7275

73-
template <typename T> struct remove_reference<T const &>{
74-
typedef T type;
75-
};
76+
template <typename T>
77+
struct is_void {
78+
enum { value = std::is_same<void,T>::value };
79+
};
7680

77-
template <typename T> struct remove_const{
78-
typedef T type;
79-
};
81+
template <typename T> struct is_const{
82+
enum { value = false};
83+
};
8084

81-
template <typename T> struct remove_const<T const>{
82-
typedef T type;
83-
};
85+
template <typename T> struct is_const<T const>{
86+
enum { value = true};
87+
};
8488

85-
template <typename T>
86-
struct is_void {
87-
enum { value = std::is_same<void,T>::value };
88-
};
8989

90-
template <typename T> struct is_const{
91-
enum { value = false};
92-
};
90+
template <typename T>
91+
struct is_pointer {
92+
template <typename P> static detail::yes select(detail::other<P*>);
93+
static detail::no select(...);
9394

94-
template <typename T> struct is_const<T const>{
95-
enum { value = true};
96-
};
95+
enum { value = sizeof(detail::yes) == sizeof(select(detail::other<T>()))};
96+
};
9797

98+
template <typename T>
99+
struct is_reference {
100+
template <typename P> static detail::yes select(detail::other<P&>);
101+
static detail::no select(...);
98102

99-
template <typename T>
100-
struct is_pointer {
101-
template <typename P> static detail::yes select(detail::other<P*>);
102-
static detail::no select(...);
103+
enum { value = sizeof(detail::yes) == sizeof(select(detail::other<T>()))};
104+
};
103105

104-
enum { value = sizeof(detail::yes) == sizeof(select(detail::other<T>()))};
105-
};
106+
template <typename _T1, typename _T2>
107+
struct is_same {
108+
typedef typename remove_const<_T1>::type T1;
109+
typedef typename remove_const<_T2>::type T2;
106110

107-
template <typename T>
108-
struct is_reference {
109-
template <typename P> static detail::yes select(detail::other<P&>);
110-
static detail::no select(...);
111+
enum { value = is_type<T1,T2>::value };
112+
};
111113

112-
enum { value = sizeof(detail::yes) == sizeof(select(detail::other<T>()))};
113-
};
114+
template <typename _T1, typename _T2>
115+
struct is_base_and_derived {
116+
typedef typename remove_const<_T1>::type T1;
117+
typedef typename remove_const<_T2>::type T2;
114118

115-
template <typename _T1, typename _T2>
116-
struct is_same {
117-
typedef typename remove_const<_T1>::type T1;
118-
typedef typename remove_const<_T2>::type T2;
119+
static detail::yes select(T1*);
120+
static detail::no select(...);
119121

120-
enum { value = is_type<T1,T2>::value };
122+
enum {
123+
value =
124+
std::is_class<T1>::value &&
125+
std::is_class<T2>::value &&
126+
!is_same<T1,T2>::value &&
127+
sizeof(detail::yes) == sizeof(select((T2*)(0)))
121128
};
129+
};
122130

123-
template <typename _T1, typename _T2>
124-
struct is_base_and_derived {
125-
typedef typename remove_const<_T1>::type T1;
126-
typedef typename remove_const<_T2>::type T2;
127-
128-
static detail::yes select(T1*);
129-
static detail::no select(...);
130-
131-
enum {
132-
value =
133-
std::is_class<T1>::value &&
134-
std::is_class<T2>::value &&
135-
!is_same<T1,T2>::value &&
136-
sizeof(detail::yes) == sizeof(select((T2*)(0)))
137-
};
138-
};
131+
template <template <typename _1> class T1, typename T2, typename T3>
132+
struct is_base_and_derived_or_same_for_template_template_1_1 {
133+
template <typename P>
134+
static typename _if<
135+
is_base_and_derived<P,T3>::value ||
136+
is_same<P,T3>::value,
137+
detail::yes,
138+
detail::no
139+
>::result select(T1<P>*);
140+
static detail::no select(...);
141+
142+
enum { value = sizeof(detail::yes) == sizeof(select((T2*)0))};
143+
};
139144

140-
template <template <typename _1> class T1, typename T2, typename T3>
141-
struct is_base_and_derived_or_same_for_template_template_1_1 {
142-
template <typename P>
143-
static typename _if<
144-
is_base_and_derived<P,T3>::value ||
145-
is_same<P,T3>::value,
146-
detail::yes,
147-
detail::no
148-
>::result select(T1<P>*);
149-
static detail::no select(...);
150-
151-
enum { value = sizeof(detail::yes) == sizeof(select((T2*)0))};
152-
};
145+
template <template <typename _1> class T1, typename T2>
146+
struct is_base_and_derived_or_same_from_template {
147+
template <typename P>
148+
static detail::yes select(T1<P>*);
149+
static detail::no select(...);
153150

154-
template <template <typename _1> class T1, typename T2>
155-
struct is_base_and_derived_or_same_from_template {
156-
template <typename P>
157-
static detail::yes select(T1<P>*);
158-
static detail::no select(...);
151+
enum { value = sizeof(detail::yes) == sizeof(select((T2*)0))};
152+
};
159153

160-
enum { value = sizeof(detail::yes) == sizeof(select((T2*)0))};
161-
};
154+
declare_has(iterator);
155+
declare_has(const_iterator);
156+
// declare_has(reference);
157+
// declare_has(const_reference);
158+
declare_has(value_type);
159+
declare_has(size_type);
160+
// declare_has(value_compare);
162161

163-
declare_has(iterator);
164-
declare_has(const_iterator);
165-
// declare_has(reference);
166-
// declare_has(const_reference);
167-
declare_has(value_type);
168-
declare_has(size_type);
169-
// declare_has(value_compare);
170-
171-
template <typename T>
172-
struct is_stl_container {
173-
enum {
174-
value =
175-
has_iterator<T>::value &&
176-
has_const_iterator<T>::value &&
162+
template <typename T>
163+
struct is_stl_container {
164+
enum {
165+
value =
166+
has_iterator<T>::value &&
167+
has_const_iterator<T>::value &&
177168
// has_reference<T>::value &&
178169
// has_const_reference<T>::value &&
179-
has_size_type<T>::value &&
180-
has_value_type<T>::value
181-
};
170+
has_size_type<T>::value &&
171+
has_value_type<T>::value
182172
};
183-
184-
// template <typename _T>
185-
// struct is_tree_structure {
186-
// enum {
187-
// value =
188-
// has_value_compare<_T>::value
189-
// };
190-
// };
191173
};
192-
#endif
174+
175+
// template <typename _T>
176+
// struct is_tree_structure {
177+
// enum {
178+
// value =
179+
// has_value_compare<_T>::value
180+
// };
181+
// };
182+
};
193183
#endif // object_type_traits_h_included

0 commit comments

Comments
 (0)