How to check whether or not C++ type is trivially copyable? I have a class, which uses memcpy and memcmp functions with specified template type T and I would like to fire assert for types, that are not safe to copy with memcpy. Is there any way to do that (with existing standard)?
No, not possible in C++98/C++03. Things like this are why
<type_traits>
was added to C++0x. Some of the features from<type_traits>
can be implemented in C++03, often using the SFINAE principle, but several, includingstd::is_trivially_copyable<T>
, will simply require built-in compiler support.