rename castSafely to follow naming rule

This commit is contained in:
falsycat 2023-09-11 06:37:24 +09:00
parent 0123434f4b
commit 8690d758f4
3 changed files with 8 additions and 8 deletions

View File

@ -7,7 +7,7 @@
namespace nf7 { namespace nf7 {
template <typename R, typename T> template <typename R, typename T>
auto castSafely( auto CastSafely(
T v, std::source_location location = std::source_location::current()) T v, std::source_location location = std::source_location::current())
-> std::enable_if_t<std::is_arithmetic_v<R> && std::is_arithmetic_v<T>, R> { -> std::enable_if_t<std::is_arithmetic_v<R> && std::is_arithmetic_v<T>, R> {
const auto r = static_cast<R>(v); const auto r = static_cast<R>(v);

View File

@ -7,17 +7,17 @@
TEST(Numeric, CastSafelyShrink) { TEST(Numeric, CastSafelyShrink) {
EXPECT_EQ(nf7::castSafely<uint8_t>(uint32_t {0}), 0); EXPECT_EQ(nf7::CastSafely<uint8_t>(uint32_t {0}), 0);
} }
TEST(Numeric, CastSafelyShrinkWithOverflow) { TEST(Numeric, CastSafelyShrinkWithOverflow) {
EXPECT_THROW(nf7::castSafely<uint8_t>(uint32_t {1000}), nf7::Exception); EXPECT_THROW(nf7::CastSafely<uint8_t>(uint32_t {1000}), nf7::Exception);
} }
TEST(Numeric, CastSafelyShrinkWithUnderflow) { TEST(Numeric, CastSafelyShrinkWithUnderflow) {
EXPECT_THROW(nf7::castSafely<int8_t>(int32_t {-1000}), nf7::Exception); EXPECT_THROW(nf7::CastSafely<int8_t>(int32_t {-1000}), nf7::Exception);
} }
TEST(Numeric, CastSafelyShrinkWithSignDrop) { TEST(Numeric, CastSafelyShrinkWithSignDrop) {
EXPECT_THROW(nf7::castSafely<uint8_t>(int32_t {-1}), nf7::Exception); EXPECT_THROW(nf7::CastSafely<uint8_t>(int32_t {-1}), nf7::Exception);
} }
TEST(Numeric, CastSafelyExpand) { TEST(Numeric, CastSafelyExpand) {
EXPECT_EQ(nf7::castSafely<uint32_t>(uint8_t {255}), 255); EXPECT_EQ(nf7::CastSafely<uint32_t>(uint8_t {255}), 255);
} }

View File

@ -266,10 +266,10 @@ class Value final {
N num(std::optional<N> def = std::nullopt, N num(std::optional<N> def = std::nullopt,
std::source_location location = std::source_location::current()) const { std::source_location location = std::source_location::current()) const {
if (is<Integer>()) { if (is<Integer>()) {
return castSafely<N>(as<Integer>()); return CastSafely<N>(as<Integer>());
} }
if (is<Real>()) { if (is<Real>()) {
return castSafely<N>(as<Real>()); return CastSafely<N>(as<Real>());
} }
if (std::nullopt != def) { if (std::nullopt != def) {
return *def; return *def;