YSTest: addressof.hpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

addressof.hpp
浏览该文件的文档.
1 /*
2 © 2015-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
32 #ifndef YB_INC_ystdex_addressof_hpp_
33 #define YB_INC_ystdex_addressof_hpp_ 1
34
35 #include "type_traits.hpp" // for "type_traits.hpp", std::declval, or_,
36 // is_detected;
37 #include <memory> // for std::addressof;
38
39 namespace ystdex
40 {
41
42 namespace details
43 {
44
46
47 template<typename _type>
48 using addressof_mem_t = decltype(std::declval<const _type&>().operator&());
49
50 template<typename _type>
51 using addressof_free_t = decltype(operator&(std::declval<const _type&>()));
53
54 } // namespace details;
55
62 template<typename _type>
63 struct has_overloaded_addressof
64 : or_<is_detected<details::addressof_mem_t, _type>,
65 is_detected<details::addressof_free_t, _type>>
66 {};
67
68
76 template<typename _type>
77 yconstfn yimpl(enable_if_t)<!has_overloaded_addressof<_type>::value, _type*>
78 constfn_addressof(_type& r)
79 {
80 return &r;
81 }
83 template<typename _type,
84 yimpl(typename = enable_if_t<has_overloaded_addressof<_type>::value>)>
85 inline _type*
86 constfn_addressof(_type& r)
87 {
88 return std::addressof(r);
89 }
91
92
99 template<typename _type>
100 yconstfn yimpl(enable_if_t)<or_<is_object<_type>, is_void<_type>>::value, void*>
101 pvoid(_type* p) ynothrow
102 {
103 return const_cast<void*>(static_cast<const volatile void*>(p));
104 }
106 template<typename _type>
107 inline yimpl(enable_if_t)<is_function<_type>::value, void*>
108 pvoid(_type* p) ynothrow
109 {
110 return const_cast<void*>(reinterpret_cast<const volatile void*>(p));
111 }
112
117 template<typename _type>
118 yconstfn void*
119 pvoid_ref(_type&& ref)
120 {
121 return ystdex::pvoid(std::addressof(ref));
122 }
124
125 } // namespace ystdex;
126
127 #endif
128
ystdex::pvoid_ref
void * pvoid_ref(_type &&ref)
Definition: addressof.hpp:119
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:680
ystdex::constfn_addressof
enable_if_t<!has_overloaded_addressof< _type >::value, _type * > constfn_addressof(_type &r)
尝试对非重载 operator& 提供 constexpr 的 std::addressof 替代。
Definition: addressof.hpp:78
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
ystdex::or_
Definition: type_traits.hpp:438
ystdex::details::addressof_mem_t
decltype(std::declval< const _type & >().operator&()) addressof_mem_t
Definition: addressof.hpp:48
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:262
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: type_traits.hpp:343
ystdex::details::addressof_free_t
decltype(operator&(std::declval< const _type & >())) addressof_free_t
Definition: addressof.hpp:51
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:766
type_traits.hpp
ISO C++ 类型特征扩展。
ystdex
特性测试宏。
Definition: ydef.h:822
ystdex::pvoid
enable_if_t< or_< is_object< _type >, is_void< _type > >::value, void * > pvoid(_type *p)
取 void* 类型的指针。
Definition: addressof.hpp:101
ystdex::has_overloaded_addressof
判断是否存在合式重载 & 操作符接受指定类型的表达式。
Definition: addressof.hpp:63
ystdex::ref
lref< _type > ref(_type &t)
构造引用包装。
Definition: ref.hpp:132
CHRLib::p
const auto p(d)