This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: About std::vector::resize().


On Wed, 2004-05-26 at 19:37, Carlo Wood wrote:
> On Wed, May 26, 2004 at 12:52:50PM +0200, Paolo Carlini wrote:
> > Agreed.
> > Are you going to actually implement this idea, at least a draft for 
> > comparison purposes? Or Carlo, perhaps?
> > 
> > Thanks,
> > Paolo.
> 
> Wouldn't this do the job?
> This patch replaces every invokation of uninitialized_copy that copies
> to a destination that is actually a just allocated (and relocated) memory,
> with __uninitialized_copy_swap.
> 
> The latter than still has to be implemented as something that fills
> the appropriate range with a default constructed value_type and
> then swaps that with each of the source elements in the range.

This should do the trick.

It's not exception safe, and stuff, but then again, how many times does
our default constructed vector throw ;-)


  template<typename _InputIterator, typename _ForwardIterator>
    inline _ForwardIterator
    __uninitialized_copy_swap(_InputIterator __first, _InputIterator
	__last, _ForwardIterator __result)
    {
      _ForwardIterator __cur = __result;
      typename 
	std::iterator_traits<_InputIterator>::value_type 
	__def_const;

      for ( ; __first != __last; ++__first, ++__cur)
      {
        std::_Construct(&*__cur, __def_const);
	__cur->swap(*__first);
      }
      return __cur;
    }





-- 
        -Dhruv Matani.
http://www.geocities.com/dhruvbird/

Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]