| 2100 | } |
| 2101 | |
| 2102 | template<typename T> static uint64_t EnumDistanceImpl(T e1, T e2) { |
| 2103 | if (e1 < e2) { std::swap(e1, e2); } // use std for scalars |
| 2104 | // Signed overflow may occur, use unsigned calculation. |
| 2105 | // The unsigned overflow is well-defined by C++ standard (modulo 2^n). |
| 2106 | return static_cast<uint64_t>(e1) - static_cast<uint64_t>(e2); |
| 2107 | } |
| 2108 | |
| 2109 | uint64_t EnumDef::Distance(const EnumVal *v1, const EnumVal *v2) const { |
| 2110 | return IsUInt64() ? EnumDistanceImpl(v1->GetAsUInt64(), v2->GetAsUInt64()) |