1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-08-11 14:19:49 +00:00

Prevent values being stolen accidentally and provide proper overloads.

This commit is contained in:
King_DuckZ 2016-07-13 12:17:54 +01:00
parent f58d7d84eb
commit 12c062b939
2 changed files with 19 additions and 8 deletions

View file

@ -78,8 +78,9 @@ namespace dinhelp {
iterator erase ( const iterator& parDele ); iterator erase ( const iterator& parDele );
iterator erase ( const iterator& parFrom, const iterator& parToExcl ); iterator erase ( const iterator& parFrom, const iterator& parToExcl );
void clear ( void ); void clear ( void );
mov_reference operator[] ( size_type parIndex ); reference operator[] ( size_type parIndex ) &;
const_reference operator[] ( size_type parIndex ) const; mov_reference operator[] ( size_type parIndex ) &&;
const_reference operator[] ( size_type parIndex ) const &;
MaxSizedArray& operator= ( const MaxSizedArray& parOther ); MaxSizedArray& operator= ( const MaxSizedArray& parOther );
bool operator== ( const MaxSizedArray& parOther ) const; bool operator== ( const MaxSizedArray& parOther ) const;
bool operator!= ( const MaxSizedArray& parOther ) const; bool operator!= ( const MaxSizedArray& parOther ) const;
@ -95,10 +96,12 @@ namespace dinhelp {
const_reverse_iterator rbegin ( void ) const; const_reverse_iterator rbegin ( void ) const;
reverse_iterator rend ( void ); reverse_iterator rend ( void );
const_reverse_iterator rend ( void ) const; const_reverse_iterator rend ( void ) const;
reference front ( void ) { return (*this)[0]; } reference front ( void ) & { return (*this)[0]; }
reference back ( void ) { return (*this)[size() - 1]; } reference back ( void ) & { return (*this)[size() - 1]; }
const_reference front ( void ) const { return (*this)[0]; } mov_reference front ( void ) && { return (*this)[0]; }
const_reference back ( void ) const { return (*this)[size() - 1]; } mov_reference back ( void ) && { return (*this)[size() - 1]; }
const_reference front ( void ) const & { return (*this)[0]; }
const_reference back ( void ) const & { return (*this)[size() - 1]; }
private: private:
pointer GetPointer_NoAssert ( void ) { return m_localMem; } pointer GetPointer_NoAssert ( void ) { return m_localMem; }

View file

@ -104,7 +104,15 @@ namespace dinhelp {
///------------------------------------------------------------------------- ///-------------------------------------------------------------------------
///------------------------------------------------------------------------- ///-------------------------------------------------------------------------
template <typename T, size_t S, typename A> template <typename T, size_t S, typename A>
typename MaxSizedArray<T, S, A>::mov_reference MaxSizedArray<T, S, A>::operator[] (size_type parIndex) { typename MaxSizedArray<T, S, A>::reference MaxSizedArray<T, S, A>::operator[] (size_type parIndex) & {
assert(parIndex < size());
return m_localMem[parIndex];
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
template <typename T, size_t S, typename A>
typename MaxSizedArray<T, S, A>::mov_reference MaxSizedArray<T, S, A>::operator[] (size_type parIndex) && {
assert(parIndex < size()); assert(parIndex < size());
return std::move(m_localMem[parIndex]); return std::move(m_localMem[parIndex]);
} }
@ -112,7 +120,7 @@ namespace dinhelp {
///------------------------------------------------------------------------- ///-------------------------------------------------------------------------
///------------------------------------------------------------------------- ///-------------------------------------------------------------------------
template <typename T, size_t S, typename A> template <typename T, size_t S, typename A>
typename MaxSizedArray<T, S, A>::const_reference MaxSizedArray<T, S, A>::operator[] (size_type parIndex) const { typename MaxSizedArray<T, S, A>::const_reference MaxSizedArray<T, S, A>::operator[] (size_type parIndex) const & {
assert(parIndex < size()); assert(parIndex < size());
return m_localMem[parIndex]; return m_localMem[parIndex];
} }