19#ifndef OPM_CUISTL_SAFE_CONVERSION_HPP
20#define OPM_CUISTL_SAFE_CONVERSION_HPP
25#include <fmt/format.h>
27#include <opm/common/ErrorMacros.hpp>
54 std::is_signed_v<int>,
55 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
57 !std::is_signed_v<std::size_t>,
58 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
61 sizeof(
int) <=
sizeof(std::size_t),
62 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
65 if (s > std::size_t(std::numeric_limits<int>::max())) {
67 fmt::format(
"Trying to convert {} to int, but it is out of range. Maximum possible int: {}. ",
69 std::numeric_limits<int>::max()));
88 std::is_signed_v<int>,
89 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
91 !std::is_signed_v<std::size_t>,
92 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
95 sizeof(
int) <=
sizeof(std::size_t),
96 "Weird architecture or my understanding of the standard is flawed. Better have a look at this function.");
100 OPM_THROW(std::invalid_argument, fmt::format(
"Trying to convert the negative number {} to size_t.",
i));
103 return std::size_t(
i);
Definition AquiferInterface.hpp:35
Contains wrappers to make the CuBLAS library behave as a modern C++ library with function overlading.
Definition cublas_safe_call.hpp:32
int to_int(std::size_t s)
to_int converts a (on most relevant platforms) 64 bits unsigned size_t to a signed 32 bits signed int
Definition safe_conversion.hpp:51
std::size_t to_size_t(int i)
to_size_t converts a (on most relevant platforms) a 32 bit signed int to a 64 bits unsigned int
Definition safe_conversion.hpp:85