Skip to content

Commit 1bf01f6

Browse files
committed
Remove include dependency from integer on Tuple
1 parent f36af5a commit 1bf01f6

10 files changed

+135
-75
lines changed

num/__private/signed_integer_macros.h

Lines changed: 71 additions & 44 deletions
Large diffs are not rendered by default.

num/__private/unsigned_integer_macros.h

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "num/__private/ptr_type.h"
2828
#include "num/integer_concepts.h"
2929
#include "option/option.h"
30-
#include "tuple/tuple.h"
3130

3231
namespace sus::containers {
3332
template <class T, size_t N>
@@ -39,6 +38,11 @@ namespace sus::num {
3938
struct u8;
4039
}
4140

41+
namespace sus::tuple {
42+
template <class T, class... Ts>
43+
class Tuple;
44+
}
45+
4246
#define _sus__unsigned_impl(T, PrimitiveT, SignedT) \
4347
_sus__unsigned_storage(PrimitiveT); \
4448
_sus__unsigned_constants(T, PrimitiveT); \
@@ -354,10 +358,12 @@ struct u8;
354358
* an arithmetic overflow would occur. If an overflow would have occurred \
355359
* then the wrapped value is returned. \
356360
*/ \
357-
constexpr Tuple<T, bool> overflowing_add(const T& rhs) const& noexcept { \
361+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
362+
::sus::tuple::Tuple<T, bool>> \
363+
constexpr Tuple overflowing_add(const T& rhs) const& noexcept { \
358364
const auto out = \
359365
__private::add_with_overflow(primitive_value, rhs.primitive_value); \
360-
return Tuple<T, bool>::with(out.value, out.overflow); \
366+
return Tuple::with(out.value, out.overflow); \
361367
} \
362368
\
363369
/** Calculates self + rhs with an unsigned rhs \
@@ -366,12 +372,13 @@ struct u8;
366372
* an arithmetic overflow would occur. If an overflow would have occurred \
367373
* then the wrapped value is returned. \
368374
*/ \
369-
template <std::same_as<SignedT> S> \
370-
constexpr Tuple<T, bool> overflowing_add_signed(const S& rhs) \
371-
const& noexcept { \
375+
template <std::same_as<SignedT> S, \
376+
std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
377+
::sus::tuple::Tuple<T, bool>> \
378+
constexpr Tuple overflowing_add_signed(const S& rhs) const& noexcept { \
372379
const auto r = __private::add_with_overflow_signed(primitive_value, \
373380
rhs.primitive_value); \
374-
return Tuple<T, bool>::with(r.value, r.overflow); \
381+
return Tuple::with(r.value, r.overflow); \
375382
} \
376383
\
377384
/** Saturating integer addition. Computes self + rhs, saturating at the \
@@ -452,10 +459,12 @@ struct u8;
452459
* #Panics \
453460
*This function will panic if rhs is 0. \
454461
*/ \
455-
constexpr Tuple<T, bool> overflowing_div(const T& rhs) const& noexcept { \
462+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
463+
::sus::tuple::Tuple<T, bool>> \
464+
constexpr Tuple overflowing_div(const T& rhs) const& noexcept { \
456465
/* TODO: Allow opting out of all overflow checks? */ \
457466
::sus::check(rhs.primitive_value != 0u); \
458-
return Tuple<T, bool>::with( \
467+
return Tuple::with( \
459468
__private::unchecked_div(primitive_value, rhs.primitive_value), \
460469
false); \
461470
} \
@@ -506,10 +515,12 @@ struct u8;
506515
* whether an arithmetic overflow would occur. If an overflow would have \
507516
* occurred then the wrapped value is returned. \
508517
*/ \
509-
constexpr Tuple<T, bool> overflowing_mul(const T& rhs) const& noexcept { \
518+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
519+
::sus::tuple::Tuple<T, bool>> \
520+
constexpr Tuple overflowing_mul(const T& rhs) const& noexcept { \
510521
const auto out = \
511522
__private::mul_with_overflow(primitive_value, rhs.primitive_value); \
512-
return Tuple<T, bool>::with(out.value, out.overflow); \
523+
return Tuple::with(out.value, out.overflow); \
513524
} \
514525
\
515526
/** Saturating integer multiplication. Computes self * rhs, saturating at \
@@ -558,9 +569,11 @@ struct u8;
558569
* represents the negation of this unsigned value. Note that for positive \
559570
* unsigned values overflow always occurs, but negating 0 does not overflow. \
560571
*/ \
561-
constexpr Tuple<T, bool> overflowing_neg() const& noexcept { \
562-
return Tuple<T, bool>::with((~(*this)).wrapping_add(T(PrimitiveT{1u})), \
563-
primitive_value != 0u); \
572+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
573+
::sus::tuple::Tuple<T, bool>> \
574+
constexpr Tuple overflowing_neg() const& noexcept { \
575+
return Tuple::with((~(*this)).wrapping_add(T(PrimitiveT{1u})), \
576+
primitive_value != 0u); \
564577
} \
565578
\
566579
/** Wrapping (modular) negation. Computes `-self`, wrapping around at the \
@@ -600,10 +613,12 @@ struct u8;
600613
* # Panics \
601614
* This function will panic if rhs is 0. \
602615
*/ \
603-
constexpr Tuple<T, bool> overflowing_rem(const T& rhs) const& noexcept { \
616+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
617+
::sus::tuple::Tuple<T, bool>> \
618+
constexpr Tuple overflowing_rem(const T& rhs) const& noexcept { \
604619
/* TODO: Allow opting out of all overflow checks? */ \
605620
::sus::check(rhs.primitive_value != 0u); \
606-
return Tuple<T, bool>::with( \
621+
return Tuple::with( \
607622
__private::unchecked_rem(primitive_value, rhs.primitive_value), \
608623
false); \
609624
} \
@@ -662,11 +677,12 @@ struct u8;
662677
* # Panics \
663678
* This function will panic if rhs is 0. \
664679
*/ \
665-
constexpr Tuple<T, bool> overflowing_div_euclid(const T& rhs) \
666-
const& noexcept { \
680+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
681+
::sus::tuple::Tuple<T, bool>> \
682+
constexpr Tuple overflowing_div_euclid(const T& rhs) const& noexcept { \
667683
/* TODO: Allow opting out of all overflow checks? */ \
668684
::sus::check(rhs.primitive_value != 0u); \
669-
return Tuple<T, bool>::with( \
685+
return Tuple::with( \
670686
__private::unchecked_div(primitive_value, rhs.primitive_value), \
671687
false); \
672688
} \
@@ -727,11 +743,12 @@ struct u8;
727743
* # Panics \
728744
* This function will panic if rhs is 0. \
729745
*/ \
730-
constexpr Tuple<T, bool> overflowing_rem_euclid(const T& rhs) \
731-
const& noexcept { \
746+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
747+
::sus::tuple::Tuple<T, bool>> \
748+
constexpr Tuple overflowing_rem_euclid(const T& rhs) const& noexcept { \
732749
/* TODO: Allow opting out of all overflow checks? */ \
733750
::sus::check(rhs.primitive_value != 0u); \
734-
return Tuple<T, bool>::with( \
751+
return Tuple::with( \
735752
__private::unchecked_rem(primitive_value, rhs.primitive_value), \
736753
false); \
737754
} \
@@ -775,10 +792,12 @@ struct u8;
775792
* where N is the number of bits, and this value is then used to perform the \
776793
* shift. \
777794
*/ \
778-
constexpr Tuple<T, bool> overflowing_shl(const u32& rhs) const& noexcept { \
795+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
796+
::sus::tuple::Tuple<T, bool>> \
797+
constexpr Tuple overflowing_shl(const u32& rhs) const& noexcept { \
779798
const auto out = \
780799
__private::shl_with_overflow(primitive_value, rhs.primitive_value); \
781-
return Tuple<T, bool>::with(out.value, out.overflow); \
800+
return Tuple::with(out.value, out.overflow); \
782801
} \
783802
\
784803
/** Panic-free bitwise shift-left; yields `*this << mask(rhs)`, where mask \
@@ -816,10 +835,12 @@ struct u8;
816835
* where N is the number of bits, and this value is then used to perform the \
817836
* shift. \
818837
*/ \
819-
constexpr Tuple<T, bool> overflowing_shr(const u32& rhs) const& noexcept { \
838+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
839+
::sus::tuple::Tuple<T, bool>> \
840+
constexpr Tuple overflowing_shr(const u32& rhs) const& noexcept { \
820841
const auto out = \
821842
__private::shr_with_overflow(primitive_value, rhs.primitive_value); \
822-
return Tuple<T, bool>::with(out.value, out.overflow); \
843+
return Tuple::with(out.value, out.overflow); \
823844
} \
824845
\
825846
/** Panic-free bitwise shift-right; yields `*this >> mask(rhs)`, where mask \
@@ -857,10 +878,12 @@ struct u8;
857878
* whether an arithmetic overflow would occur. If an overflow would have \
858879
* occurred then the wrapped value is returned. \
859880
*/ \
860-
constexpr Tuple<T, bool> overflowing_sub(const T& rhs) const& noexcept { \
881+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
882+
::sus::tuple::Tuple<T, bool>> \
883+
constexpr Tuple overflowing_sub(const T& rhs) const& noexcept { \
861884
const auto out = \
862885
__private::sub_with_overflow(primitive_value, rhs.primitive_value); \
863-
return Tuple<T, bool>::with(out.value, out.overflow); \
886+
return Tuple::with(out.value, out.overflow); \
864887
} \
865888
\
866889
/** Saturating integer subtraction. Computes self - rhs, saturating at the \
@@ -995,10 +1018,12 @@ struct u8;
9951018
* Returns a tuple of the exponentiation along with a bool indicating \
9961019
* whether an overflow happened. \
9971020
*/ \
998-
constexpr Tuple<T, bool> overflowing_pow(const u32& exp) const& noexcept { \
1021+
template <std::same_as<::sus::tuple::Tuple<T, bool>> Tuple = \
1022+
::sus::tuple::Tuple<T, bool>> \
1023+
constexpr Tuple overflowing_pow(const u32& exp) const& noexcept { \
9991024
const auto out = \
10001025
__private::pow_with_overflow(primitive_value, exp.primitive_value); \
1001-
return Tuple<T, bool>::with(out.value, out.overflow); \
1026+
return Tuple::with(out.value, out.overflow); \
10021027
} \
10031028
\
10041029
/** Wrapping (modular) exponentiation. Computes self.pow(exp), wrapping \

num/i16_unittest.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "num/signed_integer.h"
2121
#include "num/unsigned_integer.h"
2222
#include "third_party/googletest/googletest/include/gtest/gtest.h"
23+
#include "tuple/tuple.h"
2324

2425
namespace {
2526

num/i64_unittest.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "num/signed_integer.h"
2121
#include "num/unsigned_integer.h"
2222
#include "third_party/googletest/googletest/include/gtest/gtest.h"
23+
#include "tuple/tuple.h"
2324

2425
namespace {
2526

num/i8_unittest.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "num/signed_integer.h"
2121
#include "num/unsigned_integer.h"
2222
#include "third_party/googletest/googletest/include/gtest/gtest.h"
23+
#include "tuple/tuple.h"
2324

2425
namespace {
2526

num/isize_unittest.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "num/signed_integer.h"
2121
#include "num/unsigned_integer.h"
2222
#include "third_party/googletest/googletest/include/gtest/gtest.h"
23+
#include "tuple/tuple.h"
2324

2425
namespace {
2526

num/u16_unittest.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "num/signed_integer.h"
2121
#include "num/unsigned_integer.h"
2222
#include "third_party/googletest/googletest/include/gtest/gtest.h"
23+
#include "tuple/tuple.h"
2324

2425
namespace {
2526

num/u64_unittest.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "num/signed_integer.h"
2121
#include "num/unsigned_integer.h"
2222
#include "third_party/googletest/googletest/include/gtest/gtest.h"
23+
#include "tuple/tuple.h"
2324

2425
namespace {
2526

num/u8_unittest.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "num/signed_integer.h"
2121
#include "num/unsigned_integer.h"
2222
#include "third_party/googletest/googletest/include/gtest/gtest.h"
23+
#include "tuple/tuple.h"
2324

2425
namespace {
2526

num/usize_unittest.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
#include <type_traits>
1616

1717
#include "construct/into.h"
18-
#include "num/num_concepts.h"
1918
#include "containers/array.h"
19+
#include "num/num_concepts.h"
2020
#include "num/signed_integer.h"
2121
#include "num/unsigned_integer.h"
2222
#include "third_party/googletest/googletest/include/gtest/gtest.h"
23+
#include "tuple/tuple.h"
2324

2425
namespace {
2526

0 commit comments

Comments
 (0)