@@ -30,10 +30,28 @@ namespace ADT {
3030 return Range (Begin, Size);
3131 }
3232
33+ [[nodiscard]] constexpr static auto CreateMax () noexcept {
34+ return Range::FromSize (0 , std::numeric_limits<uint64_t >::max ());
35+ }
36+
37+ [[nodiscard]] constexpr static auto
38+ FromSizeAndCount (const uint64_t Begin,
39+ const uint64_t Size,
40+ const uint64_t Count) noexcept
41+ -> std::optional<ADT::Range>
42+ {
43+ auto TotalSize = Utils::MulAndCheckOverflow (Size, Count);
44+ if (TotalSize.has_value ()) {
45+ return Range::FromSize (Begin, TotalSize.value ());
46+ }
47+
48+ return std::nullopt ;
49+ }
50+
3351 [[nodiscard]] constexpr static
3452 auto FromEnd (const uint64_t Begin, const uint64_t End) noexcept {
3553 assert (Begin <= End);
36- return Range (Begin, (End - Begin));
54+ return Range::FromSize (Begin, (End - Begin));
3755 }
3856
3957 [[nodiscard]] constexpr auto front () const noexcept {
@@ -44,6 +62,29 @@ namespace ADT {
4462 return this ->Size ;
4563 }
4664
65+ [[nodiscard]]
66+ constexpr auto adding (const uint64_t Base) const noexcept
67+ -> std::optional<Range>
68+ {
69+ auto NewBegin = uint64_t ();
70+ if (!Utils::AddAndCheckOverflow (this ->front (), Base, NewBegin)) {
71+ return std::nullopt ;
72+ }
73+
74+ return Range::FromSize (NewBegin, this ->size ());
75+ }
76+
77+ [[nodiscard]]
78+ constexpr auto subtracting (const uint64_t Base) const noexcept
79+ -> std::optional<Range>
80+ {
81+ if (Base > this ->front ()) {
82+ return std::nullopt ;
83+ }
84+
85+ return Range::FromSize (this ->front () - Base, this ->size ());
86+ }
87+
4788 [[nodiscard]] constexpr auto end () const noexcept {
4889 return Utils::AddAndCheckOverflow (this ->front (), this ->size ());
4990 }
@@ -144,7 +185,7 @@ namespace ADT {
144185 indexForLoc (const uint64_t Loc,
145186 uint64_t *const MaxSizeOut = nullptr ) const noexcept
146187 {
147- assert (hasLoc (Loc));
188+ assert (this -> hasLoc (Loc));
148189
149190 const auto Index = Loc - this ->front ();
150191 if (MaxSizeOut != nullptr ) {
@@ -234,6 +275,18 @@ namespace ADT {
234275 return Range::FromSize (0 , Index);
235276 }
236277
278+ [[nodiscard]]
279+ constexpr auto multiply (const uint64_t Count) const noexcept
280+ -> std::optional<Range>
281+ {
282+ auto NewSize = uint64_t ();
283+ if (Utils::MulAddAndCheckOverflow (this ->size (), Count, NewSize)) {
284+ return std::nullopt ;
285+ }
286+
287+ return Range::FromSize (this ->front (), NewSize);
288+ }
289+
237290 [[nodiscard]]
238291 constexpr auto operator ==(const Range &Range) const noexcept {
239292 return this ->front () == Range.front () &&
0 commit comments