diff --git a/include/bmath.hh b/include/bmath.hh index c58b0a5..6b787c1 100644 --- a/include/bmath.hh +++ b/include/bmath.hh @@ -1,8 +1,55 @@ #ifndef BMATH_HEADER_ONLY_MATH_LIB #define BMATH_HEADER_ONLY_MATH_LIB +#include +#include +#include + namespace bmath { -inline int add(int x, int y) { return x + y; } -} // namespace bmath + +template + requires(std::integral || std::is_same_v) +class mint { + public: + [[nodiscard]] constexpr explicit mint() : value{} {} + [[nodiscard]] constexpr explicit mint(IntegralType _value) : value{_value} {} + [[nodiscard]] constexpr explicit operator IntegralType() const noexcept { + return value; + } + + template + [[nodiscard]] constexpr mint operator+( + mint const& otherMint) const noexcept { + return mint{value + otherMint.value}; + } + + [[nodiscard]] constexpr mint& operator-(mint const& other) const noexcept {} + [[nodiscard]] constexpr mint& operator*(mint const& other) const noexcept {} + [[nodiscard]] constexpr mint& operator/(mint const& other) const noexcept {} + [[nodiscard]] constexpr mint& operator%(mint const& other) const noexcept {} + + friend constexpr bool operator==(std::convertible_to auto a, + mint const& b) noexcept { + return static_cast(a) == b.value; + } + + friend constexpr bool operator==( + mint const& a, std::convertible_to auto b) noexcept { + return a.value == static_cast(b); + } + + template + [[nodiscard]] constexpr bool operator==( + mint const& otherMint) const noexcept { + return value == otherMint.value; + } + + [[nodiscard]] constexpr IntegralType get() const { return value; } + + private: + IntegralType value{}; +}; + +} // namespace bmath #endif diff --git a/tests/test_add.cc b/tests/test_add.cc index 5ca00af..deccf5c 100644 --- a/tests/test_add.cc +++ b/tests/test_add.cc @@ -1,8 +1,21 @@ #include +#include + #include "../include/bmath.hh" +using namespace bmath; + int main() { - assert(bmath::add(3, 4) == 3 + 3); + constexpr uint64_t four{4}, five{5}; + constexpr mint mintfour{four}; + constexpr mint mintfive{five}; + + constexpr auto mintnine = mintfour + mintfive; + static_assert(four + five == mintnine.get()); + static_assert(mintnine == four + five); + + static_assert(4 + 5 == mint{9}); + static_assert(mint{8} == 4 + 3); return 0; }