28 #ifndef YSL_INC_Core_ycutil_h_
29 #define YSL_INC_Core_ycutil_h_ 1
32 #include YFM_YSLib_Core_YException // for YSLib::LoggedEvent;
44 template<
typename _type,
typename _tStrict,
typename _tWeak>
48 std::is_convertible<_type, _tStrict>::value, _tStrict, _tWeak>;
65 template<
typename _type,
typename _tStrict>
76 template<
typename _type>
91 return a < b ? -1 : !(a == b);
98 template<
typename _type>
102 return a < b ? -1 : !(a == b);
126 template<
typename _type>
138 template<
typename _type>
142 YAssert(FetchZero<_type>() < b,
143 "Zero element as lower bound is not less than upper bound.");
144 return !(i < FetchZero<_type>()) && i < b;
151 template<
typename _type>
155 YAssert(a < b,
"Lower bound is not less than upper bound.");
156 return !(i < a) && i < b;
164 template<
typename _type>
168 YAssert(FetchZero<_type>() < b,
169 "Zero element as lower bound is not less than upper bound.");
170 return !(i < FetchZero<_type>() || b < i);
177 template<
typename _type>
181 YAssert(a < b,
"Lower bound is not less than upper bound.");
182 return !(i < a || b < i);
190 template<
typename _type>
194 YAssert(FetchZero<_type>() < b,
195 "Zero element as lower bound is not less than upper bound.");
196 return FetchZero<_type>() < i && i < b;
203 template<
typename _type>
208 "Lower bound is not less than upper bound.");
209 return a < i && i < b;
219 template<
typename _type>
223 YAssert(a,
"Null array pointer found."),
224 YAssert(n != 0,
"Zero length of array found.");
225 YAssert(!(
v < *a),
"Value less than lower bound found.");
229 while(!(++i == n ||
v < a[i]))
242 template<
typename _type>
246 YAssert(a,
"Null array pointer found."),
247 YAssert(n != 0,
"Zero length of array found.");
248 YAssert(!(
v < *a),
"Value less than lower bound found.");
253 while(!(++i == n ||
v < (s += a[i])))
264 template<
typename _type>
268 YAssert(!(b < a),
"Upper bound is less than lower bound.");
281 template<
typename _type>
285 YAssert(a < b,
"Lower bound is not less than upper bound.");
297 template<
typename _type>
311 template<
typename _type>
315 YAssert(b != FetchZero<_type>(),
"Zero upper bound found.");
325 template<
typename _type>
342 template<
typename _tOut>
347 static_assert(std::is_pod<_type>::value
348 || (std::is_nothrow_default_constructible<_type>::value
349 && std::is_nothrow_assignable<_type, _type>::value),
350 "Invalid type found.");
353 std::fill_n(dst, n, _type());
366 template<
typename _type>
385 template<
typename _type>
394 #ifdef YSL_USE_MEMORY_DEBUG
400 struct delete_obj_debug
405 template<
typename _type>
419 struct delete_second_mem_debug
424 template<
typename _type>
426 operator()(
const _type& _pr)
ynothrow
433 # define delete_obj delete_obj_debug
434 # define delete_second_mem delete_second_mem_debug
438 # define delete_obj delete_obj_ndebug
439 # define delete_second_mem delete_second_mem_ndebug
452 template<
typename _tPo
inter>
465 template<
typename _type>
477 template<
class _type>
482 ::value,
"Non-polymorphic class type found.");
typename MoreConvertible< _type, _tStrict, _type >::Result Result
void operator()(const _type &_pr) ynothrow
删除第二成员指向的对象。
void RestrictInClosedInterval(_type &v, const _type &a, const _type &b) ynothrow
约束 v 在闭区间 [a, b] 中。
typename remove_reference< _type >::type remove_reference_t
auto ClonePolymorphic(const _type &p) -> decltype(&*p)
使用 clone 成员函数复制指定指针指向的多态类类型对象。
typename conditional< _bCond, _type, _type2 >::type conditional_t
bool IsInOpenInterval(_type i, _type b) ynothrow
判断 i 是否在开区间 (FetchZero<_type>(), b) 内。
void ClearSequence(_tOut dst, size_t n) ynothrow
清除指定的连续对象。
static Result Cast(_type o)
yconstfn int FetchSignFromInterval(int d, int a, int b) ynothrow
判断整数 d 和以 [a, b](a ≤ b) 或 [b, a](a > b) 区间的关系。
void swap(any &x, any &y)
交换对象。
void operator()(_type *_ptr) ynothrow
删除指针指向的对象。
void RestrictUnsigned(_type &u, unsigned b) ynothrow
约束无符号整数 u 在左闭右开区间 [0, b) 中。
size_t SwitchAddedInterval(_type v, const _type *a, size_t n) ynothrow
计算满足指定的值 v 在区间 [b(i), b(i + 1)) 内的最小的 i ; 其中 b(i) 是 a[i] 前 i 项的和。 ...
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
yconstfn _type FetchZero() ynothrow
取指定类型的零元素。
void RestrictUnsignedStrict(_type &u, unsigned b) ynothrow
约束无符号整数 u 在区间上界 b 内。
yconstfn s8 FetchSign(int a, int b=0) ynothrow
整数类型符号函数。
void RestrictLessEqual(_type &a, _type &b) ynothrow
约束关系:a ≤ b 。
ystdex::conditional_t< std::is_convertible< _type, _tStrict >::value, _tStrict, _tWeak > Result
#define yconstfn
指定编译时常量函数。
void operator()(_tPointer &_ptr) ynothrow
删除指针指向的对象,并置指针为空值。
void RestrictInInterval(_type &i, int a, int b) ynothrow
约束整数 i 在左闭右开区间 [a, b) 中。
bool IsInInterval(_type i, _type b) ynothrow
判断 i 是否在左闭右开区间 [FetchZero<_type>(), b) 中。
size_t SwitchInterval(_type v, const _type *a, size_t n) ynothrow
计算满足指定的值 v 在区间 [a[i], a[i + 1]) 内最小的 i 。
bool IsInClosedInterval(_type i, _type b) ynothrow
判断 i 是否在闭区间 [FetchZero<_type>(), b] 中。
bool reset(_type *&p) ynothrow
yconstfn auto CloneNonpolymorphic(const _type &p) -> decltype(&*p)
使用 new 复制指定指针指向的对象。
#define YAssert(_expr, _msg)