sorted_vector: turn Find parameter into template

Enforces same type parameters for sorted_vector and Find, and makes
it easier to use.

Change-Id: Ide456a48f015cb0a9dea7a0bf2bcf2ccad527fd1
This commit is contained in:
Michael Stahl 2012-08-01 12:52:09 +02:00
parent 77165efb4e
commit 3e3acee762
6 changed files with 13 additions and 16 deletions

View file

@ -27,12 +27,13 @@ struct find_unique;
@tpl Compare comparison method
@tpl Find look up index of a Value in the array
*/
template<class Value, class Compare = std::less<Value>,
class Find = find_unique<Value, Compare> >
template<typename Value, typename Compare = std::less<Value>,
template<typename, typename> class Find = find_unique >
class sorted_vector
: private std::vector<Value>
{
private:
typedef Find<Value, Compare> Find_t;
typedef typename std::vector<Value> base_t;
typedef typename std::vector<Value>::iterator iterator;
public:
@ -47,7 +48,7 @@ public:
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)
{
const_iterator const it = base_t::insert(
@ -59,7 +60,7 @@ public:
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)
{
base_t::erase(begin_nonconst() + (ret.first - begin()));
@ -129,7 +130,7 @@ public:
*/
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();
}

View file

@ -136,8 +136,7 @@ public:
void testBasics_FindPtr()
{
o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>,
o3tl::find_partialorder_ptrequals<SwContent*,
o3tl::less_ptr_to<SwContent> > > aVec;
o3tl::find_partialorder_ptrequals> aVec;
SwContent *p1 = new SwContent(1);
SwContent *p2 = new SwContent(2);
SwContent *p2_2 = new SwContent(2);
@ -195,8 +194,7 @@ public:
void testErase_FindPtr()
{
o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>,
o3tl::find_partialorder_ptrequals<SwContent*,
o3tl::less_ptr_to<SwContent> > > aVec;
o3tl::find_partialorder_ptrequals> aVec;
SwContent *p1 = new SwContent(1);
SwContent *p1_2 = new SwContent(1);
SwContent *p1_3 = new SwContent(1);

View file

@ -145,7 +145,7 @@ struct CompareSwRedlineTbl
};
class _SwRedlineTbl
: public o3tl::sorted_vector<SwRedline*, CompareSwRedlineTbl,
o3tl::find_partialorder_ptrequals<SwRedline*, CompareSwRedlineTbl> >
o3tl::find_partialorder_ptrequals>
{
public:
~_SwRedlineTbl();

View file

@ -76,14 +76,14 @@ struct CompareSwpHtStart
bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
};
class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart,
o3tl::find_partialorder_ptrequals<SwTxtAttr*, CompareSwpHtStart> > {};
o3tl::find_partialorder_ptrequals> {};
struct CompareSwpHtEnd
{
bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
};
class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd,
o3tl::find_partialorder_ptrequals<SwTxtAttr*, CompareSwpHtEnd> > {};
o3tl::find_partialorder_ptrequals> {};
// Class SwpHintsArr

View file

@ -130,8 +130,7 @@ public:
class SwHTMLPosFlyFrms
: public o3tl::sorted_vector<SwHTMLPosFlyFrm*,
o3tl::less_ptr_to<SwHTMLPosFlyFrm>,
o3tl::find_partialorder_ptrequals<SwHTMLPosFlyFrm*,
o3tl::less_ptr_to<SwHTMLPosFlyFrm> > >
o3tl::find_partialorder_ptrequals>
{};
#endif

View file

@ -106,8 +106,7 @@ using namespace ::com::sun::star::container;
class SwContentArr
: public o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>,
o3tl::find_partialorder_ptrequals<SwContent*,
o3tl::less_ptr_to<SwContent> > >
o3tl::find_partialorder_ptrequals>
{
public:
~SwContentArr() { DeleteAndDestroyAll(); }