Kaydet (Commit) ebd2bfa2 authored tarafından Michael Stahl's avatar Michael Stahl

Revert "Revert "sorted_vector: turn Find parameter into template""

This reverts commit 8291d416.

Un-revert that, with a tweak: with the bizarre name lookup semantics
in C++, the proper way to refer to a template (as opposed to a template
instance) is by prefixing the name with its namespace, which does seem
to work with MSVC2008 & GCC 4.7; thanks to Stephan Bergmann for the hint.

Change-Id: Id9cccbe68fb3ce2dd070c4b3dbd21782c92170ca
üst 285a5ae0
...@@ -27,12 +27,13 @@ struct find_unique; ...@@ -27,12 +27,13 @@ struct find_unique;
@tpl Compare comparison method @tpl Compare comparison method
@tpl Find look up index of a Value in the array @tpl Find look up index of a Value in the array
*/ */
template<class Value, class Compare = std::less<Value>, template<typename Value, typename Compare = std::less<Value>,
class Find = find_unique<Value, Compare> > template<typename, typename> class Find = find_unique >
class sorted_vector class sorted_vector
: private std::vector<Value> : private std::vector<Value>
{ {
private: private:
typedef Find<Value, Compare> Find_t;
typedef typename std::vector<Value> base_t; typedef typename std::vector<Value> base_t;
typedef typename std::vector<Value>::iterator iterator; typedef typename std::vector<Value>::iterator iterator;
public: public:
...@@ -47,7 +48,7 @@ public: ...@@ -47,7 +48,7 @@ public:
std::pair<const_iterator,bool> insert( const Value& x ) std::pair<const_iterator,bool> insert( const Value& x )
{ {
std::pair<const_iterator, bool> const ret(Find()(begin(), end(), x)); std::pair<const_iterator, bool> const ret(Find_t()(begin(), end(), x));
if (!ret.second) if (!ret.second)
{ {
const_iterator const it = base_t::insert( const_iterator const it = base_t::insert(
...@@ -59,7 +60,7 @@ public: ...@@ -59,7 +60,7 @@ public:
size_type erase( const Value& x ) size_type erase( const Value& x )
{ {
std::pair<const_iterator, bool> const ret(Find()(begin(), end(), x)); std::pair<const_iterator, bool> const ret(Find_t()(begin(), end(), x));
if (ret.second) if (ret.second)
{ {
base_t::erase(begin_nonconst() + (ret.first - begin())); base_t::erase(begin_nonconst() + (ret.first - begin()));
...@@ -129,7 +130,7 @@ public: ...@@ -129,7 +130,7 @@ public:
*/ */
const_iterator find( const Value& x ) const const_iterator find( const Value& x ) const
{ {
std::pair<const_iterator, bool> const ret(Find()(begin(), end(), x)); std::pair<const_iterator, bool> const ret(Find_t()(begin(), end(), x));
return (ret.second) ? ret.first : end(); return (ret.second) ? ret.first : end();
} }
...@@ -180,8 +181,8 @@ template <class T> struct less_ptr_to : public std::binary_function <T*,T*,bool> ...@@ -180,8 +181,8 @@ template <class T> struct less_ptr_to : public std::binary_function <T*,T*,bool>
template<class Value, class Compare> template<class Value, class Compare>
struct find_unique struct find_unique
{ {
typedef typename sorted_vector<Value, Compare, find_unique> typedef typename sorted_vector<Value, Compare,
::const_iterator const_iterator; o3tl::find_unique> ::const_iterator const_iterator;
std::pair<const_iterator, bool> operator()( std::pair<const_iterator, bool> operator()(
const_iterator first, const_iterator last, const_iterator first, const_iterator last,
Value const& v) Value const& v)
...@@ -197,8 +198,8 @@ struct find_unique ...@@ -197,8 +198,8 @@ struct find_unique
template<class Value, class Compare> template<class Value, class Compare>
struct find_partialorder_ptrequals struct find_partialorder_ptrequals
{ {
typedef typename sorted_vector<Value, Compare, find_partialorder_ptrequals> typedef typename sorted_vector<Value, Compare,
::const_iterator const_iterator; o3tl::find_partialorder_ptrequals>::const_iterator const_iterator;
std::pair<const_iterator, bool> operator()( std::pair<const_iterator, bool> operator()(
const_iterator first, const_iterator last, const_iterator first, const_iterator last,
Value const& v) Value const& v)
......
...@@ -136,8 +136,7 @@ public: ...@@ -136,8 +136,7 @@ public:
void testBasics_FindPtr() void testBasics_FindPtr()
{ {
o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>, o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>,
o3tl::find_partialorder_ptrequals<SwContent*, o3tl::find_partialorder_ptrequals> aVec;
o3tl::less_ptr_to<SwContent> > > aVec;
SwContent *p1 = new SwContent(1); SwContent *p1 = new SwContent(1);
SwContent *p2 = new SwContent(2); SwContent *p2 = new SwContent(2);
SwContent *p2_2 = new SwContent(2); SwContent *p2_2 = new SwContent(2);
...@@ -195,8 +194,7 @@ public: ...@@ -195,8 +194,7 @@ public:
void testErase_FindPtr() void testErase_FindPtr()
{ {
o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>, o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>,
o3tl::find_partialorder_ptrequals<SwContent*, o3tl::find_partialorder_ptrequals> aVec;
o3tl::less_ptr_to<SwContent> > > aVec;
SwContent *p1 = new SwContent(1); SwContent *p1 = new SwContent(1);
SwContent *p1_2 = new SwContent(1); SwContent *p1_2 = new SwContent(1);
SwContent *p1_3 = new SwContent(1); SwContent *p1_3 = new SwContent(1);
......
...@@ -145,7 +145,7 @@ struct CompareSwRedlineTbl ...@@ -145,7 +145,7 @@ struct CompareSwRedlineTbl
}; };
class _SwRedlineTbl class _SwRedlineTbl
: public o3tl::sorted_vector<SwRedline*, CompareSwRedlineTbl, : public o3tl::sorted_vector<SwRedline*, CompareSwRedlineTbl,
o3tl::find_partialorder_ptrequals<SwRedline*, CompareSwRedlineTbl> > o3tl::find_partialorder_ptrequals>
{ {
public: public:
~_SwRedlineTbl(); ~_SwRedlineTbl();
......
...@@ -76,14 +76,14 @@ struct CompareSwpHtStart ...@@ -76,14 +76,14 @@ struct CompareSwpHtStart
bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const; bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
}; };
class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart, class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart,
o3tl::find_partialorder_ptrequals<SwTxtAttr*, CompareSwpHtStart> > {}; o3tl::find_partialorder_ptrequals> {};
struct CompareSwpHtEnd struct CompareSwpHtEnd
{ {
bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const; bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
}; };
class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd, class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd,
o3tl::find_partialorder_ptrequals<SwTxtAttr*, CompareSwpHtEnd> > {}; o3tl::find_partialorder_ptrequals> {};
// Class SwpHintsArr // Class SwpHintsArr
......
...@@ -130,8 +130,7 @@ public: ...@@ -130,8 +130,7 @@ public:
class SwHTMLPosFlyFrms class SwHTMLPosFlyFrms
: public o3tl::sorted_vector<SwHTMLPosFlyFrm*, : public o3tl::sorted_vector<SwHTMLPosFlyFrm*,
o3tl::less_ptr_to<SwHTMLPosFlyFrm>, o3tl::less_ptr_to<SwHTMLPosFlyFrm>,
o3tl::find_partialorder_ptrequals<SwHTMLPosFlyFrm*, o3tl::find_partialorder_ptrequals>
o3tl::less_ptr_to<SwHTMLPosFlyFrm> > >
{}; {};
#endif #endif
......
...@@ -106,8 +106,7 @@ using namespace ::com::sun::star::container; ...@@ -106,8 +106,7 @@ using namespace ::com::sun::star::container;
class SwContentArr class SwContentArr
: public o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>, : public o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>,
o3tl::find_partialorder_ptrequals<SwContent*, o3tl::find_partialorder_ptrequals>
o3tl::less_ptr_to<SwContent> > >
{ {
public: public:
~SwContentArr() { DeleteAndDestroyAll(); } ~SwContentArr() { DeleteAndDestroyAll(); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment