From ecf55f86d6451eed6b79618a2303111ba7ee345c Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 21 Jun 2019 00:25:21 +0900 Subject: [PATCH] refactor: add explicit type conversion --- toml/datetime.hpp | 12 ++++++------ toml/region.hpp | 9 +++++---- toml/serializer.hpp | 2 +- toml/source_location.hpp | 6 +++--- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/toml/datetime.hpp b/toml/datetime.hpp index 4ea75e7..dc52396 100644 --- a/toml/datetime.hpp +++ b/toml/datetime.hpp @@ -188,22 +188,22 @@ struct local_time explicit local_time(const std::chrono::duration& t) { const auto h = std::chrono::duration_cast(t); - this->hour = h.count(); + this->hour = static_cast(h.count()); const auto t2 = t - h; const auto m = std::chrono::duration_cast(t2); - this->minute = m.count(); + this->minute = static_cast(m.count()); const auto t3 = t2 - m; const auto s = std::chrono::duration_cast(t3); - this->second = s.count(); + this->second = static_cast(s.count()); const auto t4 = t3 - s; const auto ms = std::chrono::duration_cast(t4); - this->millisecond = ms.count(); + this->millisecond = static_cast(ms.count()); const auto t5 = t4 - ms; const auto us = std::chrono::duration_cast(t5); - this->microsecond = us.count(); + this->microsecond = static_cast(us.count()); const auto t6 = t5 - us; const auto ns = std::chrono::duration_cast(t6); - this->nanosecond = ns.count(); + this->nanosecond = static_cast(ns.count()); } operator std::chrono::nanoseconds() const diff --git a/toml/region.hpp b/toml/region.hpp index 1aaa45f..65c6818 100644 --- a/toml/region.hpp +++ b/toml/region.hpp @@ -424,13 +424,14 @@ inline std::string format_underline(const std::string& message, { assert(!reg_com.empty()); - const auto line_num_width = std::max_element(reg_com.begin(), reg_com.end(), + const auto line_num_width = static_cast(std::max_element( + reg_com.begin(), reg_com.end(), [](std::pair const& lhs, std::pair const& rhs) { return lhs.first->line_num().size() < rhs.first->line_num().size(); } - )->first->line_num().size(); + )->first->line_num().size()); std::ostringstream retval; retval << message << '\n'; @@ -453,7 +454,7 @@ inline std::string format_underline(const std::string& message, retval << ' ' << std::setw(line_num_width) << reg->line_num(); retval << " | " << reg->line() << '\n'; - retval << make_string(line_num_width + 1, ' '); + retval << make_string(static_cast(line_num_width + 1), ' '); retval << " | " << make_string(reg->before(), ' '); if(reg->size() == 1) @@ -477,7 +478,7 @@ inline std::string format_underline(const std::string& message, if(!helps.empty()) { retval << '\n'; - retval << make_string(line_num_width + 1, ' '); + retval << make_string(static_cast(line_num_width + 1), ' '); retval << " | "; for(const auto help : helps) { diff --git a/toml/serializer.hpp b/toml/serializer.hpp index 6a508a6..4711236 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -652,7 +652,7 @@ operator<<(std::basic_ostream& os, const basic_value& v) { // get status of std::setw(). const auto w = static_cast(os.width()); - const int fprec = os.precision(); + const int fprec = static_cast(os.precision()); os.width(0); if(!v.comments().empty()) diff --git a/toml/source_location.hpp b/toml/source_location.hpp index 48396a0..051f4e5 100644 --- a/toml/source_location.hpp +++ b/toml/source_location.hpp @@ -48,9 +48,9 @@ struct source_location { if(reg) { - line_num_ = std::stoul(reg->line_num()); - column_num_ = reg->before() + 1; - region_size_ = reg->size(); + line_num_ = static_cast(std::stoul(reg->line_num())); + column_num_ = static_cast(reg->before() + 1); + region_size_ = static_cast(reg->size()); file_name_ = reg->name(); line_str_ = reg->line(); }