6template<
typename T,
double M1,
double Q1>
class Length
10 explicit Length(int32_t i) : m(i) { assert(int32_t(m) == i); }
11 explicit Length(int64_t i) : m(i) { assert(int64_t(m) == i); }
12 explicit Length(T v) : m(v) { }
13 template<
double M2,
double Q2> Length(
const Length<T, M2, Q2> &l) { m = l.value() * ((M2 * Q1) / (M1 * Q2)); }
14 T value()
const {
return m; }
15 Length<T,M1,Q1> operator+(
const Length<T,M1,Q1> &l)
const {
return Length<T,M1,Q1>(m + l.m); }
16 Length<T,M1,Q1> operator-(
const Length<T,M1,Q1> &l)
const {
return Length<T,M1,Q1>(m - l.m); }
17 Length<T,M1,Q1>& operator+=(
const Length<T,M1,Q1> &l) { m += l.m;
return *
this; }
18 Length<T,M1,Q1>& operator-=(
const Length<T,M1,Q1> &l) { m += l.m;
return *
this; }
19 Length<T,M1,Q1> operator*(T s)
const {
return Length<T,M1,Q1>(m * s); }
20 Length<T,M1,Q1>& operator*=(T s) { m *= s;
return *
this; }
21 template<
double M2,
double Q2>
bool operator< (
const Length<T,M2,Q2> &l)
const {
return value() * (M1 * Q2) < l.value() * (Q1 * M2); }
22 template<
double M2,
double Q2>
bool operator<=(
const Length<T,M2,Q2> &l)
const {
return value() * (M1 * Q2) <= l.value() * (Q1 * M2); }
23 template<
double M2,
double Q2>
bool operator==(
const Length<T,M2,Q2> &l)
const {
return value() * (M1 * Q2) == l.value() * (Q1 * M2); }