diff --git a/include/ebcl/Arrays.hh b/include/ebcl/Arrays.hh index 75ae7fc..e1b594d 100644 --- a/include/ebcl/Arrays.hh +++ b/include/ebcl/Arrays.hh @@ -105,6 +105,9 @@ class T_Array final T_Array( MyType_&& source ) noexcept; MyType_& operator= ( MyType_&& other ) noexcept; + T_Array( std::initializer_list< T > list ) noexcept; + MyType_& operator= ( std::initializer_list< T > list ) noexcept; + template< typename TP > friend void swap( T_Array< TP >& lhs , T_Array< TP >& rhs ) noexcept; @@ -159,6 +162,7 @@ class T_Array final MyType_& addAll( MyType_ const& other ) noexcept; MyType_& addAll( MyType_&& other ) noexcept; + MyType_& addAll( std::initializer_list< T > values ) noexcept; // --------------------------------------------------------------------- diff --git a/include/ebcl/inline/Arrays.hh b/include/ebcl/inline/Arrays.hh index d8a6e1e..cfeb1b7 100644 --- a/include/ebcl/inline/Arrays.hh +++ b/include/ebcl/inline/Arrays.hh @@ -86,6 +86,24 @@ inline T_Array< T >& T_Array< T >::operator=( /*----------------------------------------------------------------------------*/ +template< typename T > +inline T_Array< T >::T_Array( + std::initializer_list< T > list ) noexcept + : T_Array( DEFAULT_GROWTH( ) ) +{ + addAll( std::move( list ) ); +} + +template< typename T > +inline T_Array< T >& T_Array< T >::operator= ( + std::initializer_list< T > list ) noexcept +{ + clear( ); + return addAll( std::move( list ) ); +} + +/*----------------------------------------------------------------------------*/ + template< typename T > inline void swap( T_Array< T >& lhs , T_Array< T >& rhs ) noexcept @@ -330,6 +348,19 @@ inline T_Array< T >& T_Array< T >::addAll( return *this; } +template< typename T > +inline T_Array< T >& T_Array< T >::addAll( + std::initializer_list< T > other ) noexcept +{ + ensureCapacity( size_ + other.size( ) ); + auto i = size_; + for ( T const& v : other ) { + ::new ( ( char* ) &( data_[ i ++ ] ) ) T( v ); + } + size_ += other.size( ); + return *this; +} + /*----------------------------------------------------------------------------*/ template< typename T > @@ -2125,7 +2156,7 @@ void T_AutoArray< T , S , G >::convertToDynamic_( { assert( isStatic( ) ); T_Static_& s( static_( ) ); - T_Dynamic_ d{ G }; + T_Dynamic_ d( G ); d.ensureCapacity( std::max( s.capacity( ) , capacity ) ); auto const sz( s.size( ) ); for ( auto i = 0u ; i < sz ; i ++ ) {