Phi
is_referenceable.hpp
1 #ifndef INCG_PHI_CORE_TYPE_TRAITS_IS_REFERENCEABLE_HPP
2 #define INCG_PHI_CORE_TYPE_TRAITS_IS_REFERENCEABLE_HPP
3 
4 #include "phi/phi_config.hpp"
5 
6 #if PHI_HAS_EXTENSION_PRAGMA_ONCE()
7 # pragma once
8 #endif
9 
10 #include "phi/compiler_support/constexpr.hpp"
11 #include "phi/compiler_support/inline_variables.hpp"
12 #include "phi/compiler_support/intrinsics/is_referenceable.hpp"
13 #include "phi/type_traits/integral_constant.hpp"
14 
15 // NOTE: Enabling this fails CI builds but I can't replicate them locally
16 #if PHI_SUPPORTS_IS_REFERENCEABLE() && 0
17 
18 DETAIL_PHI_BEGIN_NAMESPACE()
19 
20 template <typename TypeT>
21 struct is_referenceable : public integral_constant<bool, PHI_IS_REFERENCEABLE(TypeT)>
22 {};
23 
24 template <typename TypeT>
25 struct is_not_referenceable : public integral_constant<bool, !PHI_IS_REFERENCEABLE(TypeT)>
26 {};
27 
28 # if PHI_HAS_FEATURE_VARIABLE_TEMPLATE()
29 
30 template <typename TypeT>
31 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_referenceable_v = PHI_IS_REFERENCEABLE(TypeT);
32 
33 template <typename TypeT>
34 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_not_referenceable_v = !PHI_IS_REFERENCEABLE(TypeT);
35 
36 # endif
37 
38 #else
39 
40 # include "phi/type_traits/detail/yes_no_type.hpp"
41 # include "phi/type_traits/is_same.hpp"
42 
43 DETAIL_PHI_BEGIN_NAMESPACE()
44 
45 namespace detail
46 {
48  {
49  template <typename TypeT>
50  static TypeT& test(int);
51 
52  template <typename TypeT>
53  static no_type test(...);
54  };
55 } // namespace detail
56 
57 template <typename TypeT>
59  : public integral_constant<bool,
60  is_not_same<decltype(detail::is_referenceable_impl::test<TypeT>(0)),
61  detail::no_type>::value>
62 {};
63 
64 template <typename TypeT>
65 struct is_not_referenceable : public integral_constant<bool, !is_referenceable<TypeT>::value>
66 {};
67 
68 # if PHI_HAS_FEATURE_VARIABLE_TEMPLATE()
69 
70 template <typename TypeT>
71 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_referenceable_v = is_referenceable<TypeT>::value;
72 
73 template <typename TypeT>
74 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_not_referenceable_v = is_not_referenceable<TypeT>::value;
75 
76 # endif
77 
78 #endif
79 
80 DETAIL_PHI_END_NAMESPACE()
81 
82 #endif // INCG_PHI_CORE_TYPE_TRAITS_IS_REFERENCEABLE_HPP
Definition: integral_constant.hpp:19
Definition: is_referenceable.hpp:47
Definition: test_macros.hpp:18
Definition: yes_no_type.hpp:32
Definition: swap.hpp:23
Definition: is_referenceable.hpp:65
Definition: is_referenceable.hpp:58