From a86d7d51f39d365ec11427a66a1a94fe465a896a Mon Sep 17 00:00:00 2001 From: rich_sposato Date: Fri, 30 Sep 2011 23:16:08 +0000 Subject: [PATCH] Fixed bug 3388381 by changing ctor body. git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1127 7ec92016-0320-0410-acc4-a06ded1c099a --- include/loki/AssocVector.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/include/loki/AssocVector.h b/include/loki/AssocVector.h index bc31c52..230cb01 100644 --- a/include/loki/AssocVector.h +++ b/include/loki/AssocVector.h @@ -33,6 +33,9 @@ #include #include #include +#include +#include + namespace Loki { @@ -144,10 +147,18 @@ namespace Loki AssocVector(InputIterator first, InputIterator last, const key_compare& comp = key_compare(), const A& alloc = A()) - : Base(first, last, alloc), MyCompare(comp) + : Base( alloc ), MyCompare( comp ) { - MyCompare& me = *this; - std::sort(begin(), end(), me); + typedef ::std::vector< ::std::pair< K, V >, A > BaseType; + typedef ::std::map< K, V, C, A > TempMap; + typedef ::std::back_insert_iterator< Base > MyInserter; + MyCompare & me = *this; + // Make a temporary map similar to this type to prevent any duplicates elements. + TempMap temp( first, last, me, alloc ); + Base::reserve( temp.size() ); + BaseType & target = static_cast< BaseType & >( *this ); + MyInserter myInserter = ::std::back_inserter( target ); + ::std::copy( temp.begin(), temp.end(), myInserter ); } AssocVector& operator=(const AssocVector& rhs)