Can I safely move around a promotion option?

I have a class that carries a boost option that only contains memmovable types (QList, QString, int, etc.).

Can I declare that the wrapper class is memmovable for Qt containers?

+4
source share
2 answers

A boost::variant contains only the integral index and aligned_storage , which is guaranteed by the standard as a POD. It has no virtual members, but has user-defined constructors and a destructor. As a result, boost::variant not a POD and tries to memmove this to UB (well, I think it is UB, I did not find the final link in the standard).

However, the same can be said about QList , QString , etc. Obviously, Qt suggests that some non-POD types can be safely reproduced and distinguish between POD (so-called "primitive types") and "movable types".

Therefore, if you consider memmove QList safe, you can safely consider memmove boost::variant contain memmovable types.

+2
source

You probably know that memmoving non-POD types are technically undefined. As an aside, the option does not contain anything that would be problematic if it were perceived. Since you mention QList and QString as memmovable, and I hardly believe that they are PODs (although I haven't seen them), boost :: variant is no worse.

+1
source

Source: https://habr.com/ru/post/1416324/


All Articles