diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-04-22 20:48:42 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-04-27 09:46:53 +0100 |
| commit | 717e37f2f36e80fd27b07e71fbafec048d1ef635 (patch) | |
| tree | 97d0e2b113c78c946bf333cd67bc1e073b23d0b0 | |
| parent | 21644d17d6377a0e0eea6d6798f2b738504550d4 (diff) | |
Add checked, explicit conversion from strongly typed number for size_t
| -rw-r--r-- | src/units.hh | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/units.hh b/src/units.hh index fbb75c22..255fe9e4 100644 --- a/src/units.hh +++ b/src/units.hh @@ -1,6 +1,7 @@ #ifndef units_hh_INCLUDED #define units_hh_INCLUDED +#include "assert.hh" #include "hash.hh" #include <type_traits> @@ -115,7 +116,9 @@ public: friend size_t hash_value(RealType val) { return hash_value(val.m_value); } friend size_t abs(RealType val) { return val.m_value < ValueType(0) ? -val.m_value : val.m_value; } -private: + explicit operator size_t() { kak_assert(m_value >= 0); return (size_t)m_value; } + +protected: ValueType m_value; }; |
