Version: SMASH-3.1
numeric_cast.h
Go to the documentation of this file.
1
/*
2
*
3
* Copyright (c) 2022
4
* SMASH Team
5
*
6
* GNU General Public License (GPLv3 or later)
7
*
8
*/
9
10
#ifndef SRC_INCLUDE_SMASH_NUMERIC_CAST_H_
11
#define SRC_INCLUDE_SMASH_NUMERIC_CAST_H_
12
13
#include <limits>
14
15
namespace
smash
{
16
30
template
<
typename
D,
typename
S>
31
constexpr D
numeric_cast
(
const
S
value);
32
41
template
<>
42
constexpr uint32_t
numeric_cast
(
const
size_t
value) {
43
// Conversion from unsigned to unsigned
44
// => the only possible problem is a positive overflow.
45
if
(value > std::numeric_limits<uint32_t>::max()) {
46
throw
std::overflow_error(
47
"Input value overflows the target uint32_t type!"
);
48
}
49
return
static_cast<
uint32_t
>
(value);
50
}
51
52
}
// namespace smash
53
54
#endif
// SRC_INCLUDE_SMASH_NUMERIC_CAST_H_
smash
Definition:
action.h:24
smash::numeric_cast
constexpr D numeric_cast(const S value)
Function template to perform a safe numeric conversion between types.
S
#define S(x, n)
Definition:
sha256.cc:54
src
include
smash
numeric_cast.h
Impressum
Data privacy protection
Generated on Mon Feb 26 2024 14:05:12 for SMASH Development Documentation by
Doxygen
1.9.1