5template < primitive_number NUMBER1, primitive_number NUMBER2 >
6void cast_copy(NUMBER1 & n1, NUMBER2 n2)
14template <
typename A,
typename B >
15inline void swap(A & a, B & b)
27template <
typename TYPE >
28constexpr memsize index_of(
const TYPE * p,
const TYPE * pBegin)
31 return ::is_set(p) ? (::memsize)(p - pBegin) : -1;
36template < primitive_
character CHARACTER >
37constexpr bool string_compare_prefix(::std::strong_ordering & ordering,
const CHARACTER * pszA,
const CHARACTER * pszB)
noexcept
46 ordering = ::std::strong_ordering::equal;
54 ordering = ::std::strong_ordering::less;
61 else if (::is_empty(pszB))
64 ordering = ::std::strong_ordering::greater;
78template <
typename TYPE >
79void reverse(TYPE * begin, TYPE * end)
87 if (end <= begin)
return;
97#include "acme/prototype/collection/pair.h"
115template < primitive_
signed SIGNED >
116constexpr auto as_absolute_unsigned(SIGNED i)
121 return ::make_pair{ (
typename std::make_unsigned<SIGNED>::type) ((bNegative = i < 0) ? -i : i), bNegative };
215inline const ::particle * context_trace_object() {
return general_trace_object(); }
220template <
typename PRED,
typename ... Args >
221inline bool _returns_true(PRED pred,
const true_type& predicate_returns_void,
bool bOnVoid, Args... args)
227template <
typename PRED,
typename ... Args >
228inline bool _returns_true(PRED pred,
const false_type& predicate_returns_void,
bool, Args... args)
230 return (
bool)pred(args...);
233template <
typename PRED,
typename ... Args >
234inline bool returns_true(PRED pred,
bool bOnVoid, Args... args)
237 return _returns_true(pred, is_void<
decltype(pred(args...))>, bOnVoid, args...);
241template <
typename PRED,
typename ... Args >
242inline bool _returns_false(PRED pred,
const true_type& predicate_returns_void,
bool bOnVoid, Args... args)
248template <
typename PRED,
typename ... Args >
249inline bool _returns_false(PRED pred,
const false_type& predicate_returns_void,
bool, Args... args)
251 return !(bool)pred(args...);
254template <
typename PRED,
typename ... Args >
255inline bool returns_false(PRED pred,
bool bOnVoid, Args... args)
258 return _returns_false(pred, is_void <
decltype(pred(args...)) >, bOnVoid, args...);
297template <
typename TYPE >
298inline bool is_reference_null(
const TYPE& t)
306template <
typename TYPE >
307inline bool is_reference_set(
const TYPE& t)
339inline void __dynamic_cast(T*& ptarget, T* psource)
347template <
class T ,
typename T2 >
348inline void __dynamic_cast(T * & ptarget, T2 * psource)
351 ptarget =
dynamic_cast < T *
>(psource);
356template <
typename T1,
typename T2 >
357inline bool __sort(T1& t1, T2& t2)
461template < primitive_
integral SECOND, primitive_
integral NANOSECOND >
462constexpr void normalize_second_nanosecond(SECOND &
second, NANOSECOND &
nanosecond)
475template < primitive_
integral SECOND1, primitive_
integral NANOSECOND1, primitive_
integral SECOND2, primitive_
integral NANOSECOND2 >
476constexpr void add_second_nanosecond(SECOND1 & second1, NANOSECOND1 & nanosecond1,
const SECOND2 & second2,
const NANOSECOND2 & nanosecond2)
479 auto nanos = nanosecond1 + nanosecond2;
481 auto extrasecond = nanos > 0 ? (nanos / 1'000'000'000) : ((nanos / 1'000'000'000) - 1);
483 second1 = second1 + second2 + extrasecond;
485 nanosecond1 = nanos - extrasecond * 1'000'000'000;
491template < primitive_
integral SECOND1, primitive_
integral NANOSECOND1, primitive_
integral SECOND2, primitive_
integral NANOSECOND2 >
492constexpr void subtract_second_nanosecond(SECOND1 & second1, NANOSECOND1 & nanosecond1,
const SECOND2 & second2,
const NANOSECOND2 & nanosecond2)
495 auto nanos = nanosecond1 - nanosecond2;
497 auto extrasecond = nanos > 0 ? (nanos / 1'000'000'000) : ((nanos / 1'000'000'000) - 1);
499 second1 = second1 - second2 + extrasecond;
501 nanosecond1 = nanos - extrasecond * 1'000'000'000;
506template <
typename TYPE >
507constexpr TYPE * find_first_null_character(TYPE * p)
524template <
typename TYPE, ::comparison::equality < TYPE > EQUALITY >
525constexpr const TYPE * find_first_null_character(
const TYPE * p, EQUALITY equality)
530 while (!equality.equals(*p, t))
542template < primitive_fundamental INTEGRAL >
543constexpr ::collection::count count_until_zero_item_type(
const INTEGRAL * p)
546 ::collection::count c = 0;
563template < primitive_
character CHARACTER >
564constexpr void null_terminate(CHARACTER * & p)
572template < primitive_
character CHARACTER >
573constexpr void append_and_step_if_true(
bool b, CHARACTER *& p, CHARACTER
character)
582template < primitive_iterator ITERATOR, primitive_iterator BEGIN >
583constexpr bool iterator_is_before_begin(ITERATOR p, BEGIN)
592template < primitive_iterator ITERATOR, primitive_iterator END >
593constexpr bool iterator_is_end(ITERATOR p, END)
601template < primitive_iterator ITERATOR, primitive_iterator BEGIN, primitive_iterator END >
602constexpr bool iterator_is_ok(ITERATOR p, BEGIN, END)
610template <
typename TYPE,
typename BEGIN >
611constexpr bool iterator_is_before_begin(
const TYPE * p,
const BEGIN * begin)
619template <
typename TYPE,
typename END >
620constexpr bool iterator_is_end(
const TYPE * p,
const END * end)
628template <
typename TYPE,
typename BEGIN,
typename END >
629constexpr bool iterator_is_ok(
const TYPE * p,
const BEGIN * begin,
const END * end)
632 return p >= begin && p < end;
637template <
typename ITEM, ::comparison::equality < ITEM > EQUALITY >
638bool is_empty(
const ITEM * p, EQUALITY equality)
641 return ::is_null(p) || equality.equals(*p, 0);
646template <
typename ITEM, ::comparison::equality < ITEM > EQUALITY >
647constexpr bool _initialize_null_terminated_contains_null_terminated(
bool & b,
const ITEM * pz,
const ITEM * pzPrefix, EQUALITY equality)
650 if (::is_empty(pzPrefix, equality))
659 if (::is_empty(pz, equality))
674template <
typename ITEM, ::comparison::equality < ITEM > EQUALITY >
675constexpr bool _null_terminated_begins_null_terminated(
const ITEM * pz,
const ITEM * pzPrefix, EQUALITY equality)
681 if (!equality.equals(*pz, *pzPrefix))
692 }
while (!equality.equals(*pz,0) && !equality.equals(*pzPrefix, 0));
694 return equality.equals(*pzPrefix, 0);
699template <
typename ITEM, ::comparison::equality < ITEM > EQUALITY >
700constexpr bool null_terminated_begins_null_terminated(
const ITEM * pz,
const ITEM * pzPrefix, EQUALITY equality)
705 if (_initialize_null_terminated_contains_null_terminated(b, pz, pzPrefix, equality))
712 return _null_terminated_begins_null_terminated(pz, pzPrefix, equality);
717#include "acme/prototype/mathematics/_.h"
720template <
typename TYPE >
721TYPE * clipped_add(TYPE * p, ::collection::count c,
const non_const<TYPE> * begin,
const non_const<TYPE> * end)
727 p = minimum(p + c, end);
733 p = maximum(p + c, begin - 1);
745template < primitive_iterator ITERATOR,
typename T1,
typename T2 >
746ITERATOR clipped_add(ITERATOR p, ::collection::count c, T1, T2)
752 while (p.is_set() && c > 0)
766 while (p.is_set() && c < 0)
784template < primitive_
signed SIGNED >
793template <
typename T >
794bool found(
const T * p)
802template < primitive_
signed SIGNED >
803bool not_found(SIGNED s)
811template <
typename T >
812bool not_found(
const T * p)
824template <
typename BOOLEAN,
typename ASSIGNED,
typename ASSIGNEE >
825inline void set_if_different(BOOLEAN& bSetIfChanged, ASSIGNED& left,
const ASSIGNEE& right)
831 bSetIfChanged =
true;
841template < primitive_XYDim XYDim,
typename X,
typename Y,
typename W,
typename H >
842inline XYDim & set_dim(XYDim & rectTarget, X x, Y y, W w, H h)
845 cast_copy(rectTarget.X, x);
846 cast_copy(rectTarget.Y, y);
847 cast_copy(rectTarget.Width, w);
848 cast_copy(rectTarget.Height, h);
867template < primitive_rectangle RECTANGLE, primitive_xydim XYDIM >
868void copy(RECTANGLE & rectangle,
const XYDIM & xydim)
871 cast_copy(rectangle.left() , xydim.x);
872 cast_copy(rectangle.top() , xydim.y);
873 cast_copy(rectangle.right() , xydim.x + xydim.width);
874 cast_copy(rectangle.bottom() , xydim.y + xydim.height);
879template < primitive_origin_size ORIGIN_SIZE, primitive_rectangle RECTANGLE >
880void copy(ORIGIN_SIZE & originsize,
const RECTANGLE & rectangle)
883 cast_copy(originsize.origin.x , rectangle.left());
884 cast_copy(originsize.origin.y , rectangle.top());
885 cast_copy(originsize.size.width , rectangle.right() - rectangle.left());
886 cast_copy(originsize.size.height , rectangle.bottom() - rectangle.top());
891template < primitive_rectangle RECTANGLE1, primitive_origin_size RECTANGLE2 >
892void copy(RECTANGLE1 & rectangle1,
const RECTANGLE2 & rectangle2)
895 cast_copy(rectangle1.left() , rectangle2.origin.x);
896 cast_copy(rectangle1.top() , rectangle2.origin.y);
897 cast_copy(rectangle1.right() , rectangle2.origin.x + rectangle2.size.width);
898 cast_copy(rectangle1.bottom() , rectangle2.origin.y + rectangle2.size.height);
932template < primitive_XY POINT1, primitive_po
int POINT2 >
933void copy(POINT1 point1,
const POINT2 & point2)
936 cast_copy(point1.X, point2.x());
937 cast_copy(point1.Y, point2.y());
942template < primitive_po
int POINT1, primitive_XY POINT2 >
943void copy(POINT1 & point1,
const POINT2 & point2)
946 cast_copy(point1.x(), point2.X);
947 cast_copy(point1.y(), point2.Y);
952template < primitive_rectangle RECTANGLE1, primitive_rectangle RECTANGLE2 >
953void copy(RECTANGLE1 & rectangle1,
const RECTANGLE2 & rectangle2)
956 cast_copy(rectangle1.left(), rectangle2.left());
957 cast_copy(rectangle1.top(), rectangle2.top());
958 cast_copy(rectangle1.right(), rectangle2.right());
959 cast_copy(rectangle1.bottom(), rectangle2.bottom());
964template < primitive_XYDim XYDim, primitive_rectangle RECTANGLE >
965void copy(XYDim & xydim,
const RECTANGLE & rectangle)
968 cast_copy(xydim.X, rectangle.left());
969 cast_copy(xydim.Y, rectangle.top());
970 cast_copy(xydim.Width, rectangle.right() - rectangle.left());
971 cast_copy(xydim.Height, rectangle.bottom() - rectangle.top());
976template < primitive_rectangle RECTANGLE, primitive_XYDim XYDim >
977void copy(RECTANGLE & rectangle,
const XYDim & xydim)
980 cast_copy(rectangle.left(), xydim.X);
981 cast_copy(rectangle.top(), xydim.Y);
982 cast_copy(rectangle.right(), xydim.X + xydim.Width);
983 cast_copy(rectangle.bottom(), xydim.Y + xydim.Height);
988template < primitive_xydim XYDIM, primitive_rectangle RECTANGLE >
989void copy(XYDIM & xydim,
const RECTANGLE & rectangle)
992 cast_copy(xydim.x, rectangle.left());
993 cast_copy(xydim.y, rectangle.top());
994 cast_copy(xydim.width, rectangle.right() - rectangle.left());
995 cast_copy(xydim.height, rectangle.bottom() - rectangle.top());
1000template < primitive_XYDim XYDim1, primitive_XYDim XYDim2 >
1001void copy(XYDim1 & xydim1,
const XYDim2 & xydim2)
1004 cast_copy(xydim1.X, xydim2.X);
1005 cast_copy(xydim1.Y, xydim2.Y);
1006 cast_copy(xydim1.Width, xydim2.Width);
1007 cast_copy(xydim1.Height, xydim2.Height);
1012template < primitive_po
int POINT1, primitive_po
int POINT2 >
1013void copy(POINT1 & point1,
const POINT2 & point2)
1016 cast_copy(point1.x(), point2.x());
1017 cast_copy(point1.y(), point2.y());
1022template < primitive_po
int POINT1, raw_primitive_po
int POINT2 >
1023void copy(POINT1 & point1,
const POINT2 & point2)
1026 cast_copy(point1.x(), point2.x());
1027 cast_copy(point1.y(), point2.y());
1032template < raw_primitive_po
int POINT1, primitive_po
int POINT2 >
1033void copy(POINT1 & point1,
const POINT2 & point2)
1036 cast_copy(point1.x, point2.x());
1037 cast_copy(point1.y, point2.y());
1042template < primitive_po
int POINT, primitive_size SIZE >
1043void copy(POINT & point,
const SIZE & size)
1046 cast_copy(point.x(), size.cx());
1047 cast_copy(point.y(), size.cy());
1052template < primitive_size SIZE_TYPE1, primitive_size SIZE_TYPE2 >
1053void copy(SIZE_TYPE1 & size1,
const SIZE_TYPE2 & size2)
1056 cast_copy(size1.cx(), size2.cx());
1057 cast_copy(size1.cy(), size2.cy());
1062template <
typename CHAR_STRING >
1063inline bool is_string_empty(CHAR_STRING p) { return ::is_null(p) || *p ==
'\0'; }
Definition aaa_character.h:10
Definition aaa_nanosecond.h:9
Definition aaa_second.h:9