From dc4d299a37d2610f9b70da7960cbcbd921ee7f92 Mon Sep 17 00:00:00 2001 From: matekelemen Date: Thu, 24 Oct 2024 14:48:53 +0200 Subject: [PATCH] implement equality comparison for containers --- kratos/containers/global_pointers_vector.h | 25 ++++++++++++---------- kratos/containers/pointer_vector.h | 24 ++++++++++++--------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/kratos/containers/global_pointers_vector.h b/kratos/containers/global_pointers_vector.h index bb30ed3bb1f6..ba04848709a0 100644 --- a/kratos/containers/global_pointers_vector.h +++ b/kratos/containers/global_pointers_vector.h @@ -200,18 +200,21 @@ class GlobalPointersVector final } /** - * @brief Equality comparison operator to check if two GlobalPointersVector objects are equal. - * @details This function checks if the sizes are equal and then compares the elements for equality - * using the EqualKeyTo() function. - * @param r The GlobalPointersVector to compare with. - * @return True if the containers are equal, false otherwise. + * @brief Equality comparison operator to check if two @å GlobalPointersVector objects are equal. + * @details This function checks if the sizes are equal and then compares the elements using @a operator==. + * @param rRhs The GlobalPointersVector to compare with. + * @return True if the containers have identical sizes and store identical items in the exact same order. */ - bool operator==(const GlobalPointersVector& r) const // nothrow - { - if (size() != r.size()) - return false; - else - return std::equal(mData.begin(), mData.end(), r.mData.begin(), this->EqualKeyTo()); + bool operator==(const GlobalPointersVector& rRhs) const noexcept + { + return this->size() == rRhs.size() && std::equal( + mData.begin(), + mData.end(), + rRhs.begin(), + [](const data_type& rLhs, const data_type& rRhs) -> bool { + return rLhs == rRhs; + } + ); } ///@} diff --git a/kratos/containers/pointer_vector.h b/kratos/containers/pointer_vector.h index 3d4f988986a2..884dd3c14ea2 100644 --- a/kratos/containers/pointer_vector.h +++ b/kratos/containers/pointer_vector.h @@ -2,14 +2,14 @@ // ' / __| _` | __| _ \ __| // . \ | ( | | ( |\__ ` // _|\_\_| \__,_|\__|\___/ ____/ -// Multi-Physics +// Multi-Physics // -// License: BSD License +// License: BSD License // Kratos default license: kratos/license.txt // // Main authors: Pooyan Dadvand // Riccardo Rossi -// +// // @@ -154,12 +154,16 @@ class PointerVector final return mData[i]; } - bool operator==( const PointerVector& r ) const // nothrow + bool operator==(const PointerVector& rRhs) const noexcept { - if( size() != r.size() ) - return false; - else - return std::equal(mData.begin(), mData.end(), r.mData.begin(), this->EqualKeyTo()); + return this->size() == rRhs.size() && std::equal( + mData.begin(), + mData.end(), + rRhs.begin(), + [](const data_type& rLhs, const data_type& rRhs) -> bool { + return rLhs == rRhs; + } + ); } ///@} @@ -278,7 +282,7 @@ class PointerVector final } template - void emplace_back(Args&&... args) + void emplace_back(Args&&... args) { mData.emplace_back(std::forward(args)...); } @@ -520,4 +524,4 @@ inline std::ostream& operator << (std::ostream& rOStream, } // namespace Kratos. -#endif // KRATOS_POINTER_VECTOR_SET_H_INCLUDED defined +#endif // KRATOS_POINTER_VECTOR_SET_H_INCLUDED defined