From 6cf54f6f144cee1a297ea5398211f98da5559888 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 27 Feb 2020 11:49:41 +1100 Subject: [PATCH] cast: use concepts to constrain `narrow` --- cast.hpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/cast.hpp b/cast.hpp index 37e6d58b..ed4fbb98 100644 --- a/cast.hpp +++ b/cast.hpp @@ -8,6 +8,8 @@ #pragma once + +#include "concepts.hpp" #include "debug/assert.hpp" #include "debug/validate.hpp" #include "platform.hpp" @@ -72,17 +74,13 @@ namespace cruft::cast { /// Identity casts are allowed so as to simplify the use of this routine /// in template code. template < - typename NarrowT, - typename WideT, - typename = std::enable_if_t< - std::is_arithmetic_v && - std::is_arithmetic_v && - std::is_signed_v == std::is_signed_v && - std::is_floating_point_v == std::is_floating_point_v && - sizeof (NarrowT) <= sizeof (WideT), - void - > + concepts::arithmetic NarrowT, + concepts::arithmetic WideT > + requires + (std::is_signed_v == std::is_signed_v) && + (std::is_floating_point_v == std::is_floating_point_v) && + (sizeof (NarrowT) <= sizeof (WideT)) constexpr NarrowT narrow (const WideT &val) {