summaryrefslogtreecommitdiff
path: root/include/o3tl
diff options
context:
space:
mode:
authorAshod Nakashian <ashodnakashian@yahoo.com>2015-01-12 18:55:03 -0500
committerCaolán McNamara <caolanm@redhat.com>2015-01-16 09:13:40 +0000
commitd598c30d6e5a776430a3294dcde2e4ead2d65e08 (patch)
treed3cc39c926f5954976211ec8dcd9b1a4f5df6dee /include/o3tl
parentccaa5519cb978a640caa22ce2bcbd6c54fa44e26 (diff)
fdo#75757: remove inheritance to std::vector
sorted_vector no longer inherits from std::vector and simplified some of the code. Change-Id: Ie9ab93dae6865f21f62abc384ed8c166b74d15ec Reviewed-on: https://gerrit.libreoffice.org/13881 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'include/o3tl')
-rw-r--r--include/o3tl/sorted_vector.hxx78
1 files changed, 46 insertions, 32 deletions
diff --git a/include/o3tl/sorted_vector.hxx b/include/o3tl/sorted_vector.hxx
index 3a7abe0024f0..328b101a8347 100644
--- a/include/o3tl/sorted_vector.hxx
+++ b/include/o3tl/sorted_vector.hxx
@@ -30,29 +30,23 @@ struct find_unique;
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> vector_t;
typedef typename std::vector<Value>::iterator iterator;
public:
typedef typename std::vector<Value>::const_iterator const_iterator;
typedef typename std::vector<Value>::size_type size_type;
- using base_t::clear;
- using base_t::empty;
- using base_t::size;
-
// MODIFIERS
std::pair<const_iterator,bool> insert( const Value& x )
{
- std::pair<const_iterator, bool> const ret(Find_t()(begin(), end(), x));
+ std::pair<const_iterator, bool> const ret(Find_t()(m_vector.begin(), m_vector.end(), x));
if (!ret.second)
{
- const_iterator const it = base_t::insert(
- begin_nonconst() + (ret.first - begin()), x);
+ const_iterator const it = m_vector.insert(m_vector.begin() + (ret.first - m_vector.begin()), x);
return std::make_pair(it, true);
}
return std::make_pair(ret.first, false);
@@ -60,10 +54,10 @@ public:
size_type erase( const Value& x )
{
- std::pair<const_iterator, bool> const ret(Find_t()(begin(), end(), x));
+ std::pair<const_iterator, bool> const ret(Find_t()(m_vector.begin(), m_vector.end(), x));
if (ret.second)
{
- base_t::erase(begin_nonconst() + (ret.first - begin()));
+ m_vector.erase(m_vector.begin() + (ret.first - m_vector.begin()));
return 1;
}
return 0;
@@ -71,60 +65,75 @@ public:
void erase( size_t index )
{
- base_t::erase( begin_nonconst() + index );
+ m_vector.erase(m_vector.begin() + index);
}
// like C++ 2011: erase with const_iterator (doesn't change sort order)
void erase(const_iterator const& position)
{ // C++98 has vector::erase(iterator), so call that
- base_t::erase(begin_nonconst() + (position - begin()));
+ m_vector.erase(m_vector.begin() + (position - m_vector.begin()));
}
void erase(const_iterator const& first, const_iterator const& last)
{
- base_t::erase(begin_nonconst() + (first - begin()),
- begin_nonconst() + (last - begin()));
+ m_vector.erase(m_vector.begin() + (first - m_vector.begin()),
+ m_vector.begin() + (last - m_vector.begin()));
+ }
+
+ void clear()
+ {
+ m_vector.clear();
}
// ACCESSORS
+ size_type size() const
+ {
+ return m_vector.size();
+ }
+
+ bool empty() const
+ {
+ return m_vector.empty();
+ }
+
// Only return a const iterator, so that the vector cannot be directly updated.
const_iterator begin() const
{
- return base_t::begin();
+ return m_vector.begin();
}
// Only return a const iterator, so that the vector cannot be directly updated.
const_iterator end() const
{
- return base_t::end();
+ return m_vector.end();
}
const Value& front() const
{
- return base_t::front();
+ return m_vector.front();
}
const Value& back() const
{
- return base_t::back();
+ return m_vector.back();
}
const Value& operator[]( size_t index ) const
{
- return base_t::operator[]( index );
+ return m_vector.operator[]( index );
}
// OPERATIONS
const_iterator lower_bound( const Value& x ) const
{
- return std::lower_bound( base_t::begin(), base_t::end(), x, Compare() );
+ return std::lower_bound( m_vector.begin(), m_vector.end(), x, Compare() );
}
const_iterator upper_bound( const Value& x ) const
{
- return std::upper_bound( base_t::begin(), base_t::end(), x, Compare() );
+ return std::upper_bound( m_vector.begin(), m_vector.end(), x, Compare() );
}
/* Searches the container for an element with a value of x
@@ -135,8 +144,8 @@ public:
*/
const_iterator find( const Value& x ) const
{
- std::pair<const_iterator, bool> const ret(Find_t()(begin(), end(), x));
- return (ret.second) ? ret.first : end();
+ std::pair<const_iterator, bool> const ret(Find_t()(m_vector.begin(), m_vector.end(), x));
+ return (ret.second) ? ret.first : m_vector.end();
}
void insert(sorted_vector<Value,Compare,Find> const& rOther)
@@ -145,18 +154,25 @@ public:
// of another sorted vector
if ( empty() )
{
- base_t::insert(begin_nonconst(), rOther.begin(), rOther.end());
+ m_vector.insert(m_vector.begin(), rOther.m_vector.begin(), rOther.m_vector.end());
}
else
- for( const_iterator it = rOther.begin(); it != rOther.end(); ++it )
- insert( *it );
+ {
+ for (const_iterator it = rOther.m_vector.begin(); it != rOther.m_vector.end(); ++it)
+ {
+ insert(*it);
+ }
+ }
}
/* Clear() elements in the vector, and free them one by one. */
void DeleteAndDestroyAll()
{
- for( const_iterator it = begin(); it != end(); ++it )
+ for (const_iterator it = m_vector.begin(); it != m_vector.end(); ++it)
+ {
delete *it;
+ }
+
clear();
}
@@ -167,14 +183,12 @@ public:
// If you are calling this function, you are Doing It Wrong!
void Resort()
{
- std::stable_sort(begin_nonconst(), end_nonconst(), Compare());
+ std::stable_sort(m_vector.begin(), m_vector.end(), Compare());
}
private:
- typename base_t::iterator begin_nonconst() { return base_t::begin(); }
- typename base_t::iterator end_nonconst() { return base_t::end(); }
-
+ vector_t m_vector;
};