From b6a67275c9b85265c6221a7e8b20ffc266ef690c Mon Sep 17 00:00:00 2001 From: Kjetil Olsen Lye Date: Wed, 29 Mar 2023 11:49:34 +0200 Subject: [PATCH] Rename to to_int and to_size_t --- .../linalg/cuistl/detail/safe_conversion.hpp | 8 ++++---- tests/cuistl/test_safe_conversion.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/opm/simulators/linalg/cuistl/detail/safe_conversion.hpp b/opm/simulators/linalg/cuistl/detail/safe_conversion.hpp index 735c8eab3..f8ef7f883 100644 --- a/opm/simulators/linalg/cuistl/detail/safe_conversion.hpp +++ b/opm/simulators/linalg/cuistl/detail/safe_conversion.hpp @@ -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, @@ -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, diff --git a/tests/cuistl/test_safe_conversion.cpp b/tests/cuistl/test_safe_conversion.cpp index 9215d5c51..216efb6ab 100644 --- a/tests/cuistl/test_safe_conversion.cpp +++ b/tests/cuistl/test_safe_conversion.cpp @@ -25,7 +25,7 @@ BOOST_AUTO_TEST_CASE(TestToIntThrowsOutofRange) { - BOOST_CHECK_THROW(Opm::cuistl::detail::convert(size_t(std::numeric_limits::max()) + size_t(1)); + BOOST_CHECK_THROW(Opm::cuistl::detail::to_int(size_t(std::numeric_limits::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::max(), - Opm::cuistl::detail::convert(size_t(std::numeric_limits::max()))); + Opm::cuistl::detail::to_int(size_t(std::numeric_limits::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::max()), - Opm::cuistl::detail::convert(std::numeric_limits::max())); + Opm::cuistl::detail::to_size_t(std::numeric_limits::max())); }