diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-10-08 09:16:13 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-10-08 15:41:50 +0200 |
commit | 6832ded200f7a563b9e2cf81148fd26fdb064fdd (patch) | |
tree | 0f7aff13b0ac63dd16b15ff9329dbc2529355aa6 /src | |
parent | db5519c663ad119a47cb7747f80109267c301156 (diff) | |
download | justbuild-6832ded200f7a563b9e2cf81148fd26fdb064fdd.tar.gz |
Name classes, structs and enums using CamelCase.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/common/remote/port.hpp | 4 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp | 8 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp | 18 | ||||
-rw-r--r-- | src/buildtool/execution_engine/dag/dag.hpp | 8 | ||||
-rw-r--r-- | src/buildtool/file_system/file_root.hpp | 72 | ||||
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 2 | ||||
-rw-r--r-- | src/buildtool/file_system/git_repo.hpp | 9 | ||||
-rw-r--r-- | src/utils/automata/dfa_minimizer.hpp | 4 | ||||
-rw-r--r-- | src/utils/cpp/atomic.hpp | 4 | ||||
-rw-r--r-- | src/utils/cpp/expected.hpp | 4 | ||||
-rw-r--r-- | src/utils/cpp/transformed_range.hpp | 46 | ||||
-rw-r--r-- | src/utils/cpp/type_safe_arithmetic.hpp | 94 |
12 files changed, 132 insertions, 141 deletions
diff --git a/src/buildtool/common/remote/port.hpp b/src/buildtool/common/remote/port.hpp index 161d8c3b..01d28e8d 100644 --- a/src/buildtool/common/remote/port.hpp +++ b/src/buildtool/common/remote/port.hpp @@ -27,8 +27,8 @@ #include "src/utils/cpp/type_safe_arithmetic.hpp" // Port -struct PortTag : type_safe_arithmetic_tag<std::uint16_t> {}; -using Port = type_safe_arithmetic<PortTag>; +struct PortTag : TypeSafeArithmeticTag<std::uint16_t> {}; +using Port = TypeSafeArithmetic<PortTag>; [[nodiscard]] static auto ParsePort(int const port_num) noexcept -> std::optional<Port> { diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp index a31939b4..0a8d5638 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp @@ -278,7 +278,7 @@ namespace { } } // namespace -BazelNetworkReader::IncrementalReader::iterator::iterator( +BazelNetworkReader::IncrementalReader::Iterator::Iterator( BazelNetworkReader const& owner, std::vector<bazel_re::Digest>::const_iterator begin, std::vector<bazel_re::Digest>::const_iterator end) noexcept @@ -286,7 +286,7 @@ BazelNetworkReader::IncrementalReader::iterator::iterator( current_ = FindCurrentIterator(begin_, end_); } -auto BazelNetworkReader::IncrementalReader::iterator::operator*() const noexcept +auto BazelNetworkReader::IncrementalReader::Iterator::operator*() const noexcept -> value_type { if (begin_ != current_) { if (std::distance(begin_, current_) > 1) { @@ -300,8 +300,8 @@ auto BazelNetworkReader::IncrementalReader::iterator::operator*() const noexcept return {}; } -auto BazelNetworkReader::IncrementalReader::iterator::operator++() noexcept - -> iterator& { +auto BazelNetworkReader::IncrementalReader::Iterator::operator++() noexcept + -> Iterator& { begin_ = current_; current_ = FindCurrentIterator(begin_, end_); return *this; diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp index e3e283c7..95f64126 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp @@ -106,7 +106,7 @@ class BazelNetworkReader::IncrementalReader final { std::vector<bazel_re::Digest> digests) noexcept : owner_(owner), digests_(std::move(digests)) {} - class iterator final { + class Iterator final { public: using value_type = std::vector<ArtifactBlob>; using pointer = value_type*; @@ -114,22 +114,22 @@ class BazelNetworkReader::IncrementalReader final { using difference_type = std::ptrdiff_t; using iterator_category = std::forward_iterator_tag; - iterator(BazelNetworkReader const& owner, + Iterator(BazelNetworkReader const& owner, std::vector<bazel_re::Digest>::const_iterator begin, std::vector<bazel_re::Digest>::const_iterator end) noexcept; auto operator*() const noexcept -> value_type; - auto operator++() noexcept -> iterator&; + auto operator++() noexcept -> 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 lhs.begin_ == rhs.begin_ and lhs.end_ == rhs.end_ and lhs.current_ == rhs.current_; } - [[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); } @@ -142,11 +142,11 @@ class BazelNetworkReader::IncrementalReader final { }; [[nodiscard]] auto begin() const noexcept { - return iterator{owner_, digests_.begin(), digests_.end()}; + return Iterator{owner_, digests_.begin(), digests_.end()}; } [[nodiscard]] auto end() const noexcept { - return iterator{owner_, digests_.end(), digests_.end()}; + return Iterator{owner_, digests_.end(), digests_.end()}; } private: diff --git a/src/buildtool/execution_engine/dag/dag.hpp b/src/buildtool/execution_engine/dag/dag.hpp index cd75fde4..a479d8b6 100644 --- a/src/buildtool/execution_engine/dag/dag.hpp +++ b/src/buildtool/execution_engine/dag/dag.hpp @@ -178,13 +178,13 @@ class DependencyGraph : DirectedAcyclicGraph { class ArtifactNode; // Node identifier for actions - struct ActionNodeIdentifierTag : type_safe_arithmetic_tag<std::size_t> {}; - using ActionNodeIdentifier = type_safe_arithmetic<ActionNodeIdentifierTag>; + struct ActionNodeIdentifierTag : TypeSafeArithmeticTag<std::size_t> {}; + using ActionNodeIdentifier = TypeSafeArithmetic<ActionNodeIdentifierTag>; // Node identifier for artifacts - struct ArtifactNodeIdentifierTag : type_safe_arithmetic_tag<std::size_t> {}; + struct ArtifactNodeIdentifierTag : TypeSafeArithmeticTag<std::size_t> {}; using ArtifactNodeIdentifier = - type_safe_arithmetic<ArtifactNodeIdentifierTag>; + TypeSafeArithmetic<ArtifactNodeIdentifierTag>; /// \brief Class for traversal state data specific for ActionNode's /// Provides the following atomic operations (listed on the public methods): diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp index fed32177..6b1454ad 100644 --- a/src/buildtool/file_system/file_root.hpp +++ b/src/buildtool/file_system/file_root.hpp @@ -96,13 +96,13 @@ class FilteredIterator { class FileRoot { using fs_root_t = std::filesystem::path; - struct git_root_t { + struct RootGit { gsl::not_null<GitCASPtr> cas; gsl::not_null<GitTreePtr> tree; }; // absent roots are defined by a tree hash with no witnessing repository using absent_root_t = std::string; - using root_t = std::variant<fs_root_t, git_root_t, absent_root_t>; + using root_t = std::variant<fs_root_t, RootGit, absent_root_t>; public: static constexpr auto kGitTreeMarker = "git tree"; @@ -324,7 +324,7 @@ class FileRoot { FileRoot(gsl::not_null<GitCASPtr> const& cas, gsl::not_null<GitTreePtr> const& tree, bool ignore_special = false) noexcept - : root_{git_root_t{cas, tree}}, ignore_special_{ignore_special} {} + : root_{RootGit{cas, tree}}, ignore_special_{ignore_special} {} [[nodiscard]] static auto FromGit(std::filesystem::path const& repo_path, std::string const& git_tree_id, @@ -353,12 +353,12 @@ class FileRoot { [[nodiscard]] auto ContentDescription() const noexcept -> std::optional<nlohmann::json> { try { - if (std::holds_alternative<git_root_t>(root_)) { + if (std::holds_alternative<RootGit>(root_)) { nlohmann::json j; j.push_back(ignore_special_ ? kGitTreeIgnoreSpecialMarker : kGitTreeMarker); // we need the root tree id, irrespective of ignore_special flag - j.push_back(std::get<git_root_t>(root_).tree->FileRootHash()); + j.push_back(std::get<RootGit>(root_).tree->FileRootHash()); return j; } if (std::holds_alternative<absent_root_t>(root_)) { @@ -381,17 +381,17 @@ class FileRoot { // `IsDirectory()`, and `BlobType()` on contents of the same directory will // be served without any additional file system lookups. [[nodiscard]] auto HasFastDirectoryLookup() const noexcept -> bool { - return std::holds_alternative<git_root_t>(root_); + return std::holds_alternative<RootGit>(root_); } [[nodiscard]] auto Exists(std::filesystem::path const& path) const noexcept -> bool { - if (std::holds_alternative<git_root_t>(root_)) { + if (std::holds_alternative<RootGit>(root_)) { if (path == ".") { return true; } return static_cast<bool>( - std::get<git_root_t>(root_).tree->LookupEntryByPath(path)); + std::get<RootGit>(root_).tree->LookupEntryByPath(path)); } if (std::holds_alternative<fs_root_t>(root_)) { auto root_path = std::get<fs_root_t>(root_) / path; @@ -407,10 +407,9 @@ class FileRoot { [[nodiscard]] auto IsFile( std::filesystem::path const& file_path) const noexcept -> bool { - if (std::holds_alternative<git_root_t>(root_)) { - if (auto entry = - std::get<git_root_t>(root_).tree->LookupEntryByPath( - file_path)) { + if (std::holds_alternative<RootGit>(root_)) { + if (auto entry = std::get<RootGit>(root_).tree->LookupEntryByPath( + file_path)) { return IsFileObject(entry->Type()); } } @@ -423,10 +422,9 @@ class FileRoot { [[nodiscard]] auto IsSymlink( std::filesystem::path const& file_path) const noexcept -> bool { - if (std::holds_alternative<git_root_t>(root_)) { - if (auto entry = - std::get<git_root_t>(root_).tree->LookupEntryByPath( - file_path)) { + if (std::holds_alternative<RootGit>(root_)) { + if (auto entry = std::get<RootGit>(root_).tree->LookupEntryByPath( + file_path)) { return IsSymlinkObject(entry->Type()); } } @@ -444,13 +442,12 @@ class FileRoot { [[nodiscard]] auto IsDirectory( std::filesystem::path const& dir_path) const noexcept -> bool { - if (std::holds_alternative<git_root_t>(root_)) { + if (std::holds_alternative<RootGit>(root_)) { if (dir_path == ".") { return true; } - if (auto entry = - std::get<git_root_t>(root_).tree->LookupEntryByPath( - dir_path)) { + if (auto entry = std::get<RootGit>(root_).tree->LookupEntryByPath( + dir_path)) { return entry->IsTree(); } } @@ -464,10 +461,9 @@ class FileRoot { /// \brief Read content of file or symlink. [[nodiscard]] auto ReadContent(std::filesystem::path const& file_path) const noexcept -> std::optional<std::string> { - if (std::holds_alternative<git_root_t>(root_)) { - if (auto entry = - std::get<git_root_t>(root_).tree->LookupEntryByPath( - file_path)) { + if (std::holds_alternative<RootGit>(root_)) { + if (auto entry = std::get<RootGit>(root_).tree->LookupEntryByPath( + file_path)) { if (IsBlobObject(entry->Type())) { return entry->Blob(); } @@ -488,8 +484,8 @@ class FileRoot { [[nodiscard]] auto ReadDirectory(std::filesystem::path const& dir_path) const noexcept -> DirectoryEntries { try { - if (std::holds_alternative<git_root_t>(root_)) { - auto const& tree = std::get<git_root_t>(root_).tree; + if (std::holds_alternative<RootGit>(root_)) { + auto const& tree = std::get<RootGit>(root_).tree; if (dir_path == ".") { return DirectoryEntries{&(*tree)}; } @@ -523,10 +519,9 @@ class FileRoot { [[nodiscard]] auto BlobType(std::filesystem::path const& file_path) const noexcept -> std::optional<ObjectType> { - if (std::holds_alternative<git_root_t>(root_)) { - if (auto entry = - std::get<git_root_t>(root_).tree->LookupEntryByPath( - file_path)) { + if (std::holds_alternative<RootGit>(root_)) { + if (auto entry = std::get<RootGit>(root_).tree->LookupEntryByPath( + file_path)) { if (IsBlobObject(entry->Type())) { return entry->Type(); } @@ -546,9 +541,9 @@ class FileRoot { /// \brief Read a blob from the root based on its ID. [[nodiscard]] auto ReadBlob(std::string const& blob_id) const noexcept -> std::optional<std::string> { - if (std::holds_alternative<git_root_t>(root_)) { - return std::get<git_root_t>(root_).cas->ReadObject( - blob_id, /*is_hex_id=*/true); + if (std::holds_alternative<RootGit>(root_)) { + return std::get<RootGit>(root_).cas->ReadObject(blob_id, + /*is_hex_id=*/true); } return std::nullopt; } @@ -557,9 +552,9 @@ class FileRoot { /// This should include all valid entry types. [[nodiscard]] auto ReadTree(std::string const& tree_id) const noexcept -> std::optional<GitTree> { - if (std::holds_alternative<git_root_t>(root_)) { + if (std::holds_alternative<RootGit>(root_)) { try { - auto const& cas = std::get<git_root_t>(root_).cas; + auto const& cas = std::get<RootGit>(root_).cas; return GitTree::Read(cas, tree_id); } catch (...) { return std::nullopt; @@ -575,10 +570,9 @@ class FileRoot { std::filesystem::path const& file_path, std::string const& repository) const noexcept -> std::optional<ArtifactDescription> { - if (std::holds_alternative<git_root_t>(root_)) { - if (auto entry = - std::get<git_root_t>(root_).tree->LookupEntryByPath( - file_path)) { + if (std::holds_alternative<RootGit>(root_)) { + if (auto entry = std::get<RootGit>(root_).tree->LookupEntryByPath( + file_path)) { if (entry->IsBlob()) { if (not ProtocolTraits::IsNative(hash_type)) { auto compatible_hash = diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index 4d5dfcb9..800da4b8 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -1841,7 +1841,7 @@ auto GitRepo::ReadTree(std::string const& id, for (auto const& entry : entries) { if (std::any_of(entry.second.begin(), entry.second.end(), - [](tree_entry_t const& item) { + [](TreeEntry const& item) { return IsSymlinkObject(item.type); })) { auto digest = ArtifactDigestFactory::Create( diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index 0127c604..df100b35 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -44,12 +44,11 @@ class GitRepo { public: // Stores the data for defining a single Git tree entry, which consists of // a name (flat basename) and an object type (file/executable/tree). - struct tree_entry_t { - tree_entry_t(std::string n, ObjectType t) - : name{std::move(n)}, type{t} {} + struct TreeEntry { + TreeEntry(std::string n, ObjectType t) : name{std::move(n)}, type{t} {} std::string name; ObjectType type; - [[nodiscard]] auto operator==(tree_entry_t const& other) const noexcept + [[nodiscard]] auto operator==(TreeEntry const& other) const noexcept -> bool { return name == other.name and type == other.type; } @@ -59,7 +58,7 @@ class GitRepo { // Note that sharding by id is used as this format enables a more efficient // internal implementation for creating trees. using tree_entries_t = - std::unordered_map<std::string, std::vector<tree_entry_t>>; + std::unordered_map<std::string, std::vector<TreeEntry>>; // Stores the info of an object read by its path. struct TreeEntryInfo { 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<StatePairKey, StatePairValue, StatePairKey::hash_t>; + std::unordered_map<StatePairKey, StatePairValue, StatePairKey::Hash>; public: using bisimulation_t = std::unordered_map<std::string, std::string>; 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 T> -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<std::shared_ptr<T>>, once libcxx adds support for it. // [https://libcxx.llvm.org/docs/Cxx2aStatus.html] template <class T> -class atomic_shared_ptr { +class atomic_shared_ptr { // NOLINT(readability-identifier-naming) using ptr_t = std::shared_ptr<T>; 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 E> -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 T, class E> -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 <typename Iterator, typename Result> +template <typename TIterator, typename Result> class TransformedRange final { public: using converter_t = - std::function<Result(typename Iterator::value_type const&)>; + std::function<Result(typename TIterator::value_type const&)>; - class iterator final { + class Iterator final { public: using value_type = std::remove_reference_t<Result>; 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 <typename Iterator, +template <typename TIterator, typename Function, - typename IteratorValue = typename Iterator::value_type> -TransformedRange(Iterator, Iterator, Function) - -> TransformedRange<Iterator, + typename IteratorValue = typename TIterator::value_type> +TransformedRange(TIterator, TIterator, Function) + -> TransformedRange<TIterator, std::invoke_result_t<Function, IteratorValue>>; #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<int, -2, +3> {}; -/// using my_type_t = type_safe_arithmetic<my_type_tag>; +/// struct my_type_tag : TypeSafeArithmeticTag<int, -2, +3> {}; +/// using my_type_t = TypeSafeArithmetic<my_type_tag>; template <typename T, T MIN_VALUE = std::numeric_limits<T>::lowest(), T MAX_VALUE = std::numeric_limits<T>::max(), T SMALLEST_VALUE = std::numeric_limits<T>::min()> -struct type_safe_arithmetic_tag { +struct TypeSafeArithmeticTag { static_assert(std::is_arithmetic_v<T>, "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 <typename TAG> -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 <typename TAG> -// bool operator==(type_safe_arithmetic<TAG> lhs, type_safe_arithmetic<TAG> rhs) +// bool operator==(TypeSafeArithmetic<TAG> lhs, TypeSafeArithmetic<TAG> rhs) // { // return lhs.get() == rhs.get(); // } // // template <typename TAG> -// bool operator!=(type_safe_arithmetic<TAG> lhs, type_safe_arithmetic<TAG> rhs) +// bool operator!=(TypeSafeArithmetic<TAG> lhs, TypeSafeArithmetic<TAG> rhs) // { // return !(lhs == rhs); // } // // template <typename TAG> -// bool operator>(type_safe_arithmetic<TAG> lhs, type_safe_arithmetic<TAG> rhs) +// bool operator>(TypeSafeArithmetic<TAG> lhs, TypeSafeArithmetic<TAG> rhs) // { // return lhs.get() > rhs.get(); // } // // template <typename TAG> -// bool operator>=(type_safe_arithmetic<TAG> lhs, type_safe_arithmetic<TAG> rhs) +// bool operator>=(TypeSafeArithmetic<TAG> lhs, TypeSafeArithmetic<TAG> rhs) // { // return lhs.get() >= rhs.get(); // } // // template <typename TAG> -// bool operator<(type_safe_arithmetic<TAG> lhs, type_safe_arithmetic<TAG> rhs) +// bool operator<(TypeSafeArithmetic<TAG> lhs, TypeSafeArithmetic<TAG> rhs) // { // return lhs.get() < rhs.get(); // } // // template <typename TAG> -// bool operator<=(type_safe_arithmetic<TAG> lhs, type_safe_arithmetic<TAG> rhs) +// bool operator<=(TypeSafeArithmetic<TAG> lhs, TypeSafeArithmetic<TAG> rhs) // { // return lhs.get() <= rhs.get(); // } // // template <typename TAG> -// type_safe_arithmetic<TAG> operator+(type_safe_arithmetic<TAG> lhs, -// type_safe_arithmetic<TAG> rhs) { -// return type_safe_arithmetic<TAG>{lhs.get() + rhs.get()}; +// TypeSafeArithmetic<TAG> operator+(TypeSafeArithmetic<TAG> lhs, +// TypeSafeArithmetic<TAG> rhs) { +// return TypeSafeArithmetic<TAG>{lhs.get() + rhs.get()}; // } template <typename TAG> -auto operator+=(type_safe_arithmetic<TAG>& lhs, - type_safe_arithmetic<TAG> rhs) -> type_safe_arithmetic<TAG>& { +auto operator+=(TypeSafeArithmetic<TAG>& lhs, + TypeSafeArithmetic<TAG> rhs) -> TypeSafeArithmetic<TAG>& { lhs.set(lhs.get() + rhs.get()); return lhs; } // template <typename TAG> -// type_safe_arithmetic<TAG> operator-(type_safe_arithmetic<TAG> lhs, -// type_safe_arithmetic<TAG> rhs) { -// return type_safe_arithmetic<TAG>{lhs.get() - rhs.get()}; +// TypeSafeArithmetic<TAG> operator-(TypeSafeArithmetic<TAG> lhs, +// TypeSafeArithmetic<TAG> rhs) { +// return TypeSafeArithmetic<TAG>{lhs.get() - rhs.get()}; // } // // template <typename TAG> -// type_safe_arithmetic<TAG>& operator-=(type_safe_arithmetic<TAG>& lhs, -// type_safe_arithmetic<TAG> rhs) { +// TypeSafeArithmetic<TAG>& operator-=(TypeSafeArithmetic<TAG>& lhs, +// TypeSafeArithmetic<TAG> rhs) { // lhs.set(lhs.get() - rhs.get()); // return lhs; // } // // template <typename TAG> -// type_safe_arithmetic<TAG> operator*(type_safe_arithmetic<TAG> lhs, +// TypeSafeArithmetic<TAG> operator*(TypeSafeArithmetic<TAG> lhs, // typename TAG::value_t rhs) { -// return type_safe_arithmetic<TAG>{lhs.get() - rhs}; +// return TypeSafeArithmetic<TAG>{lhs.get() - rhs}; // } // // template <typename TAG> -// type_safe_arithmetic<TAG>& operator*=(type_safe_arithmetic<TAG>& lhs, +// TypeSafeArithmetic<TAG>& operator*=(TypeSafeArithmetic<TAG>& lhs, // typename TAG::value_t rhs) { // lhs.set(lhs.get() * rhs); // return lhs; // } // // template <typename TAG> -// type_safe_arithmetic<TAG> operator/(type_safe_arithmetic<TAG> lhs, +// TypeSafeArithmetic<TAG> operator/(TypeSafeArithmetic<TAG> lhs, // typename TAG::value_t rhs) { -// return type_safe_arithmetic<TAG>{lhs.get() / rhs}; +// return TypeSafeArithmetic<TAG>{lhs.get() / rhs}; // } // // template <typename TAG> -// type_safe_arithmetic<TAG>& operator/=(type_safe_arithmetic<TAG>& lhs, +// TypeSafeArithmetic<TAG>& operator/=(TypeSafeArithmetic<TAG>& lhs, // typename TAG::value_t rhs) { // lhs.set(lhs.get() / rhs); // return lhs; // } // // template <typename TAG> -// type_safe_arithmetic<TAG>& operator++(type_safe_arithmetic<TAG>& a) { -// return a += type_safe_arithmetic<TAG>{1}; +// TypeSafeArithmetic<TAG>& operator++(TypeSafeArithmetic<TAG>& a) { +// return a += TypeSafeArithmetic<TAG>{1}; // } template <typename TAG> -auto operator++(type_safe_arithmetic<TAG>& a, - int) -> type_safe_arithmetic<TAG> { +auto operator++(TypeSafeArithmetic<TAG>& a, int) -> TypeSafeArithmetic<TAG> { auto r = a; - a += type_safe_arithmetic<TAG>{1}; + a += TypeSafeArithmetic<TAG>{1}; return r; } // template <typename TAG> -// type_safe_arithmetic<TAG>& operator--(type_safe_arithmetic<TAG>& a) { -// return a -= type_safe_arithmetic<TAG>{1}; +// TypeSafeArithmetic<TAG>& operator--(TypeSafeArithmetic<TAG>& a) { +// return a -= TypeSafeArithmetic<TAG>{1}; // } // // template <typename TAG> -// type_safe_arithmetic<TAG> operator--(type_safe_arithmetic<TAG>& a, int) { +// TypeSafeArithmetic<TAG> operator--(TypeSafeArithmetic<TAG>& a, int) { // auto r = a; -// a += type_safe_arithmetic<TAG>{1}; +// a += TypeSafeArithmetic<TAG>{1}; // return r; // } |