summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-04-22 20:48:42 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-04-27 09:46:53 +0100
commit717e37f2f36e80fd27b07e71fbafec048d1ef635 (patch)
tree97d0e2b113c78c946bf333cd67bc1e073b23d0b0 /src
parent21644d17d6377a0e0eea6d6798f2b738504550d4 (diff)
Add checked, explicit conversion from strongly typed number for size_t
Diffstat (limited to 'src')
-rw-r--r--src/units.hh5
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;
};