remove \r
[extl.git] / extl / type / traits / is_ref.h
blob87f4b47348d6bd37afaf6473189dd1b62fc39ea8
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: is_ref.h
4 * Created: 08.02.17
5 * Updated: 08.07.09
7 * Brief: is_ref traits
9 * [<Home>]
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.
17 #endif
19 /* ///////////////////////////////////////////////////////////////////////
20 * Includes
22 #include "prefix.h"
23 #include "logical_op.h"
25 #ifndef EXTL_TEMPLATE_PARTIAL_SPEC_SUPPORT // for VC6.0 ...
26 # ifdef EXTL_TYPE_TRAITS_IS_FUNC_SUPPORT
27 # include "is_func.h"
28 # endif
29 #endif
31 /* ///////////////////////////////////////////////////////////////////////
32 * Macros
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 /* ///////////////////////////////////////////////////////////////////////
40 * ::extl namespace
42 EXTL_BEGIN_NAMESPACE
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)
55 # endif
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)
68 # endif
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 */
83 >::value))
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)
90 # endif
92 # endif /* EXTL_TEMPLATE_PARTIAL_SPEC_SUPPORT */
94 /* ///////////////////////////////////////////////////////////////////////
95 * Unit-testing
97 # ifdef EXTL_TYPE_TRAITS_TEST_ENABLE
98 # include "unit_test/is_ref_test.h"
99 # endif
100 #endif
102 /* ///////////////////////////////////////////////////////////////////////
103 * ::extl namespace
105 EXTL_END_NAMESPACE
107 /* //////////////////////////////////////////////////////////////////// */
108 #endif /* EXTL_TYPE_TRAITS_IS_REF_H */
109 /* //////////////////////////////////////////////////////////////////// */