From 023e945ab298bfa6e73eb6b82789fc2fca97f247 Mon Sep 17 00:00:00 2001 From: Takeshi Abe Date: Mon, 18 May 2015 15:16:17 +0900 Subject: sc: simplify code by replacing std::find_if with std::any_of ... or std::none_of. Change-Id: I84808bedbaf098f7c4c987ea62d0ccc4a2b7c2f5 Reviewed-on: https://gerrit.libreoffice.org/15780 Tested-by: Jenkins Reviewed-by: David Tardon --- sc/qa/unit/subsequent_filters-test.cxx | 3 ++- sc/source/core/data/column2.cxx | 3 ++- sc/source/core/data/dpdimsave.cxx | 2 +- sc/source/core/data/dpgroup.cxx | 7 ++----- sc/source/core/data/dpobject.cxx | 12 +++++------- sc/source/core/tool/rangelst.cxx | 11 +++-------- sc/source/core/tool/userlist.cxx | 5 ++--- sc/source/filter/excel/xelink.cxx | 13 +++---------- sc/source/filter/excel/xestyle.cxx | 4 ++-- sc/source/ui/docshell/externalrefmgr.cxx | 4 +--- 10 files changed, 23 insertions(+), 41 deletions(-) diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index b0286e66b1ff..c0b12d385a6d 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -75,6 +75,7 @@ #include "helper/qahelper.hxx" #include "helper/shared_test_impl.hxx" +#include using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -1701,7 +1702,7 @@ public: bool hasDimension(const std::vector& rDims, const OUString& aName) { - return std::find_if(rDims.begin(), rDims.end(), FindDimByName(aName)) != rDims.end(); + return std::any_of(rDims.begin(), rDims.end(), FindDimByName(aName)); } } diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index 930107889bfe..eca99eb4e32d 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -67,6 +67,7 @@ #include #include +#include // factor from font size to optimal cell height (text width) #define SC_ROT_BREAK_FACTOR 6 @@ -2481,7 +2482,7 @@ bool hasNonEmpty( const sc::FormulaGroupContext::StrArrayType& rArray, SCROW nRo std::advance(it, nRow1); sc::FormulaGroupContext::StrArrayType::const_iterator itEnd = it; std::advance(itEnd, nRow2-nRow1+1); - return std::find_if(it, itEnd, NonNullStringFinder()) != itEnd; + return std::any_of(it, itEnd, NonNullStringFinder()); } } diff --git a/sc/source/core/data/dpdimsave.cxx b/sc/source/core/data/dpdimsave.cxx index 40dcb3f1f175..ffa721dbe0e9 100644 --- a/sc/source/core/data/dpdimsave.cxx +++ b/sc/source/core/data/dpdimsave.cxx @@ -602,7 +602,7 @@ bool ScDPDimensionSaveData::operator==( const ScDPDimensionSaveData& ) const void ScDPDimensionSaveData::AddGroupDimension( const ScDPSaveGroupDimension& rGroupDim ) { - OSL_ENSURE( ::std::find_if( maGroupDims.begin(), maGroupDims.end(), ScDPSaveGroupDimNameFunc( rGroupDim.GetGroupDimName() ) ) == maGroupDims.end(), + OSL_ENSURE( ::std::none_of( maGroupDims.begin(), maGroupDims.end(), ScDPSaveGroupDimNameFunc( rGroupDim.GetGroupDimName() ) ), "ScDPDimensionSaveData::AddGroupDimension - group dimension exists already" ); // ReplaceGroupDimension() adds new or replaces existing ReplaceGroupDimension( rGroupDim ); diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx index 49edcfbe89e4..b9c557233826 100644 --- a/sc/source/core/data/dpgroup.cxx +++ b/sc/source/core/data/dpgroup.cxx @@ -39,6 +39,7 @@ #include #include #include +#include using namespace ::com::sun::star; using ::com::sun::star::uno::Any; @@ -755,11 +756,7 @@ void ScDPGroupTableData::ModifyFilterCriteria(vector::iterator it = - std::find_if( - aMatchValues.begin(), aMatchValues.end(), FindCaseInsensitive(pGrpItem->GetName())); - - if (it == aMatchValues.end()) + if (std::none_of(aMatchValues.begin(), aMatchValues.end(), FindCaseInsensitive(pGrpItem->GetName()))) continue; pGrpItem->FillGroupFilter(*pGrpFilter); diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index 30884cc17bc5..ab982c4ef6c8 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -78,6 +78,7 @@ #include #include #include +#include using namespace com::sun::star; using ::std::vector; @@ -2588,7 +2589,7 @@ void ScDPObject::ConvertOrientation( { // if set via api, a data column may occur several times // (if the function hasn't been changed yet) -> also look for duplicate data column - bFirst = std::find_if(itrBeg, itr, FindByOriginalDim(nCol)) == itr; + bFirst = std::none_of(itrBeg, itr, FindByOriginalDim(nCol)); } sheet::GeneralFunction eFunc = ScDataPilotConversion::FirstFunc(rField.nFuncMask); @@ -3682,20 +3683,17 @@ ScRangeList ScDPCollection::GetAllTableRanges( SCTAB nTab ) const bool ScDPCollection::IntersectsTableByColumns( SCCOL nCol1, SCCOL nCol2, SCROW nRow, SCTAB nTab ) const { - return std::find_if( - maTables.begin(), maTables.end(), FindIntersetingTableByColumns(nCol1, nCol2, nRow, nTab)) != maTables.end(); + return std::any_of(maTables.begin(), maTables.end(), FindIntersetingTableByColumns(nCol1, nCol2, nRow, nTab)); } bool ScDPCollection::IntersectsTableByRows( SCCOL nCol, SCROW nRow1, SCROW nRow2, SCTAB nTab ) const { - return std::find_if( - maTables.begin(), maTables.end(), FindIntersectingTableByRows(nCol, nRow1, nRow2, nTab)) != maTables.end(); + return std::any_of(maTables.begin(), maTables.end(), FindIntersectingTableByRows(nCol, nRow1, nRow2, nTab)); } bool ScDPCollection::HasTable( const ScRange& rRange ) const { - return std::find_if( - maTables.begin(), maTables.end(), FindIntersectingTable(rRange)) != maTables.end(); + return std::any_of(maTables.begin(), maTables.end(), FindIntersectingTable(rRange)); } #if DEBUG_PIVOT_TABLE diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx index 44d740f8d93e..8b1bb08a20c0 100644 --- a/sc/source/core/tool/rangelst.cxx +++ b/sc/source/core/tool/rangelst.cxx @@ -28,6 +28,7 @@ #include "rechead.hxx" #include "compiler.hxx" #include +#include using ::std::vector; using ::std::advance; @@ -1054,18 +1055,12 @@ void ScRangeList::Append( const ScRange& rRange ) bool ScRangeList::Intersects( const ScRange& rRange ) const { - const_iterator itrEnd = maRanges.end(); - const_iterator itr = - find_if(maRanges.begin(), itrEnd, FindIntersectingRange(rRange)); - return itr != itrEnd; + return std::any_of(maRanges.begin(), maRanges.end(), FindIntersectingRange(rRange)); } bool ScRangeList::In( const ScRange& rRange ) const { - const_iterator itrEnd = maRanges.end(); - const_iterator itr = - find_if(maRanges.begin(), itrEnd, FindEnclosingRange(rRange)); - return itr != itrEnd; + return std::any_of(maRanges.begin(), maRanges.end(), FindEnclosingRange(rRange)); } size_t ScRangeList::GetCellCount() const diff --git a/sc/source/core/tool/userlist.cxx b/sc/source/core/tool/userlist.cxx index 6f594dff46da..411a2fdf5c8c 100644 --- a/sc/source/core/tool/userlist.cxx +++ b/sc/source/core/tool/userlist.cxx @@ -26,6 +26,7 @@ #include #include +#include namespace { @@ -317,9 +318,7 @@ bool ScUserList::operator!=( const ScUserList& r ) const bool ScUserList::HasEntry( const OUString& rStr ) const { - DataType::const_iterator itr = ::std::find_if( - maData.begin(), maData.end(), ::boost::bind(&ScUserListData::GetString, _1) == rStr); - return itr != maData.end(); + return ::std::any_of(maData.begin(), maData.end(), ::boost::bind(&ScUserListData::GetString, _1) == rStr); } ScUserList::iterator ScUserList::begin() diff --git a/sc/source/filter/excel/xelink.cxx b/sc/source/filter/excel/xelink.cxx index 6fd5e8269e94..a936f457c61d 100644 --- a/sc/source/filter/excel/xelink.cxx +++ b/sc/source/filter/excel/xelink.cxx @@ -33,7 +33,6 @@ #include using ::std::unique_ptr; -using ::std::find_if; using ::std::vector; using ::com::sun::star::uno::Any; @@ -1884,9 +1883,7 @@ void XclExpSupbookBuffer::StoreCell( sal_uInt16 nFileId, const OUString& rTabNam return; FindSBIndexEntry f(nSupbookId, nSheetId); - XclExpSBIndexVec::iterator itrEnd = maSBIndexVec.end(); - XclExpSBIndexVec::const_iterator itr = find_if(maSBIndexVec.begin(), itrEnd, f); - if (itr == itrEnd) + if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(), f)) { maSBIndexVec.push_back(XclExpSBIndex()); XclExpSBIndex& r = maSBIndexVec.back(); @@ -1950,9 +1947,7 @@ void XclExpSupbookBuffer::StoreCellRange( sal_uInt16 nFileId, const OUString& rT { sal_uInt16 nSheetId = nFirstSheetId + static_cast(nTab); FindSBIndexEntry f(nSupbookId, nSheetId); - XclExpSBIndexVec::iterator itrEnd = maSBIndexVec.end(); - XclExpSBIndexVec::const_iterator itr = find_if(maSBIndexVec.begin(), itrEnd, f); - if (itr == itrEnd) + if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(), f)) { maSBIndexVec.push_back(XclExpSBIndex()); XclExpSBIndex& r = maSBIndexVec.back(); @@ -2055,9 +2050,7 @@ XclExpXti XclExpSupbookBuffer::GetXti( sal_uInt16 nFileId, const OUString& rTabN return aXti; FindSBIndexEntry f(nSupbookId, nSheetId); - XclExpSBIndexVec::iterator itrEnd = maSBIndexVec.end(); - XclExpSBIndexVec::const_iterator itr = find_if(maSBIndexVec.begin(), itrEnd, f); - if (itr == itrEnd) + if (::std::none_of(maSBIndexVec.begin(), maSBIndexVec.end(), f)) { maSBIndexVec.push_back(XclExpSBIndex()); XclExpSBIndex& r = maSBIndexVec.back(); diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx index 46ecbfb558ec..df5c75b2e822 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -2986,12 +2986,12 @@ void XclExpXFBuffer::AppendXFIndex( sal_uInt32 nXFId ) void XclExpXFBuffer::AddBorderAndFill( const XclExpXF& rXF ) { - if( std::find_if( maBorders.begin(), maBorders.end(), XclExpBorderPred( rXF.GetBorderData() ) ) == maBorders.end() ) + if( std::none_of( maBorders.begin(), maBorders.end(), XclExpBorderPred( rXF.GetBorderData() ) ) ) { maBorders.push_back( rXF.GetBorderData() ); } - if( std::find_if( maFills.begin(), maFills.end(), XclExpFillPred( rXF.GetAreaData() ) ) == maFills.end() ) + if( std::none_of( maFills.begin(), maFills.end(), XclExpFillPred( rXF.GetAreaData() ) ) ) { maFills.push_back( rXF.GetAreaData() ); } diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx index 6791f57b674e..36dc18d2142e 100644 --- a/sc/source/ui/docshell/externalrefmgr.cxx +++ b/sc/source/ui/docshell/externalrefmgr.cxx @@ -2591,9 +2591,7 @@ bool ScExternalRefManager::hasExternalFile(sal_uInt16 nFileId) const bool ScExternalRefManager::hasExternalFile(const OUString& rFile) const { - vector::const_iterator itrBeg = maSrcFiles.begin(), itrEnd = maSrcFiles.end(); - vector::const_iterator itr = find_if(itrBeg, itrEnd, FindSrcFileByName(rFile)); - return itr != itrEnd; + return ::std::any_of(maSrcFiles.begin(), maSrcFiles.end(), FindSrcFileByName(rFile)); } const ScExternalRefManager::SrcFileData* ScExternalRefManager::getExternalFileData(sal_uInt16 nFileId) const -- cgit