From 6832ded200f7a563b9e2cf81148fd26fdb064fdd Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Tue, 8 Oct 2024 09:16:13 +0200 Subject: Name classes, structs and enums using CamelCase. --- src/utils/automata/dfa_minimizer.hpp | 4 +- src/utils/cpp/atomic.hpp | 4 +- src/utils/cpp/expected.hpp | 4 +- src/utils/cpp/transformed_range.hpp | 46 ++++++++--------- src/utils/cpp/type_safe_arithmetic.hpp | 94 +++++++++++++++++----------------- 5 files changed, 75 insertions(+), 77 deletions(-) (limited to 'src/utils') diff --git a/src/utils/automata/dfa_minimizer.hpp b/src/utils/automata/dfa_minimizer.hpp index d536bd8b..69bc0b52 100644 --- a/src/utils/automata/dfa_minimizer.hpp +++ b/src/utils/automata/dfa_minimizer.hpp @@ -51,7 +51,7 @@ class DFAMinimizer { // Key used for state pairs. Reordering names will result in the same key. class StatePairKey { public: - struct hash_t { + struct Hash { [[nodiscard]] auto operator()(StatePairKey const& p) const -> std::size_t { std::size_t hash{}; @@ -91,7 +91,7 @@ class DFAMinimizer { }; using state_pairs_t = - std::unordered_map; + std::unordered_map; public: using bisimulation_t = std::unordered_map; diff --git a/src/utils/cpp/atomic.hpp b/src/utils/cpp/atomic.hpp index ec1c7dc0..94bda75f 100644 --- a/src/utils/cpp/atomic.hpp +++ b/src/utils/cpp/atomic.hpp @@ -26,7 +26,7 @@ // libcxx adds support for notify_*() and wait(). // [https://libcxx.llvm.org/docs/Cxx2aStatus.html] template -class atomic { +class atomic { // NOLINT(readability-identifier-naming) public: atomic() = default; explicit atomic(T value) : value_{std::move(value)} {} @@ -97,7 +97,7 @@ class atomic { // std::atomic>, once libcxx adds support for it. // [https://libcxx.llvm.org/docs/Cxx2aStatus.html] template -class atomic_shared_ptr { +class atomic_shared_ptr { // NOLINT(readability-identifier-naming) using ptr_t = std::shared_ptr; public: diff --git a/src/utils/cpp/expected.hpp b/src/utils/cpp/expected.hpp index 823c4650..da3955b7 100644 --- a/src/utils/cpp/expected.hpp +++ b/src/utils/cpp/expected.hpp @@ -20,7 +20,7 @@ // TODO(modernize): replace this by std::unexpected once we switched to C++23 template -class unexpected { +class unexpected { // NOLINT(readability-identifier-naming) public: explicit unexpected(E error) : error_{std::move(error)} {} [[nodiscard]] auto error() && -> E { return std::move(error_); } @@ -31,7 +31,7 @@ class unexpected { // TODO(modernize): replace this by std::expected once we switched to C++23 template -class expected { +class expected { // NOLINT(readability-identifier-naming) public: expected(T value) noexcept // NOLINT : value_{std::in_place_index<0>, std::move(value)} {} diff --git a/src/utils/cpp/transformed_range.hpp b/src/utils/cpp/transformed_range.hpp index f28029f3..cc3fe5d6 100644 --- a/src/utils/cpp/transformed_range.hpp +++ b/src/utils/cpp/transformed_range.hpp @@ -30,16 +30,16 @@ /// \brief Transform iterable sequence "on the fly" invoking the given /// transformation callback. If the callback throws an exception, /// std::terminate is called. -/// \tparam Iterator Type of the iterator of the sequence to be +/// \tparam TIterator Type of the iterator of the sequence to be /// transformed. /// \tparam Result Type of the transformation result. -template +template class TransformedRange final { public: using converter_t = - std::function; + std::function; - class iterator final { + class Iterator final { public: using value_type = std::remove_reference_t; using pointer = value_type*; @@ -47,9 +47,9 @@ class TransformedRange final { using difference_type = std::ptrdiff_t; using iterator_category = std::forward_iterator_tag; - iterator() noexcept = default; - iterator(Iterator iterator, converter_t c) noexcept - : iterator_(std::move(iterator)), c_(std::move(c)) {} + Iterator() noexcept = default; + Iterator(TIterator Iterator, converter_t c) noexcept + : iterator_(std::move(Iterator)), c_(std::move(c)) {} auto operator*() const noexcept -> decltype(auto) { try { @@ -59,35 +59,35 @@ class TransformedRange final { } } - auto operator++() noexcept -> iterator& { + auto operator++() noexcept -> Iterator& { ++iterator_; return *this; } - [[nodiscard]] friend auto operator==(iterator const& lhs, - iterator const& rhs) noexcept + [[nodiscard]] friend auto operator==(Iterator const& lhs, + Iterator const& rhs) noexcept -> bool { return lhs.iterator_ == rhs.iterator_; } - [[nodiscard]] friend auto operator!=(iterator const& lhs, - iterator const& rhs) noexcept + [[nodiscard]] friend auto operator!=(Iterator const& lhs, + Iterator const& rhs) noexcept -> bool { return not(lhs == rhs); } private: - Iterator iterator_{}; + TIterator iterator_{}; converter_t c_{}; }; - TransformedRange(Iterator begin, Iterator end, converter_t c) noexcept + TransformedRange(TIterator begin, TIterator end, converter_t c) noexcept : begin_{std::move(begin), std::move(c)}, end_{std::move(end), nullptr} {} - [[nodiscard]] auto begin() const noexcept -> iterator { return begin_; } - [[nodiscard]] auto end() const noexcept -> iterator { return end_; } - [[nodiscard]] auto size() const -> typename iterator::difference_type { + [[nodiscard]] auto begin() const noexcept -> Iterator { return begin_; } + [[nodiscard]] auto end() const noexcept -> Iterator { return end_; } + [[nodiscard]] auto size() const -> typename Iterator::difference_type { return std::distance(begin_, end_); } @@ -101,17 +101,17 @@ class TransformedRange final { } private: - iterator const begin_; - iterator const end_; + Iterator const begin_; + Iterator const end_; }; // User-defined deduction guide to help compiler dealing with generic lambdas // and invokable objects. -template -TransformedRange(Iterator, Iterator, Function) - -> TransformedRange +TransformedRange(TIterator, TIterator, Function) + -> TransformedRange>; #endif // INCLUDED_SRC_OTHER_TOOLS_TRANSFORMED_RANGE_HPP diff --git a/src/utils/cpp/type_safe_arithmetic.hpp b/src/utils/cpp/type_safe_arithmetic.hpp index 690e9a86..52efd81c 100644 --- a/src/utils/cpp/type_safe_arithmetic.hpp +++ b/src/utils/cpp/type_safe_arithmetic.hpp @@ -20,16 +20,16 @@ #include "gsl/gsl" -/// \struct type_safe_arithmetic_tag +/// \struct TypeSafeArithmeticTag /// \brief Abstract tag defining types and limits for custom arithmetic types. /// Usage example: -/// struct my_type_tag : type_safe_arithmetic_tag {}; -/// using my_type_t = type_safe_arithmetic; +/// struct my_type_tag : TypeSafeArithmeticTag {}; +/// using my_type_t = TypeSafeArithmetic; template ::lowest(), T MAX_VALUE = std::numeric_limits::max(), T SMALLEST_VALUE = std::numeric_limits::min()> -struct type_safe_arithmetic_tag { +struct TypeSafeArithmeticTag { static_assert(std::is_arithmetic_v, "T must be an arithmetic type (integer or floating-point)"); @@ -44,11 +44,11 @@ struct type_safe_arithmetic_tag { static constexpr value_t smallest_value = SMALLEST_VALUE; }; -/// \class type_safe_arithmetic +/// \class TypeSafeArithmetic /// \brief Abstract class for defining custom arithmetic types. -/// \tparam TAG The actual \ref type_safe_arithmetic_tag +/// \tparam TAG The actual \ref TypeSafeArithmeticTag template -class type_safe_arithmetic { +class TypeSafeArithmetic { typename TAG::value_t m_value{}; public: @@ -63,20 +63,19 @@ class type_safe_arithmetic { static constexpr value_t min_value = tag_t::min_value; static constexpr value_t smallest_value = tag_t::smallest_value; - constexpr type_safe_arithmetic() = default; + constexpr TypeSafeArithmetic() = default; // NOLINTNEXTLINE - constexpr /*explicit*/ type_safe_arithmetic(value_t value) { set(value); } + constexpr /*explicit*/ TypeSafeArithmetic(value_t value) { set(value); } - type_safe_arithmetic(type_safe_arithmetic const&) = default; - type_safe_arithmetic(type_safe_arithmetic&&) noexcept = default; - auto operator=(type_safe_arithmetic const&) -> type_safe_arithmetic& = - default; - auto operator=(type_safe_arithmetic&&) noexcept -> type_safe_arithmetic& = - default; - ~type_safe_arithmetic() = default; + TypeSafeArithmetic(TypeSafeArithmetic const&) = default; + TypeSafeArithmetic(TypeSafeArithmetic&&) noexcept = default; + auto operator=(TypeSafeArithmetic const&) -> TypeSafeArithmetic& = default; + auto operator=(TypeSafeArithmetic&&) noexcept -> TypeSafeArithmetic& = + default; + ~TypeSafeArithmetic() = default; - auto operator=(value_t value) -> type_safe_arithmetic& { + auto operator=(value_t value) -> TypeSafeArithmetic& { set(value); return *this; } @@ -96,115 +95,114 @@ class type_safe_arithmetic { }; // template -// bool operator==(type_safe_arithmetic lhs, type_safe_arithmetic rhs) +// bool operator==(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) // { // return lhs.get() == rhs.get(); // } // // template -// bool operator!=(type_safe_arithmetic lhs, type_safe_arithmetic rhs) +// bool operator!=(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) // { // return !(lhs == rhs); // } // // template -// bool operator>(type_safe_arithmetic lhs, type_safe_arithmetic rhs) +// bool operator>(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) // { // return lhs.get() > rhs.get(); // } // // template -// bool operator>=(type_safe_arithmetic lhs, type_safe_arithmetic rhs) +// bool operator>=(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) // { // return lhs.get() >= rhs.get(); // } // // template -// bool operator<(type_safe_arithmetic lhs, type_safe_arithmetic rhs) +// bool operator<(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) // { // return lhs.get() < rhs.get(); // } // // template -// bool operator<=(type_safe_arithmetic lhs, type_safe_arithmetic rhs) +// bool operator<=(TypeSafeArithmetic lhs, TypeSafeArithmetic rhs) // { // return lhs.get() <= rhs.get(); // } // // template -// type_safe_arithmetic operator+(type_safe_arithmetic lhs, -// type_safe_arithmetic rhs) { -// return type_safe_arithmetic{lhs.get() + rhs.get()}; +// TypeSafeArithmetic operator+(TypeSafeArithmetic lhs, +// TypeSafeArithmetic rhs) { +// return TypeSafeArithmetic{lhs.get() + rhs.get()}; // } template -auto operator+=(type_safe_arithmetic& lhs, - type_safe_arithmetic rhs) -> type_safe_arithmetic& { +auto operator+=(TypeSafeArithmetic& lhs, + TypeSafeArithmetic rhs) -> TypeSafeArithmetic& { lhs.set(lhs.get() + rhs.get()); return lhs; } // template -// type_safe_arithmetic operator-(type_safe_arithmetic lhs, -// type_safe_arithmetic rhs) { -// return type_safe_arithmetic{lhs.get() - rhs.get()}; +// TypeSafeArithmetic operator-(TypeSafeArithmetic lhs, +// TypeSafeArithmetic rhs) { +// return TypeSafeArithmetic{lhs.get() - rhs.get()}; // } // // template -// type_safe_arithmetic& operator-=(type_safe_arithmetic& lhs, -// type_safe_arithmetic rhs) { +// TypeSafeArithmetic& operator-=(TypeSafeArithmetic& lhs, +// TypeSafeArithmetic rhs) { // lhs.set(lhs.get() - rhs.get()); // return lhs; // } // // template -// type_safe_arithmetic operator*(type_safe_arithmetic lhs, +// TypeSafeArithmetic operator*(TypeSafeArithmetic lhs, // typename TAG::value_t rhs) { -// return type_safe_arithmetic{lhs.get() - rhs}; +// return TypeSafeArithmetic{lhs.get() - rhs}; // } // // template -// type_safe_arithmetic& operator*=(type_safe_arithmetic& lhs, +// TypeSafeArithmetic& operator*=(TypeSafeArithmetic& lhs, // typename TAG::value_t rhs) { // lhs.set(lhs.get() * rhs); // return lhs; // } // // template -// type_safe_arithmetic operator/(type_safe_arithmetic lhs, +// TypeSafeArithmetic operator/(TypeSafeArithmetic lhs, // typename TAG::value_t rhs) { -// return type_safe_arithmetic{lhs.get() / rhs}; +// return TypeSafeArithmetic{lhs.get() / rhs}; // } // // template -// type_safe_arithmetic& operator/=(type_safe_arithmetic& lhs, +// TypeSafeArithmetic& operator/=(TypeSafeArithmetic& lhs, // typename TAG::value_t rhs) { // lhs.set(lhs.get() / rhs); // return lhs; // } // // template -// type_safe_arithmetic& operator++(type_safe_arithmetic& a) { -// return a += type_safe_arithmetic{1}; +// TypeSafeArithmetic& operator++(TypeSafeArithmetic& a) { +// return a += TypeSafeArithmetic{1}; // } template -auto operator++(type_safe_arithmetic& a, - int) -> type_safe_arithmetic { +auto operator++(TypeSafeArithmetic& a, int) -> TypeSafeArithmetic { auto r = a; - a += type_safe_arithmetic{1}; + a += TypeSafeArithmetic{1}; return r; } // template -// type_safe_arithmetic& operator--(type_safe_arithmetic& a) { -// return a -= type_safe_arithmetic{1}; +// TypeSafeArithmetic& operator--(TypeSafeArithmetic& a) { +// return a -= TypeSafeArithmetic{1}; // } // // template -// type_safe_arithmetic operator--(type_safe_arithmetic& a, int) { +// TypeSafeArithmetic operator--(TypeSafeArithmetic& a, int) { // auto r = a; -// a += type_safe_arithmetic{1}; +// a += TypeSafeArithmetic{1}; // return r; // } -- cgit v1.2.3