YSTest: deref_op.hpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

deref_op.hpp
浏览该文件的文档.
1 /*
2 © 2011-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
28 #ifndef YB_INC_ystdex_deref_op_hpp_
29 #define YB_INC_ystdex_deref_op_hpp_ 1
30
31 #include "../ydef.h"
32
33 namespace ystdex
34 {
35
43 template<typename _tIter>
44 yconstfn bool
45 is_undereferenceable(const _tIter&) ynothrow
46 {
47 return {};
48 }
49 template<typename _type>
50 yconstfn bool
51 is_undereferenceable(_type* p) ynothrow
52 {
53 return !p;
54 }
56
57
59
60
62 template<typename _tOther, typename _type>
63 yconstfn auto
64 nonnull_or(_type p, _tOther&& other = {}) -> decltype(p ? p : other)
65 {
66 return p ? p : other;
67 }
68 template<typename _tOther, typename _type, typename _tNull = nullptr_t>
69 yconstfn auto
70 nonnull_or(_type p, _tOther&& other, _tNull null)
71 -> decltype(!bool(p == null) ? p : other)
72 {
73 return !bool(p == null) ? p : other;
74 }
76
77
79
80 template<typename _tOther, typename _type>
81 yconstfn auto
82 value_or(_type p, _tOther&& other = {}) -> decltype(p ? *p : other)
83 {
84 return p ? *p : other;
85 }
86 template<typename _tOther, typename _type, typename _tSentinal = nullptr_t>
87 yconstfn auto
88 value_or(_type p, _tOther&& other, _tSentinal last)
89 -> decltype(!bool(p == last) ? *p : other)
90 {
91 return !bool(p == last) ? *p : other;
92 }
94
95
97
98 template<typename _tOther, typename _func, typename _type>
99 yconstfn auto
100 call_value_or(_func f, _type p, _tOther&& other = {})
101 -> decltype(p ? f(*p) : other)
102 {
103 return p ? f(*p) : other;
104 }
105 template<typename _tOther, typename _func, typename _type,
106 typename _tSentinal = nullptr_t>
107 yconstfn auto
108 call_value_or(_func f, _type p, _tOther&& other, _tSentinal last)
109 -> decltype(!bool(p == last) ? f(*p) : other)
110 {
111 return !bool(p == last) ? f(*p) : other;
112 }
114
115
116 } // namespace ystdex;
117
118 #endif
119
platform::p
while p p
Definition: YCLib/FileSystem.h:225
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
ystdex::value_or
auto value_or(_type p, _tOther &&other={}) -> decltype(p?*p:other)
取非空值或默认值。
Definition: deref_op.hpp:82
ystdex
特性测试宏。
Definition: ydef.h:796
ystdex::is_undereferenceable
bool is_undereferenceable(const _tIter &)
Definition: deref_op.hpp:45
ystdex::call_value_or
auto call_value_or(_func f, _type p, _tOther &&other={}) -> decltype(p?f(*p):other)
调用非空值或取默认值。
Definition: deref_op.hpp:100
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:654
CHRLib::CharSet::other
Definition: Encoding.h:65
YSLib::IO::f
const string &path const String &path _func f
Definition: YSLib/Service/FileSystem.h:430
ystdex::nonnull_or
auto nonnull_or(_type p, _tOther &&other={}) -> decltype(p?p:other)
取非空引用或默认值。
Definition: deref_op.hpp:64
platform::bool
std::FILE *fp bool
Definition: FileIO.h:1187