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]

PODs vs memset


Hi everyone, hi Gaby,

while quickly adapting valarray to use the front-end __is_pod instead of the library version (otherwise it didn't compile), I adjusted this code in valarray:

 template<typename _Tp>
   struct _Array_default_ctor<_Tp, true>
   {
     // For fundamental types, it suffices to say 'memset()'
     inline static void
     _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
     { std::memset(__b, 0, (__e - __b) * sizeof(_Tp)); }
   };

template<typename _Tp>
inline void
__valarray_default_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
{
_Array_default_ctor<_Tp, __is_pod(_Tp)>::_S_do_it(__b, __e);
}


I think you (Gaby) made sure the latter scheme worked fine with the message:

http://gcc.gnu.org/ml/gcc/2005-12/msg00266.html

Now however the problem is that __is_pod actually establishes POD-ness, not just a weak subset of it (basically only scalars), therefore wanted to double check with you that the positive result of that thread also holds for all POD types. Depending on the answer I will either:

1- To be safe, change valarray to use a library-based __is_scalar or whatelse you would suggest.
2- Do not further change valarray and instead think about improving stl_algobase.h / stl_uninitialized.h / maybe the containers (I have to see) consistently with the above, thus always using memset (zero) for default-construction of POD types.


Thanks,
Paolo.


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