in valarray.h I found that resize is always deleting the old array,
reallocating a new array and initialize to the value specified. The text book
(Stroustrup) indicates that only the newly allocated elements should be
initialized. In my case the array size was not changed but the array
reinitialized (bad code will be changed). I assume this has been corrected in
later versions. I solved the problem by putting the "destroy" and "fill" inside
the if block.
Regards,
Theo Bosman

  template <class _Tp>
    inline void
    valarray<_Tp>::resize (size_t __n, _Tp __c)
    {
      // This complication is so to make valarray<valarray<T> > work
      // even though it is not required by the standard.  Nobody should
      // be saying valarray<valarray<T> > anyway.  See the specs.

      __valarray_destroy_elements(_M_data, _M_data + _M_size);

      if (_M_size != __n)
        {
          __valarray_release_memory(_M_data);
          _M_size = __n;
          _M_data = __valarray_get_storage<_Tp>(__n); 
        }
          __valarray_fill_construct(_M_data, _M_data + __n, __c);
    }


-- 
           Summary: resize initializes whole array
           Product: gcc
           Version: 3.3.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: theo dot bosman at net dot HCC dot nl


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29688

Reply via email to