VCCC  2024.05
VisualCamp Common C++ library
dereferenceable.hpp
Go to the documentation of this file.
1 //
2 // Created by cosge on 2023-12-02.
3 //
4 
5 #ifndef VCCC_CONCEPTS_DEREFERENCEABLE_HPP_
6 #define VCCC_CONCEPTS_DEREFERENCEABLE_HPP_
7 
8 #include <type_traits>
9 
12 
13 namespace vccc {
14 namespace detail {
15 
16 template<typename T, typename = void>
17 struct dereferenceable_impl_3 : std::false_type {};
18 
19 template<typename T>
20 struct dereferenceable_impl_3<T, void_t<decltype(*std::declval<T&>())>>
21  : is_referencable<decltype(*std::declval<T&>())> {};
22 
23 // Dereferencing a void* is illegal, but some compilers compiles these expression in unevaluated context.
24 // Omitting dereferenceable_impl_2 does not change the behavior of dereferenceable, but it is to remove warning
25 template<typename T, bool = std::is_void<std::remove_pointer_t<std::remove_reference_t<T>>>::value /* false */>
26 struct dereferenceable_impl_2 : dereferenceable_impl_3<T> {};
27 
28 template<typename T>
29 struct dereferenceable_impl_2<T, true> : std::false_type {};
30 
32 struct dereferenceable_impl_1 : dereferenceable_impl_2<T> {};
33 
34 template<typename T>
35 struct dereferenceable_impl_1<T, false> : std::false_type {};
36 
37 } // namespace detail
38 
39 
42 
44 template<typename T>
45 struct dereferenceable : detail::dereferenceable_impl_1<T> {};
46 
48 
49 } // namespace vccc
50 
51 #endif // VCCC_CONCEPTS_DEREFERENCEABLE_HPP_
void void_t
Definition: void_t.hpp:19
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
specifies that an object of a type can be dereferenced
Definition: dereferenceable.hpp:45