diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index 9aa5e212c..8599dbd8e 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -100,8 +100,9 @@ public: bool equal(base_type const& impl) const override { - auto const& other = dynamic_cast(impl); - return iter_ == other.iter_; + if (auto const p = dynamic_cast(&impl)) + return iter_ == p->iter_; + return false; } void @@ -148,8 +149,9 @@ public: bool equal(base_type const& impl) const override { - auto const& other = dynamic_cast(impl); - return iter_ == other.iter_; + if (auto const p = dynamic_cast(&impl)) + return iter_ == p->iter_; + return false; } void diff --git a/src/ripple/ledger/detail/ReadViewFwdRange.h b/src/ripple/ledger/detail/ReadViewFwdRange.h index af00944cf..c37eab214 100644 --- a/src/ripple/ledger/detail/ReadViewFwdRange.h +++ b/src/ripple/ledger/detail/ReadViewFwdRange.h @@ -126,7 +126,7 @@ public: private: ReadView const* view_ = nullptr; std::unique_ptr impl_; - boost::optional mutable cache_; + std::optional mutable cache_; }; static_assert(std::is_nothrow_move_constructible{}, ""); diff --git a/src/ripple/ledger/detail/ReadViewFwdRange.ipp b/src/ripple/ledger/detail/ReadViewFwdRange.ipp index 7fc1bb3da..ae84259d7 100644 --- a/src/ripple/ledger/detail/ReadViewFwdRange.ipp +++ b/src/ripple/ledger/detail/ReadViewFwdRange.ipp @@ -52,11 +52,12 @@ auto ReadViewFwdRange::iterator::operator=(iterator const& other) -> iterator& { - if (this == &other) - return *this; - view_ = other.view_; - impl_ = other.impl_ ? other.impl_->copy() : nullptr; - cache_ = other.cache_; + if (this != &other) + { + view_ = other.view_; + impl_ = other.impl_ ? other.impl_->copy() : nullptr; + cache_ = other.cache_; + } return *this; } @@ -65,9 +66,13 @@ auto ReadViewFwdRange::iterator::operator=(iterator&& other) noexcept -> iterator& { - view_ = other.view_; - impl_ = std::move(other.impl_); - cache_ = std::move(other.cache_); + if (this != &other) + { + view_ = other.view_; + impl_ = std::move(other.impl_); + cache_ = std::move(other.cache_); + } + return *this; } @@ -76,7 +81,11 @@ bool ReadViewFwdRange::iterator::operator==(iterator const& other) const { assert(view_ == other.view_); - return impl_->equal(*other.impl_); + + if (impl_ != nullptr && other.impl_ != nullptr) + return impl_->equal(*other.impl_); + + return impl_ == other.impl_; } template @@ -107,7 +116,7 @@ auto ReadViewFwdRange::iterator::operator++() -> iterator& { impl_->increment(); - cache_ = boost::none; + cache_.reset(); return *this; } diff --git a/src/ripple/ledger/impl/OpenView.cpp b/src/ripple/ledger/impl/OpenView.cpp index 45e2698ae..f352f9352 100644 --- a/src/ripple/ledger/impl/OpenView.cpp +++ b/src/ripple/ledger/impl/OpenView.cpp @@ -45,8 +45,9 @@ public: bool equal(base_type const& impl) const override { - auto const& other = dynamic_cast(impl); - return iter_ == other.iter_; + if (auto const p = dynamic_cast(&impl)) + return iter_ == p->iter_; + return false; } void diff --git a/src/ripple/ledger/impl/RawStateTable.cpp b/src/ripple/ledger/impl/RawStateTable.cpp index a563606ac..ff01b68eb 100644 --- a/src/ripple/ledger/impl/RawStateTable.cpp +++ b/src/ripple/ledger/impl/RawStateTable.cpp @@ -61,9 +61,13 @@ public: bool equal(base_type const& impl) const override { - auto const& other = dynamic_cast(impl); - assert(end1_ == other.end1_ && end0_ == other.end0_); - return iter1_ == other.iter1_ && iter0_ == other.iter0_; + if (auto const p = dynamic_cast(&impl)) + { + assert(end1_ == p->end1_ && end0_ == p->end0_); + return iter1_ == p->iter1_ && iter0_ == p->iter0_; + } + + return false; } void diff --git a/src/ripple/shamap/SHAMap.h b/src/ripple/shamap/SHAMap.h index f2974001f..0cc919b17 100644 --- a/src/ripple/shamap/SHAMap.h +++ b/src/ripple/shamap/SHAMap.h @@ -564,7 +564,13 @@ private: pointer item_ = nullptr; public: - const_iterator() = default; + const_iterator() = delete; + + const_iterator(const_iterator const& other) = default; + const_iterator& + operator=(const_iterator const& other) = default; + + ~const_iterator() = default; reference operator*() const; @@ -578,7 +584,7 @@ public: private: explicit const_iterator(SHAMap const* map); - const_iterator(SHAMap const* map, pointer item); + const_iterator(SHAMap const* map, std::nullptr_t); const_iterator(SHAMap const* map, pointer item, SharedPtrNodeStack&& stack); friend bool @@ -586,16 +592,16 @@ private: friend class SHAMap; }; -inline SHAMap::const_iterator::const_iterator(SHAMap const* map) - : map_(map), item_(nullptr) +inline SHAMap::const_iterator::const_iterator(SHAMap const* map) : map_(map) { - auto temp = map_->peekFirstItem(stack_); - if (temp) + assert(map_ != nullptr); + + if (auto temp = map_->peekFirstItem(stack_)) item_ = temp->peekItem().get(); } -inline SHAMap::const_iterator::const_iterator(SHAMap const* map, pointer item) - : map_(map), item_(item) +inline SHAMap::const_iterator::const_iterator(SHAMap const* map, std::nullptr_t) + : map_(map) { } @@ -622,8 +628,7 @@ SHAMap::const_iterator::operator->() const inline SHAMap::const_iterator& SHAMap::const_iterator::operator++() { - auto temp = map_->peekNextItem(item_->key(), stack_); - if (temp) + if (auto temp = map_->peekNextItem(item_->key(), stack_)) item_ = temp->peekItem().get(); else item_ = nullptr; diff --git a/src/test/shamap/SHAMap_test.cpp b/src/test/shamap/SHAMap_test.cpp index 98f61abec..a4b1746b2 100644 --- a/src/test/shamap/SHAMap_test.cpp +++ b/src/test/shamap/SHAMap_test.cpp @@ -37,7 +37,6 @@ static_assert(!std::is_move_constructible{}, ""); static_assert(!std::is_move_assignable{}, ""); static_assert(std::is_nothrow_destructible{}, ""); -static_assert(std::is_default_constructible{}, ""); static_assert(std::is_copy_constructible{}, ""); static_assert(std::is_copy_assignable{}, ""); static_assert(std::is_move_constructible{}, "");