Can I memcpy() any type which has a trivial destructor?

前端 未结 4 1077
感情败类
感情败类 2021-02-20 17:02

I do realize is_pod is a sufficient condition for a type to be memcpy-able, but is has_trivial_destructor also sufficien

4条回答
  •  醉梦人生
    2021-02-20 17:43

    It is not sufficient that an object has a trivial destructor. It also needs to have trivial copy operations. The object may maintain pointers to internal buffers, for example. There is no need to destroy anything but copying would need to set up the pointers in the copied to object because they would otherwise point into the buffer of the source object.

提交回复
热议问题