From 717e37f2f36e80fd27b07e71fbafec048d1ef635 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 22 Apr 2016 20:48:42 +0100 Subject: [PATCH] Add checked, explicit conversion from strongly typed number for size_t --- src/units.hh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 @@ -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; };