1 /* ///////////////////////////////////////////////////////////////////////
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_TYPE_TRAITS_IS_REF_H
13 #define EXTL_TYPE_TRAITS_IS_REF_H
15 #ifndef EXTL_TYPE_TRAITS_IS_REF_SUPPORT
16 # error extl::is_ref is not supported by current compiler.
19 /* ///////////////////////////////////////////////////////////////////////
23 #include "logical_op.h"
25 #ifndef EXTL_TEMPLATE_PARTIAL_SPEC_SUPPORT // for VC6.0 ...
26 # ifdef EXTL_TYPE_TRAITS_IS_FUNC_SUPPORT
31 /* ///////////////////////////////////////////////////////////////////////
34 #define EXTL_MUST_BE_REF(type) EXTL_MUST_BE_(is_ref, type)
35 #define EXTL_MUST_BE_CV_REF(type) EXTL_MUST_BE_CV_(is_ref, type)
36 #define EXTL_MUST_NOT_BE_REF(type) EXTL_MUST_NOT_BE_(is_ref, type)
37 #define EXTL_MUST_NOT_BE_CV_REF(type) EXTL_MUST_NOT_BE_CV_(is_ref, type)
39 /* ///////////////////////////////////////////////////////////////////////
44 #ifdef EXTL_TYPE_TRAITS_SUPPORT
46 # ifdef EXTL_TEMPLATE_PARTIAL_SPEC_SUPPORT
48 EXTL_BOOL_TRAIT_DEF_1(is_ref
, e_false_v
)
49 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T
, is_ref
, T
&, e_true_v
)
51 # if defined(EXTL_COMPILER_IS_BORLAND) && !defined(__COMO__) && (__BORLANDC__ < 0x600)
52 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T
, is_ref
, T
& const, e_true_v
)
53 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T
, is_ref
, T
& volatile, e_true_v
)
54 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T
, is_ref
, T
& const volatile, e_true_v
)
57 # if defined(EXTL_COMPILER_IS_GCC) && (__GNUC__ < 3)
58 // these allow us to work around illegally cv-qualified reference types
59 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T
, is_ref
, T
const , is_ref
<T
>::value
)
60 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T
, is_ref
, T
volatile , is_ref
<T
>::value
)
61 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T
, is_ref
, T
const volatile , is_ref
<T
>::value
)
62 // However, the above specializations confuse gcc 2.96 unless we also
63 // supply these specializations for array types
64 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_2(typename_param_k T
, e_size_t N
, is_ref
, T
[N
], e_false_v
)
65 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_2(typename_param_k T
, e_size_t N
, is_ref
, const T
[N
], e_false_v
)
66 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_2(typename_param_k T
, e_size_t N
, is_ref
, volatile T
[N
], e_false_v
)
67 EXTL_BOOL_TRAIT_PARTIAL_SPEC_1_2(typename_param_k T
, e_size_t N
, is_ref
, const volatile T
[N
], e_false_v
)
69 # else /* !defined(EXTL_TEMPLATE_PARTIAL_SPEC_SUPPORT) */
71 char EXTL_CDECL
is_ref_helper1(...);
72 // retrun type: T&(*)(type_wrap<T>)
73 template <typename_param_k T
>
74 T
&(* is_ref_helper1(type_wrap
<T
>))(type_wrap
<T
>);
76 yes_type EXTL_CDECL
is_ref_helper2(...);
77 template <typename_param_k T
>
78 no_type
is_ref_helper2(T
&(*)(type_wrap
<T
>)); // note: cannot exclude function type
80 //EXTL_BOOL_TRAIT_DEF_1(is_ref, sizeof(is_ref_helper2(is_ref_helper1(type_wrap<T>()))) == sizeof(yes_type))
81 EXTL_BOOL_TRAIT_DEF_1(is_ref
, (op_and
< (sizeof(is_ref_helper2(is_ref_helper1(type_wrap
<T
>()))) == sizeof(yes_type
))
82 , (op_not
<(is_func
<T
>::value
)>::value
) /* exclude function type */
85 EXTL_BOOL_TRAIT_SPEC_1(is_ref
, void, e_false_v
)
86 # ifdef EXTL_CV_VOID_SPEC_SUPPORT
87 EXTL_BOOL_TRAIT_SPEC_1(is_ref
, void const, e_false_v
)
88 EXTL_BOOL_TRAIT_SPEC_1(is_ref
, void volatile, e_false_v
)
89 EXTL_BOOL_TRAIT_SPEC_1(is_ref
, void const volatile, e_false_v
)
92 # endif /* EXTL_TEMPLATE_PARTIAL_SPEC_SUPPORT */
94 /* ///////////////////////////////////////////////////////////////////////
97 # ifdef EXTL_TYPE_TRAITS_TEST_ENABLE
98 # include "unit_test/is_ref_test.h"
102 /* ///////////////////////////////////////////////////////////////////////
107 /* //////////////////////////////////////////////////////////////////// */
108 #endif /* EXTL_TYPE_TRAITS_IS_REF_H */
109 /* //////////////////////////////////////////////////////////////////// */