Skip to content
Snippets Groups Projects
Commit bd3e231c authored by Jan Trávníček's avatar Jan Trávníček
Browse files

documentation and ptr container fixes

parent a1f29ecf
No related branches found
No related tags found
No related merge requests found
...@@ -39,9 +39,9 @@ namespace ext { ...@@ -39,9 +39,9 @@ namespace ext {
* \brief * \brief
* Implementation of set mimicking the iterface of the standard library set. The inner representation is using sorted vector of unique value. * Implementation of set mimicking the iterface of the standard library set. The inner representation is using sorted vector of unique value.
* *
* \param T the type of stored values * \tparam T the type of stored values
* \param Compare the less comparator used to determinine order between elements - defaults to std::less < T > * \tparam Compare the less comparator used to determinine order between elements - defaults to std::less < T >
* \param Alloc the allocator of elements - defaults to std::allocator < T > * \tparam Alloc the allocator of elements - defaults to std::allocator < T >
*/ */
template < class T, class Compare = std::less<T>, class Alloc = std::allocator<T> > template < class T, class Compare = std::less<T>, class Alloc = std::allocator<T> >
class linear_set { class linear_set {
......
This diff is collapsed.
...@@ -50,9 +50,6 @@ public: ...@@ -50,9 +50,6 @@ public:
insert ( cbegin ( ), std::move ( init ) ); insert ( cbegin ( ), std::move ( init ) );
} }
   
ptr_vector ( std::initializer_list < T * > init ) : m_data ( init ) {
}
explicit ptr_vector ( size_type count ) { explicit ptr_vector ( size_type count ) {
resize ( count ); resize ( count );
} }
...@@ -143,10 +140,6 @@ public: ...@@ -143,10 +140,6 @@ public:
return * m_data.back ( ); return * m_data.back ( );
} }
   
bool null ( size_type index ) const {
return m_data.at ( index ) == NULL;
}
/* T * const * data ( ) noexcept { /* T * const * data ( ) noexcept {
return m_data.data ( ); return m_data.data ( );
} }
...@@ -318,6 +311,7 @@ public: ...@@ -318,6 +311,7 @@ public:
m_data.pop_back ( ); m_data.pop_back ( );
} }
   
template < class R = T >
void resize ( size_type count ) { void resize ( size_type count ) {
for ( size_type i = count; i < m_data.size ( ); ++ i ) { for ( size_type i = count; i < m_data.size ( ); ++ i ) {
delete m_data [ i ]; delete m_data [ i ];
...@@ -325,7 +319,7 @@ public: ...@@ -325,7 +319,7 @@ public:
size_type i = m_data.size ( ); size_type i = m_data.size ( );
m_data.resize ( count ); m_data.resize ( count );
for ( ; i < count; ++ i ) { for ( ; i < count; ++ i ) {
m_data [ i ] = NULL; m_data [ i ] = new R ( );
} }
} }
   
...@@ -341,6 +335,13 @@ public: ...@@ -341,6 +335,13 @@ public:
} }
} }
   
void shrink ( size_type count ) {
for ( size_type i = count; i < m_data.size ( ); ++ i ) {
delete m_data [ i ];
}
m_data.resize ( std::min ( count, m_data.size ( ) ) );
}
void swap ( ptr_vector & other ) { void swap ( ptr_vector & other ) {
std::swap ( this->m_data, other.m_data ); std::swap ( this->m_data, other.m_data );
} }
......
...@@ -54,9 +54,9 @@ void PtrVectorTest::testPolymorph() { ...@@ -54,9 +54,9 @@ void PtrVectorTest::testPolymorph() {
CPPUNIT_ASSERT ( data [ 1 ].type ( ) == PtrVectorTest::Type::CHILD1 ); CPPUNIT_ASSERT ( data [ 1 ].type ( ) == PtrVectorTest::Type::CHILD1 );
CPPUNIT_ASSERT ( data [ 2 ].type ( ) == PtrVectorTest::Type::CHILD1 ); CPPUNIT_ASSERT ( data [ 2 ].type ( ) == PtrVectorTest::Type::CHILD1 );
   
data.resize ( 4 ); data.resize < Child2 > ( 4 );
CPPUNIT_ASSERT ( data.null ( 3 ) ); CPPUNIT_ASSERT ( data.at ( 3 ) == Child2 ( ) );
data.resize ( 3 ); data.shrink ( 3 );
   
ext::ptr_vector < Base > data2 = data; ext::ptr_vector < Base > data2 = data;
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment