diff --git a/alib2std/src/extensions/ptr_array.hpp b/alib2std/src/extensions/ptr_array.hpp index 4d88d22f417d27640962277d90533c020986d5cf..cd16cae88055f0aef8516d7e74c93b79c3846678 100644 --- a/alib2std/src/extensions/ptr_array.hpp +++ b/alib2std/src/extensions/ptr_array.hpp @@ -207,20 +207,18 @@ public: template < class R > iterator set ( const_iterator pos, R && value ) { - m_data.at ( std::distance ( cbegin ( ), pos ) ) = ext::clone ( std::forward < R > ( value ) ); - return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) ); + return set ( pos, ext::clone ( std::forward < R > ( value ) ) ); } - template < class R > iterator set ( const_iterator pos, T * value ) { + delete m_data.at ( std::distance ( cbegin ( ), pos ) ); m_data.at ( std::distance ( cbegin ( ), pos ) ) = value ; return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) ); } template < class R, class ... Args > iterator emplace_set ( const_iterator pos, Args && ... args ) { - m_data.at ( std::distance ( cbegin ( ), pos ) ) = new R ( std::forward < Args > ( args ) ... ) ; - return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) ); + return set ( pos, new R ( std::forward < Args > ( args ) ... ) ); } void swap ( ptr_array & other ) { diff --git a/alib2std/src/extensions/ptr_vector.hpp b/alib2std/src/extensions/ptr_vector.hpp index b0e0fcb70c3285b309a01cf55953355c8500884e..67211a66fc071b2551b4c302a9b6a7cbb38ed1ce 100644 --- a/alib2std/src/extensions/ptr_vector.hpp +++ b/alib2std/src/extensions/ptr_vector.hpp @@ -236,20 +236,18 @@ public: template < class R > iterator set ( const_iterator pos, R && value ) { - m_data.at ( std::distance ( cbegin ( ), pos ) ) = ext::clone ( std::forward < R > ( value ) ); - return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) ); + return set ( pos, ext::clone ( std::forward < R > ( value ) ) ); } - template < class R > iterator set ( const_iterator pos, T * value ) { - m_data.at ( std::distance ( cbegin ( ), pos ) ) = value ; + delete m_data.at ( std::distance ( cbegin ( ), pos ) ); + m_data.at ( std::distance ( cbegin ( ), pos ) ) = value; return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) ); } template < class R, class ... Args > iterator emplace_set ( const_iterator pos, Args && ... args ) { - m_data.at ( std::distance ( cbegin ( ), pos ) ) = new R ( std::forward < Args > ( args ) ... ) ; - return dereferencer ( m_data.begin ( ) + std::distance ( cbegin ( ), pos ) ); + return set ( pos, new R ( std::forward < R > ( args ) ... ) ); } template < class R >