1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
/**********************************************************************
Audacity: A Digital Audio Editor
@file wxArrayStringEx.h
Paul Licameli split from MemoryX.h
**********************************************************************/
#ifndef __AUDACITY_WX_ARRAY_STRING_EX__
#define __AUDACITY_WX_ARRAY_STRING_EX__
#include <wx/arrstr.h>
//! Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list
class wxArrayStringEx : public wxArrayString
{
public:
using wxArrayString::wxArrayString;
wxArrayStringEx() = default;
template< typename Iterator >
wxArrayStringEx( Iterator start, Iterator finish )
{
this->reserve( std::distance( start, finish ) );
while( start != finish )
this->push_back( *start++ );
}
template< typename T >
wxArrayStringEx( std::initializer_list< T > items )
{
this->reserve( this->size() + items.size() );
for ( const auto &item : items )
this->push_back( item );
}
//! The move operations can take arguments of the base class wxArrayString
wxArrayStringEx( wxArrayString &&other )
{
swap( other );
}
//! The move operations can take arguments of the base class wxArrayString
wxArrayStringEx &operator= ( wxArrayString &&other )
{
if ( this != &other ) {
clear();
swap( other );
}
return *this;
}
using wxArrayString::insert;
template< typename T >
iterator insert( const_iterator pos, std::initializer_list< T > items )
{
const auto index = pos - ((const wxArrayString*)this)->begin();
this->wxArrayString::Insert( {}, index, items.size() );
auto result = this->begin() + index, iter = result;
for ( auto pItem = items.begin(), pEnd = items.end();
pItem != pEnd;
++pItem, ++iter
) {
*iter = *pItem;
}
return result;
}
};
#endif
|