I looked into the GCC STL (4.6.1) and saw that std::copy()
uses an optimized version in case the builtin __is_trivial()
evaluates to true
.
Since the std::copy()
and std::reverse_copy()
templates are very useful for copying elements in arrays, I would like to use them. However, I have some types (which are results of template instantiations) that are structs that contain some trivial values, no pointers and have no copy constructor or assignment operator.
Is G++ smart enough to figure out that my type in fact is trivial? Is there any way in C++98 to make sure an STL implementation knows that my type is trivial?
I guess that in C++11, things will become convenient using the is_trivial<>
type trait. Is this right?
Thanks!
EDIT: Sorry for being so late with this, but here is an example of a pretty simple Type
class that is not trivial to 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;
}