num/pairnum.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <istream> | ||
| 4 | #include <ostream> | ||
| 5 | |||
| 6 | #include "num/modnum.hpp" | ||
| 7 | |||
| 8 | namespace wala { | ||
| 9 | |||
| 10 | template <typename U, typename V> struct pairnum : num_ops<pairnum<U, V>> { | ||
| 11 | using Self = pairnum; | ||
| 12 | U u; | ||
| 13 | V v; | ||
| 14 | |||
| 15 | ✗ | pairnum() : u(0), v(0) {} | |
| 16 | ✗ | pairnum(long long val) : u(val), v(val) {} | |
| 17 | ✗ | pairnum(const U& u_, const V& v_) : u(u_), v(v_) {} | |
| 18 | |||
| 19 | ✗ | friend std::ostream& operator << (std::ostream& out, const Self& n) { return out << '(' << n.u << ',' << ' ' << n.v << ')'; } | |
| 20 | ✗ | friend std::istream& operator >> (std::istream& in, Self& n) { long long val; in >> val; n = Self(val); return in; } | |
| 21 | |||
| 22 | ✗ | friend bool operator == (const Self& a, const Self& b) { return a.u == b.u && a.v == b.v; } | |
| 23 | |||
| 24 | ✗ | Self inv() const { | |
| 25 | ✗ | return Self(u.inv(), v.inv()); | |
| 26 | } | ||
| 27 | ✗ | Self neg() const { | |
| 28 | ✗ | return Self(u.neg(), v.neg()); | |
| 29 | } | ||
| 30 | |||
| 31 | ✗ | Self& operator ++ () { | |
| 32 | ✗ | ++u, ++v; | |
| 33 | ✗ | return *this; | |
| 34 | } | ||
| 35 | ✗ | Self& operator -- () { | |
| 36 | ✗ | --u, --v; | |
| 37 | ✗ | return *this; | |
| 38 | } | ||
| 39 | |||
| 40 | ✗ | Self& operator += (const Self& o) { | |
| 41 | ✗ | u += o.u; | |
| 42 | ✗ | v += o.v; | |
| 43 | ✗ | return *this; | |
| 44 | } | ||
| 45 | ✗ | Self& operator -= (const Self& o) { | |
| 46 | ✗ | u -= o.u; | |
| 47 | ✗ | v -= o.v; | |
| 48 | ✗ | return *this; | |
| 49 | } | ||
| 50 | ✗ | Self& operator *= (const Self& o) { | |
| 51 | ✗ | u *= o.u; | |
| 52 | ✗ | v *= o.v; | |
| 53 | ✗ | return *this; | |
| 54 | } | ||
| 55 | ✗ | Self& operator /= (const Self& o) { | |
| 56 | ✗ | u /= o.u; | |
| 57 | ✗ | v /= o.v; | |
| 58 | ✗ | return *this; | |
| 59 | } | ||
| 60 | }; | ||
| 61 | |||
| 62 | } // namespace wala | ||
| 63 |