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
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include "concepts.hpp"
|
||||||
#include "debug/assert.hpp"
|
#include "debug/assert.hpp"
|
||||||
#include "debug/validate.hpp"
|
#include "debug/validate.hpp"
|
||||||
#include "platform.hpp"
|
#include "platform.hpp"
|
||||||
@ -72,17 +74,13 @@ namespace cruft::cast {
|
|||||||
/// Identity casts are allowed so as to simplify the use of this routine
|
/// Identity casts are allowed so as to simplify the use of this routine
|
||||||
/// in template code.
|
/// in template code.
|
||||||
template <
|
template <
|
||||||
typename NarrowT,
|
concepts::arithmetic NarrowT,
|
||||||
typename WideT,
|
concepts::arithmetic 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
|
|
||||||
>
|
|
||||||
>
|
>
|
||||||
|
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
|
constexpr NarrowT
|
||||||
narrow (const WideT &val)
|
narrow (const WideT &val)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user