Rename to to_int and to_size_t

This commit is contained in:
Kjetil Olsen Lye 2023-03-29 11:49:34 +02:00
parent 5373fb7a9c
commit b6a67275c9
2 changed files with 10 additions and 10 deletions

View File

@ -39,7 +39,7 @@ namespace Opm::cuistl::detail
{
/**
* @brief convert converts a (on most relevant platforms) 64 bits unsigned size_t to a signed 32 bits signed int
* @brief to_int converts a (on most relevant platforms) 64 bits unsigned size_t to a signed 32 bits signed int
* @param s the unsigned integer
* @throw std::invalid_argument exception if s is out of range for an int
* @return converted s to int if s is within the range of int
@ -47,7 +47,7 @@ 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
*/
int
convert(size_t s)
to_int(size_t s)
{
static_assert(
std::is_signed_v<int>,
@ -73,7 +73,7 @@ convert(size_t s)
}
/**
* @brief convert converts a (on most relevant platforms) a 32 bit signed int to a 64 bits unsigned int
* @brief to_size_t converts a (on most relevant platforms) a 32 bit signed int to a 64 bits unsigned int
* @param i the signed integer
* @return converted i to size_t if it is a non-negative integer.
*
@ -81,7 +81,7 @@ convert(size_t s)
* @todo This can be done for more generic types, but then it is probably wise to wait for C++20's cmp-functions
*/
size_t
convert(int i)
to_size_t(int i)
{
static_assert(
std::is_signed_v<int>,

View File

@ -25,7 +25,7 @@
BOOST_AUTO_TEST_CASE(TestToIntThrowsOutofRange)
{
BOOST_CHECK_THROW(Opm::cuistl::detail::convert(size_t(std::numeric_limits<int>::max()) + size_t(1));
BOOST_CHECK_THROW(Opm::cuistl::detail::to_int(size_t(std::numeric_limits<int>::max()) + size_t(1));
, std::invalid_argument);
}
@ -33,26 +33,26 @@ BOOST_AUTO_TEST_CASE(TestToIntConvertInRange)
{
// This might seem slow, but it is really fast:
for (size_t i = 0; i <= size_t(1024 * 1024); ++i) {
BOOST_CHECK_EQUAL(int(i), Opm::cuistl::detail::convert(i));
BOOST_CHECK_EQUAL(int(i), Opm::cuistl::detail::to_int(i));
}
BOOST_CHECK_EQUAL(std::numeric_limits<int>::max(),
Opm::cuistl::detail::convert(size_t(std::numeric_limits<int>::max())));
Opm::cuistl::detail::to_int(size_t(std::numeric_limits<int>::max())));
}
BOOST_AUTO_TEST_CASE(TestToSizeTThrowsOutofRange)
{
BOOST_CHECK_THROW(Opm::cuistl::detail::convert(-1);, std::invalid_argument);
BOOST_CHECK_THROW(Opm::cuistl::detail::to_size_t(-1);, std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(TestToSizeTConvertInRange)
{
// This might seem slow, but it is really fast:
for (int i = 0; i <= 1024 * 1024; ++i) {
BOOST_CHECK_EQUAL(size_t(i), Opm::cuistl::detail::convert(i));
BOOST_CHECK_EQUAL(size_t(i), Opm::cuistl::detail::to_size_t(i));
}
BOOST_CHECK_EQUAL(size_t(std::numeric_limits<int>::max()),
Opm::cuistl::detail::convert(std::numeric_limits<int>::max()));
Opm::cuistl::detail::to_size_t(std::numeric_limits<int>::max()));
}