mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Switched from size_t to std::size_t in safe_conversion.hpp.
This commit is contained in:
parent
171a205125
commit
1a6720996a
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <opm/common/ErrorMacros.hpp>
|
#include <opm/common/ErrorMacros.hpp>
|
||||||
@ -47,21 +48,21 @@ namespace Opm::cuistl::detail
|
|||||||
* @todo This can be done for more generic types, but then it is probably wise to wait for C++20's cmp-functions
|
* @todo This can be done for more generic types, but then it is probably wise to wait for C++20's cmp-functions
|
||||||
*/
|
*/
|
||||||
inline int
|
inline int
|
||||||
to_int(size_t s)
|
to_int(std::size_t s)
|
||||||
{
|
{
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_signed_v<int>,
|
std::is_signed_v<int>,
|
||||||
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
||||||
static_assert(
|
static_assert(
|
||||||
!std::is_signed_v<size_t>,
|
!std::is_signed_v<std::size_t>,
|
||||||
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
||||||
|
|
||||||
static_assert(
|
static_assert(
|
||||||
sizeof(int) <= sizeof(size_t),
|
sizeof(int) <= sizeof(std::size_t),
|
||||||
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
||||||
|
|
||||||
|
|
||||||
if (s > size_t(std::numeric_limits<int>::max())) {
|
if (s > std::size_t(std::numeric_limits<int>::max())) {
|
||||||
OPM_THROW(std::invalid_argument,
|
OPM_THROW(std::invalid_argument,
|
||||||
fmt::format("Trying to convert {} to int, but it is out of range. Maximum possible int: {}. ",
|
fmt::format("Trying to convert {} to int, but it is out of range. Maximum possible int: {}. ",
|
||||||
s,
|
s,
|
||||||
@ -80,18 +81,18 @@ to_int(size_t s)
|
|||||||
* @throw std::invalid_argument if i is negative.
|
* @throw std::invalid_argument if i is negative.
|
||||||
* @todo This can be done for more generic types, but then it is probably wise to wait for C++20's cmp-functions
|
* @todo This can be done for more generic types, but then it is probably wise to wait for C++20's cmp-functions
|
||||||
*/
|
*/
|
||||||
inline size_t
|
inline std::size_t
|
||||||
to_size_t(int i)
|
to_size_t(int i)
|
||||||
{
|
{
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_signed_v<int>,
|
std::is_signed_v<int>,
|
||||||
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
||||||
static_assert(
|
static_assert(
|
||||||
!std::is_signed_v<size_t>,
|
!std::is_signed_v<std::size_t>,
|
||||||
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
||||||
|
|
||||||
static_assert(
|
static_assert(
|
||||||
sizeof(int) <= sizeof(size_t),
|
sizeof(int) <= sizeof(std::size_t),
|
||||||
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
"Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
|
||||||
|
|
||||||
|
|
||||||
@ -99,7 +100,7 @@ to_size_t(int i)
|
|||||||
OPM_THROW(std::invalid_argument, fmt::format("Trying to convert the negative number {} to size_t.", i));
|
OPM_THROW(std::invalid_argument, fmt::format("Trying to convert the negative number {} to size_t.", i));
|
||||||
}
|
}
|
||||||
|
|
||||||
return size_t(i);
|
return std::size_t(i);
|
||||||
}
|
}
|
||||||
} // namespace Opm::cuistl::detail
|
} // namespace Opm::cuistl::detail
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user