cast: use concepts to constrain narrow
This commit is contained in:
parent
5d0b75d129
commit
6cf54f6f14
18
cast.hpp
18
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<NarrowT> &&
|
||||
std::is_arithmetic_v<WideT> &&
|
||||
std::is_signed_v<NarrowT> == std::is_signed_v<WideT> &&
|
||||
std::is_floating_point_v<NarrowT> == std::is_floating_point_v<WideT> &&
|
||||
sizeof (NarrowT) <= sizeof (WideT),
|
||||
void
|
||||
>
|
||||
concepts::arithmetic NarrowT,
|
||||
concepts::arithmetic WideT
|
||||
>
|
||||
requires
|
||||
(std::is_signed_v<NarrowT> == std::is_signed_v<WideT>) &&
|
||||
(std::is_floating_point_v<NarrowT> == std::is_floating_point_v<WideT>) &&
|
||||
(sizeof (NarrowT) <= sizeof (WideT))
|
||||
constexpr NarrowT
|
||||
narrow (const WideT &val)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user