@@ -181,12 +181,25 @@ class MI_EXPORT_LIB Properties {
181181
182182 // Perform a range check just in case
183183 if constexpr (std::is_integral_v<T2> && !std::is_same_v<T2, bool >) {
184- constexpr T2 min = (T2) std::numeric_limits<T>::min (),
185- max = (T2) std::numeric_limits<T>::max ();
186-
187- if (value < min || value > max)
188- Throw (" Property \" %s\" : value %lld is out of bounds, must be "
189- " in the range [%lld, %lld]" , name, value, min, max);
184+ constexpr T min_t = std::numeric_limits<T>::min (),
185+ max_t = std::numeric_limits<T>::max ();
186+
187+ if constexpr (std::is_unsigned_v<T>) {
188+ bool out_of_bounds = false ;
189+ if constexpr (max_t <= (T) std::numeric_limits<T2>::max ())
190+ out_of_bounds = value > (T2) max_t ;
191+ if (value < 0 )
192+ out_of_bounds = true ;
193+ if (out_of_bounds)
194+ Throw (" Property \" %s\" : value %lld is out of bounds, must be "
195+ " in the range [%llu, %llu]" , name, value,
196+ (unsigned long long ) min_t , (unsigned long long ) max_t );
197+ } else {
198+ if (value < (T2) min_t || value > (T2) max_t )
199+ Throw (" Property \" %s\" : value %lld is out of bounds, must be "
200+ " in the range [%lld, %lld]" , name, value,
201+ (long long ) min_t , (long long ) max_t );
202+ }
190203 }
191204
192205 if constexpr (std::is_same_v<T2, ref<Object>>) {
@@ -243,12 +256,25 @@ class MI_EXPORT_LIB Properties {
243256
244257 // Perform a range check just in case
245258 if constexpr (std::is_integral_v<T2> && !std::is_same_v<T2, bool >) {
246- constexpr T2 min = (T2) std::numeric_limits<T>::min (),
247- max = (T2) std::numeric_limits<T>::max ();
248-
249- if (value < min || value > max)
250- Throw (" Property \" %s\" : value %lld is out of bounds, must be "
251- " in the range [%lld, %lld]" , name, value, min, max);
259+ constexpr T min_t = std::numeric_limits<T>::min ();
260+ constexpr T max_t = std::numeric_limits<T>::max ();
261+
262+ if constexpr (std::is_unsigned_v<T>) {
263+ bool out_of_bounds = false ;
264+ if constexpr (max_t <= (T) std::numeric_limits<T2>::max ())
265+ out_of_bounds = value > (T2) max_t ;
266+ if (value < 0 )
267+ out_of_bounds = true ;
268+ if (out_of_bounds)
269+ Throw (" Property \" %s\" : value %lld is out of bounds, must be "
270+ " in the range [%llu, %llu]" , name, value,
271+ (unsigned long long ) min_t , (unsigned long long ) max_t );
272+ } else {
273+ if (value < (T2) min_t || value > (T2) max_t )
274+ Throw (" Property \" %s\" : value %lld is out of bounds, must be "
275+ " in the range [%lld, %lld]" , name, value,
276+ (long long ) min_t , (long long ) max_t );
277+ }
252278 }
253279
254280 if constexpr (std::is_same_v<T2, ref<Object>>) {
0 commit comments