//Excerpt from the header file (version 3). #include //for memmove class __dont_care {}; class __true: public __dont_care {}; class __false: public __dont_care {}; template class __traits { public: typedef __false memmovable; }; //Specializations: one for each built-in type template <> class __traits { typedef __true memmovable; }; template <> class __traits { typedef __true memmovable; }; //etc. template inline OUTPUT __copy2(INPUT begin, INPUT end, OUTPUT result, input_iterator_tag) { cout << "input iterator\n"; for (; begin != end; ++begin, ++result) { *result = *begin; //(*result).operator=(*begin); } return result; } template inline OUTPUT __copy2(RANDOM begin, RANDOM end, OUTPUT result, random_access_iterator_tag) { cout << "random access iterator\n"; for (typename iterator_traits::difference_type n = end - begin; n > 0; --n) { *result = *begin; //(*result).operator=(*begin); ++begin; ++result; } return result; } template inline OUTPUT __copy1(INPUT begin, INPUT end, OUTPUT result, __dont_care) { return __copy2(begin, end, result, typename iterator_traits::iterator_category()); } template inline T *__copy1(T *begin, T *end, T* result, __true) { cout << "memmove\n"; memmove(result, begin, (end - begin) * sizeof(T)); return result + (end - begin); } template inline T *__copy1(const T *begin, const T *end, T* result, __true) { cout << "memmove\n"; memmove(result, begin, (end - begin) * sizeof(T)); return result + (end - begin); } template inline OUTPUT mycopy(INPUT begin, INPUT end, OUTPUT result) { typedef typename iterator_traits::value_type value_type; typedef typename __traits::memmovable memmovable; return __copy1(begin, end, result, memmovable()); }