I looked into GCC STL (4.6.1) and saw that std::copy() uses the optimized version if the built-in __is_trivial() is true .
Since the std::copy() and std::reverse_copy() patterns are very useful for copying elements in arrays, I would like to use them. However, I have several types (which are examples of template instances) that are structures that contain some trivial values, without pointers, and don't have a constructor or assignment operator.
Is g ++ smart enough to realize that my type is actually trivial? Is there a way in C ++ 98 to make sure that the STL implementation knows that my type is trivial?
I think that in C ++ 11 everything will become more convenient using a trait like is_trivial<> . Is it correct?
Thanks!
EDIT: Sorry to be so late, but here is an example of a fairly simple Type class that is not trivial for GCC and llvm. Any ideas?
#include <iostream> struct Spec; template <typename TValue, typename TSpec> class Type { public: TValue value; Type() : value(0) {} }; int main() { std::cerr << "__is_trivial(...) == " << __is_trivial(Type<char, Spec>) << '\n'; return 0; }
source share