From: <ric...@us...> - 2011-09-30 23:16:14
|
Revision: 1127 http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1127&view=rev Author: rich_sposato Date: 2011-09-30 23:16:08 +0000 (Fri, 30 Sep 2011) Log Message: ----------- Fixed bug 3388381 by changing ctor body. Modified Paths: -------------- trunk/include/loki/AssocVector.h Modified: trunk/include/loki/AssocVector.h =================================================================== --- trunk/include/loki/AssocVector.h 2011-09-30 23:14:41 UTC (rev 1126) +++ trunk/include/loki/AssocVector.h 2011-09-30 23:16:08 UTC (rev 1127) @@ -33,7 +33,10 @@ #include <functional> #include <vector> #include <utility> +#include <iterator> +#include <map> + namespace Loki { //////////////////////////////////////////////////////////////////////////////// @@ -144,10 +147,18 @@ 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) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |