14#ifndef RANGES_V3_ITERATOR_DIFFMAX_T_HPP
15#define RANGES_V3_ITERATOR_DIFFMAX_T_HPP
27#include <range/v3/detail/prologue.hpp>
30RANGES_DIAGNOSTIC_IGNORE_UNSIGNED_MATH
45 constexpr diffmax_t(tag,
bool neg, std::uintmax_t val)
51 constexpr void _check()
53 RANGES_ENSURE(!neg_ || val_);
55 static constexpr diffmax_t _normalize(
bool neg, std::uintmax_t val)
57 return diffmax_t{tag{}, val && neg, val};
62 diffmax_t() =
default;
66 constexpr diffmax_t(T val) noexcept
68 , val_(0 > val ?
static_cast<std::uintmax_t
>(-val)
69 : static_cast<std::uintmax_t>(val))
72 friend constexpr bool operator<(diffmax_t a, diffmax_t b)
noexcept
76 return a.neg_ ? (b.neg_ ? a.val_ > b.val_ :
true)
77 : (b.neg_ ? false : a.val_ < b.val_);
79 friend constexpr bool operator>(diffmax_t a, diffmax_t b)
noexcept
83 friend constexpr bool operator<=(diffmax_t a, diffmax_t b)
noexcept
87 friend constexpr bool operator>=(diffmax_t a, diffmax_t b)
noexcept
91 friend constexpr bool operator==(diffmax_t a, diffmax_t b)
noexcept
95 return a.val_ == b.val_ && a.neg_ == b.neg_;
97 friend constexpr bool operator!=(diffmax_t a, diffmax_t b)
noexcept
102 friend constexpr diffmax_t operator+(diffmax_t a)
noexcept
106 friend constexpr diffmax_t
operator-(diffmax_t a)
noexcept
108 return _normalize(!a.neg_, a.val_);
111 friend constexpr diffmax_t operator+(diffmax_t a, diffmax_t b)
noexcept
113 return a.neg_ == b.neg_
114 ? diffmax_t{tag{}, a.neg_, a.val_ + b.val_}
115 : (a.neg_ ? (a.val_ > b.val_
116 ? diffmax_t{tag{},
true, a.val_ - b.val_}
117 : diffmax_t{tag{},
false, b.val_ - a.val_})
119 ? diffmax_t{tag{}, true, b.val_ - a.val_}
120 : diffmax_t{tag{}, false, a.val_ - b.val_}));
122 friend constexpr diffmax_t
operator-(diffmax_t a, diffmax_t b)
noexcept
126 friend constexpr diffmax_t
operator*(diffmax_t a, diffmax_t b)
noexcept
128 return _normalize(a.neg_ ^ b.neg_, a.val_ * b.val_);
130 friend constexpr diffmax_t operator/(diffmax_t a, diffmax_t b)
noexcept
132 return _normalize(a.neg_ ^ b.neg_, a.val_ / b.val_);
134 friend constexpr diffmax_t operator%(diffmax_t a, diffmax_t b)
noexcept
136 return _normalize(a.neg_, a.val_ % b.val_);
138 static constexpr std::uintmax_t compl_if(
bool neg,
139 std::uintmax_t val)
noexcept
141 return neg ? ~val + 1 : val;
143 friend constexpr diffmax_t operator&(diffmax_t a, diffmax_t b)
noexcept
147 compl_if(a.neg_ && b.neg_,
148 compl_if(a.neg_, a.val_) & compl_if(b.neg_, b.val_)));
150 friend constexpr diffmax_t operator|(diffmax_t a, diffmax_t b)
noexcept
154 compl_if(a.neg_ || b.neg_,
155 compl_if(a.neg_, a.val_) | compl_if(b.neg_, b.val_)));
157 friend constexpr diffmax_t operator^(diffmax_t a, diffmax_t b)
noexcept
160 bool(a.neg_ ^ b.neg_),
161 compl_if(
bool(a.neg_ ^ b.neg_),
162 compl_if(a.neg_, a.val_) ^ compl_if(b.neg_, b.val_)));
165 friend constexpr diffmax_t operator<<(diffmax_t a, diffmax_t b)
noexcept
167 RANGES_ENSURE(!a.neg_);
168 return b.neg_ ? diffmax_t{tag{},
false, a.val_ >> b.val_}
169 : diffmax_t{tag{},
false, a.val_ << b.val_};
171 friend constexpr diffmax_t operator>>(diffmax_t a, diffmax_t b)
noexcept
173 return b.neg_ ? diffmax_t{tag{}, a.neg_, a.val_ << b.val_}
174 : diffmax_t{tag{}, a.neg_, a.val_ >> b.val_};
177 friend constexpr diffmax_t & operator+=(diffmax_t & a, diffmax_t b)
noexcept
181 friend constexpr diffmax_t & operator-=(diffmax_t & a, diffmax_t b)
noexcept
185 friend constexpr diffmax_t & operator*=(diffmax_t & a, diffmax_t b)
noexcept
189 friend constexpr diffmax_t & operator/=(diffmax_t & a, diffmax_t b)
noexcept
193 friend constexpr diffmax_t & operator%=(diffmax_t & a, diffmax_t b)
noexcept
197 friend constexpr diffmax_t & operator&=(diffmax_t & a, diffmax_t b)
noexcept
201 friend constexpr diffmax_t & operator|=(diffmax_t & a, diffmax_t b)
noexcept
205 friend constexpr diffmax_t & operator^=(diffmax_t & a, diffmax_t b)
noexcept
209 friend constexpr diffmax_t & operator<<=(diffmax_t & a, diffmax_t b)
noexcept
214 friend constexpr diffmax_t & operator>>=(diffmax_t & a, diffmax_t b)
noexcept
221 friend constexpr auto operator+=(T & a, diffmax_t b)
noexcept
222 -> CPP_broken_friend_ret(T &)(
223 requires integral<T>)
225 return (a =
static_cast<T
>(diffmax_t{a} + b));
228 friend constexpr auto operator-=(T & a, diffmax_t b)
noexcept
229 -> CPP_broken_friend_ret(T &)(
230 requires integral<T>)
232 return (a =
static_cast<T
>(diffmax_t{a} - b));
235 friend constexpr auto operator*=(T & a, diffmax_t b)
noexcept
236 -> CPP_broken_friend_ret(T &)(
237 requires integral<T>)
239 return (a =
static_cast<T
>(diffmax_t{a} * b));
242 friend constexpr auto operator/=(T & a, diffmax_t b)
noexcept
243 -> CPP_broken_friend_ret(T &)(
244 requires integral<T>)
246 return (a =
static_cast<T
>(diffmax_t{a} / b));
249 friend constexpr auto operator%=(T & a, diffmax_t b)
noexcept
250 -> CPP_broken_friend_ret(T &)(
251 requires integral<T>)
253 return (a =
static_cast<T
>(diffmax_t{a} % b));
256 friend constexpr auto operator&=(T & a, diffmax_t b)
noexcept
257 -> CPP_broken_friend_ret(T &)(
258 requires integral<T>)
260 return (a =
static_cast<T
>(diffmax_t{a} & b));
263 friend constexpr auto operator|=(T & a, diffmax_t b)
noexcept
264 -> CPP_broken_friend_ret(T &)(
265 requires integral<T>)
267 return (a =
static_cast<T
>(diffmax_t{a} | b));
270 friend constexpr auto operator^=(T & a, diffmax_t b)
noexcept
271 -> CPP_broken_friend_ret(T &)(
272 requires integral<T>)
274 return (a =
static_cast<T
>(diffmax_t{a} ^ b));
277 friend constexpr auto operator<<=(T & a, diffmax_t b)
noexcept
278 -> CPP_broken_friend_ret(T &)(
279 requires integral<T>)
281 a =
static_cast<T
>(diffmax_t{a} << b);
285 friend constexpr auto operator>>=(T & a, diffmax_t b)
noexcept
286 -> CPP_broken_friend_ret(T &)(
287 requires integral<T>)
289 a =
static_cast<T
>(diffmax_t{a} >> b);
293 friend constexpr diffmax_t & operator++(diffmax_t & a)
noexcept
295 a.neg_ = (a.neg_ ? --a.val_ : ++a.val_) && a.neg_;
298 friend constexpr diffmax_t & operator--(diffmax_t & a)
noexcept
300 a.neg_ = (a.neg_ ? ++a.val_ : --a.val_) && a.neg_;
303 friend constexpr diffmax_t operator++(diffmax_t & a,
int)
noexcept
309 friend constexpr diffmax_t operator--(diffmax_t & a,
int)
noexcept
316 template(
typename T)(
317 requires integral<T>)
319 operator T() const noexcept
321 return neg_ ? -
static_cast<T
>(val_) : static_cast<T>(val_);
323 constexpr explicit operator bool() const noexcept
327 constexpr bool operator!() const noexcept
332 template<
typename Ostream>
333 friend auto operator<<(Ostream & sout, diffmax_t a)
334 -> CPP_broken_friend_ret(std::ostream &)(
335 requires derived_from<
336 Ostream, std::basic_ostream<
typename Ostream::char_type,
337 typename Ostream::traits_type>>)
339 return sout << (&
"-"[!a.neg_]) << a.val_;
343#if RANGES_CXX_INLINE_VARIABLES >= RANGES_CXX_INLINE_VARIABLES_17
345 inline constexpr bool _is_integer_like_<diffmax_t> =
true;
347 template<
typename Enable>
348 constexpr bool _is_integer_like_<diffmax_t, Enable> =
true;
355RANGES_DIAGNOSTIC_IGNORE_MISMATCHED_TAGS
360 struct numeric_limits<::ranges::detail::diffmax_t>
362 static constexpr bool is_specialized =
true;
363 static constexpr bool is_signed =
true;
364 static constexpr bool is_integer =
true;
365 static constexpr bool is_exact =
true;
366 static constexpr bool has_infinity =
false;
367 static constexpr bool has_quiet_NaN =
false;
368 static constexpr bool has_signaling_NaN =
false;
369 static constexpr bool has_denorm =
false;
370 static constexpr bool has_denorm_loss =
false;
371 static constexpr std::float_round_style round_style = std::round_toward_zero;
372 static constexpr bool is_iec559 =
false;
373 static constexpr bool is_bounded =
true;
374 static constexpr bool is_modulo =
false;
375 static constexpr int digits = CHAR_BIT *
sizeof(std::uintmax_t) + 1;
376 static constexpr int digits10 =
377 static_cast<int>(digits * 0.301029996);
378 static constexpr int max_digits10 = 0;
379 static constexpr int radix = 2;
380 static constexpr int min_exponent = 0;
381 static constexpr int min_exponent10 = 0;
382 static constexpr int max_exponent = 0;
383 static constexpr int max_exponent10 = 0;
384 static constexpr bool traps =
true;
385 static constexpr bool tinyness_before =
false;
387 static constexpr ::ranges::detail::diffmax_t max() noexcept
389 return std::uintmax_t(-1);
391 static constexpr ::ranges::detail::diffmax_t min() noexcept
395 static constexpr ::ranges::detail::diffmax_t lowest() noexcept
399 static constexpr ::ranges::detail::diffmax_t epsilon() noexcept
403 static constexpr ::ranges::detail::diffmax_t round_error() noexcept
407 static constexpr ::ranges::detail::diffmax_t infinity() noexcept
411 static constexpr ::ranges::detail::diffmax_t quiet_NaN() noexcept
415 static constexpr ::ranges::detail::diffmax_t signaling_NaN() noexcept
419 static constexpr ::ranges::detail::diffmax_t denorm_min() noexcept
425 struct numeric_limits<::ranges::detail::diffmax_t const>
426 : numeric_limits<::ranges::detail::diffmax_t>
429 struct numeric_limits<::ranges::detail::diffmax_t volatile>
430 : numeric_limits<::ranges::detail::diffmax_t>
433 struct numeric_limits<::ranges::detail::diffmax_t const volatile>
434 : numeric_limits<::ranges::detail::diffmax_t>
437#if RANGES_CXX_INLINE_VARIABLES >= RANGES_CXX_INLINE_VARIABLES_17
438 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_specialized;
439 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_signed;
440 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_integer;
441 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_exact;
442 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::has_infinity;
443 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::has_quiet_NaN;
444 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::has_signaling_NaN;
445 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::has_denorm;
446 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::has_denorm_loss;
447 inline constexpr std::float_round_style
448 numeric_limits<::ranges::detail::diffmax_t>::round_style;
449 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_iec559;
450 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_bounded;
451 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::is_modulo;
452 inline constexpr int numeric_limits<::ranges::detail::diffmax_t>::digits;
453 inline constexpr int numeric_limits<::ranges::detail::diffmax_t>::digits10;
454 inline constexpr int numeric_limits<::ranges::detail::diffmax_t>::max_digits10;
455 inline constexpr int numeric_limits<::ranges::detail::diffmax_t>::radix;
456 inline constexpr int numeric_limits<::ranges::detail::diffmax_t>::min_exponent;
457 inline constexpr int numeric_limits<::ranges::detail::diffmax_t>::min_exponent10;
458 inline constexpr int numeric_limits<::ranges::detail::diffmax_t>::max_exponent;
459 inline constexpr int numeric_limits<::ranges::detail::diffmax_t>::max_exponent10;
460 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::traps;
461 inline constexpr bool numeric_limits<::ranges::detail::diffmax_t>::tinyness_before;
468#include <range/v3/detail/epilogue.hpp>
Point operator*(double s, const Point &a)
Multiply point by scalar.
Definition shapes.h:250
Point operator-(const Point &a, const Point &b)
Subtract two points_ component-wise.
Definition shapes.h:244