diff options
author | hop311 <hop3114@gmail.com> | 2024-07-19 20:02:25 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-07-19 20:02:25 +0200 |
commit | 03647d2249f72b6545628bb844685f87c4581062 (patch) | |
tree | 435dde45bb17dc12e74cc79bd5f25cc7a7ef8dca /src/openvic-simulation/utility | |
parent | a673f89bb2705826b1c646365eab1775727372b7 (diff) |
Cleanup: inheritance, const movable variables, code formattingformat-cleanup
Diffstat (limited to 'src/openvic-simulation/utility')
-rw-r--r-- | src/openvic-simulation/utility/Getters.hpp | 12 | ||||
-rw-r--r-- | src/openvic-simulation/utility/StringUtils.hpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/utility/TslHelper.hpp | 18 | ||||
-rw-r--r-- | src/openvic-simulation/utility/Utility.hpp | 12 |
4 files changed, 24 insertions, 22 deletions
diff --git a/src/openvic-simulation/utility/Getters.hpp b/src/openvic-simulation/utility/Getters.hpp index 5d06a8d..c4114eb 100644 --- a/src/openvic-simulation/utility/Getters.hpp +++ b/src/openvic-simulation/utility/Getters.hpp @@ -99,14 +99,16 @@ namespace OpenVic::utility { } \ template<typename T> \ constexpr T* cast_to() { \ - if (is_derived_from<T>() || is_type<CLASS>()) \ + if (is_derived_from<T>() || is_type<CLASS>()) { \ return (static_cast<T*>(this)); \ + } \ return nullptr; \ } \ template<typename T> \ - constexpr const T* const cast_to() const { \ - if (is_derived_from<T>() || is_type<CLASS>()) \ - return (static_cast<const T*>(this)); \ + constexpr T const* const cast_to() const { \ + if (is_derived_from<T>() || is_type<CLASS>()) { \ + return (static_cast<T const*>(this)); \ + } \ return nullptr; \ } @@ -160,7 +162,7 @@ namespace OpenVic { * for variable getters created using the PROPERTY macro. */ template<typename decl, typename T> - inline constexpr decltype(auto) _get_property(const T& property) { + inline constexpr decltype(auto) _get_property(T const& property) { if constexpr (std::is_reference_v<decl>) { /* Return const reference */ return property; diff --git a/src/openvic-simulation/utility/StringUtils.hpp b/src/openvic-simulation/utility/StringUtils.hpp index 0df2952..bec11ec 100644 --- a/src/openvic-simulation/utility/StringUtils.hpp +++ b/src/openvic-simulation/utility/StringUtils.hpp @@ -18,7 +18,7 @@ namespace OpenVic::StringUtils { * still starts with "0", otherwise 10. The success bool pointer parameter is used to report whether * or not conversion was successful. It can be nullptr if this information is not needed. */ - constexpr uint64_t string_to_uint64(char const* str, const char* const end, bool* successful = nullptr, int base = 10) { + constexpr uint64_t string_to_uint64(char const* str, char const* const end, bool* successful = nullptr, int base = 10) { if (successful != nullptr) { *successful = false; } @@ -105,7 +105,7 @@ namespace OpenVic::StringUtils { return string_to_uint64(str.data(), str.length(), successful, base); } - constexpr int64_t string_to_int64(char const* str, const char* const end, bool* successful = nullptr, int base = 10) { + constexpr int64_t string_to_int64(char const* str, char const* const end, bool* successful = nullptr, int base = 10) { if (successful != nullptr) { *successful = false; } diff --git a/src/openvic-simulation/utility/TslHelper.hpp b/src/openvic-simulation/utility/TslHelper.hpp index 9d1ae77..a8bd0bd 100644 --- a/src/openvic-simulation/utility/TslHelper.hpp +++ b/src/openvic-simulation/utility/TslHelper.hpp @@ -70,39 +70,39 @@ namespace OpenVic { return tmp; } - bool operator==(const ordered_iterator& rhs) const { + bool operator==(ordered_iterator const& rhs) const { return m_iterator == rhs.m_iterator; } - bool operator!=(const ordered_iterator& rhs) const { + bool operator!=(ordered_iterator const& rhs) const { return m_iterator != rhs.m_iterator; } - bool operator<(const ordered_iterator& rhs) const { + bool operator<(ordered_iterator const& rhs) const { return m_iterator < rhs.m_iterator; } - bool operator>(const ordered_iterator& rhs) const { + bool operator>(ordered_iterator const& rhs) const { return m_iterator > rhs.m_iterator; } - bool operator<=(const ordered_iterator& rhs) const { + bool operator<=(ordered_iterator const& rhs) const { return m_iterator <= rhs.m_iterator; } - bool operator>=(const ordered_iterator& rhs) const { + bool operator>=(ordered_iterator const& rhs) const { return m_iterator >= rhs.m_iterator; } - friend ordered_iterator operator+(difference_type n, const ordered_iterator& it) { + friend ordered_iterator operator+(difference_type n, ordered_iterator const& it) { return n + it.m_iterator; } - ordered_iterator operator+(const ordered_iterator& rhs) const { + ordered_iterator operator+(ordered_iterator const& rhs) const { return m_iterator + rhs.m_iterator; } - difference_type operator-(const ordered_iterator& rhs) const { + difference_type operator-(ordered_iterator const& rhs) const { return m_iterator - rhs.m_iterator; } diff --git a/src/openvic-simulation/utility/Utility.hpp b/src/openvic-simulation/utility/Utility.hpp index 8180e55..1542d45 100644 --- a/src/openvic-simulation/utility/Utility.hpp +++ b/src/openvic-simulation/utility/Utility.hpp @@ -32,13 +32,13 @@ namespace OpenVic::utility { } template<class T> - inline constexpr void hash_combine(std::size_t& s, const T& v) { + inline constexpr void hash_combine(std::size_t& s, T const& v) { std::hash<T> h; s ^= h(v) + 0x9e3779b9 + (s << 6) + (s >> 2); } template<size_t Shift, class T> - inline constexpr void hash_combine_index(std::size_t& s, const T& v) { + inline constexpr void hash_combine_index(std::size_t& s, T const& v) { std::hash<T> h; if constexpr (Shift == 0) { s = h(v); @@ -61,8 +61,8 @@ namespace OpenVic::utility { ( [&] { // If args is not last pointer of args - if (static_cast<const void*>(&(std::get<sizeof...(args) - 1>(arg_tuple))) != - static_cast<const void*>(&args)) { + if (static_cast<void const*>(&(std::get<sizeof...(args) - 1>(arg_tuple))) != + static_cast<void const*>(&args)) { s <<= sizeof(Args) * CHAR_BIT; } s |= std::hash<Args> {}(args); @@ -82,10 +82,10 @@ namespace OpenVic::utility { inline constexpr bool is_specialization_of_v = is_specialization_of<T, Z>::value; template <template<typename...> class Template, typename... Args> - void _derived_from_specialization_impl(const Template<Args...>&); + void _derived_from_specialization_impl(Template<Args...> const&); template <typename T, template<typename...> class Template> - concept is_derived_from_specialization_of = requires(const T& t) { + concept is_derived_from_specialization_of = requires(T const& t) { _derived_from_specialization_impl<Template>(t); }; |