Traits文档boost的写的比较好
http://www.boost.org/doc/libs/1_42_0/libs/type_traits/doc/html/index.html
// GCC's libstdc++ 20070724 and later supports C++ TR1 type_traits in the std namespace.
// VC10 (VS2010) and later support C++ TR1 type_traits in the std::tr1 namespace.
//
// opt::copy
// same semantics as std::copy
// calls memcpy where appropriate.
//
namespace detail{
template
I2 copy_imp(I1 first, I1 last, I2 out, const boost::integral_constant
{
while(first != last)
{
*out = *first;
++out;
++first;
}
return out;
}
template
T* copy_imp(const T* first, const T* last, T* out, const boost::true_type&)
{
memcpy(out, first, (last-first)*sizeof(T));
return out+(last-first);
}
}
template
inline I2 copy(I1 first, I1 last, I2 out)
{
//
// We can copy with memcpy if T has a trivial assignment operator,
// and if the iterator arguments are actually pointers (this last
// requirement we detect with overload resolution):
//
typedef typename std::iterator_traits
return detail::copy_imp(first, last, out, boost::has_trivial_assign
}
About typeStraits
Apr202010
Subscribe to:
Post Comments (Atom)
0 评论: (+add yours?)
Post a Comment