[Libreoffice-commits] core.git: include/comphelper sc/source
Michael Stahl
mstahl at redhat.com
Fri Nov 6 05:00:22 PST 2015
include/comphelper/stl_types.hxx | 23 +++++++++++++++++++++++
sc/source/core/tool/dbdata.cxx | 24 ++++--------------------
2 files changed, 27 insertions(+), 20 deletions(-)
New commits:
commit eaf640d282dd2bd8f647a510e401323da506a810
Author: Michael Stahl <mstahl at redhat.com>
Date: Fri Nov 6 11:48:35 2015 +0100
comphelper: add a generic implementation of std container operator==
... that contain std::unique_ptr. With C++11 variadic templates this
apparently works for both std::vector and std::set; associative
containers like std::map have different iterators so need a different
implementation.
Change-Id: I6872445b007875c310d08fa7a8d7311075880b1d
Reviewed-on: https://gerrit.libreoffice.org/19818
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Michael Stahl <mstahl at redhat.com>
diff --git a/include/comphelper/stl_types.hxx b/include/comphelper/stl_types.hxx
index 84ea999..f154937 100644
--- a/include/comphelper/stl_types.hxx
+++ b/include/comphelper/stl_types.hxx
@@ -100,6 +100,29 @@ template<class T> struct UniquePtrValueLess
}
};
+/// by-value implementation of std::foo<std::unique_ptr<T>>::operator==
+template<template<typename, typename...> class C, typename T, typename... Etc>
+bool ContainerUniquePtrEquals(
+ C<std::unique_ptr<T>, Etc...> const& lhs,
+ C<std::unique_ptr<T>, Etc...> const& rhs)
+{
+ if (lhs.size() != rhs.size())
+ {
+ return false;
+ }
+ for (auto iter1 = lhs.begin(), iter2 = rhs.begin();
+ iter1 != lhs.end();
+ ++iter1, ++iter2)
+ {
+ if (!(**iter1 == **iter2))
+ {
+ return false;
+ }
+ }
+ return true;
+};
+
+
/** STL-compliant structure for comparing Reference< <iface> > instances
*/
template < class IAFCE >
diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx
index cdf0ff0..5f145fa 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -34,6 +34,8 @@
#include "dociter.hxx"
#include "brdcst.hxx"
+#include <comphelper/stl_types.hxx>
+
#include <memory>
#include <utility>
@@ -1169,18 +1171,7 @@ size_t ScDBCollection::NamedDBs::size() const
bool ScDBCollection::NamedDBs::operator== (const NamedDBs& r) const
{
- if (m_DBs.size() != r.m_DBs.size())
- {
- return false;
- }
- for (auto iter1 = m_DBs.begin(), iter2 = r.m_DBs.begin(); iter1 != m_DBs.end(); ++iter1, ++iter2)
- {
- if (**iter1 != **iter2)
- {
- return false;
- }
- }
- return true;
+ return ::comphelper::ContainerUniquePtrEquals(m_DBs, r.m_DBs);
}
ScDBCollection::AnonDBs::iterator ScDBCollection::AnonDBs::begin()
@@ -1257,14 +1248,7 @@ bool ScDBCollection::AnonDBs::has( const ScDBData* p ) const
bool ScDBCollection::AnonDBs::operator== (const AnonDBs& r) const
{
- if (m_DBs.size() != r.m_DBs.size())
- return false;
- for (auto iter1 = begin(), iter2 = r.begin(); iter1 != end(); ++iter1, ++iter2)
- {
- if (**iter1 != **iter2)
- return false;
- }
- return true;
+ return ::comphelper::ContainerUniquePtrEquals(m_DBs, r.m_DBs);
}
ScDBCollection::AnonDBs::AnonDBs()
More information about the Libreoffice-commits
mailing list