1 ////////////////////////////////////////////////////////////////////////////////
2 // flex_string
3 // Copyright (c) 2001 by Andrei Alexandrescu
4 // Permission to use, copy, modify, distribute and sell this software for any
5 //     purpose is hereby granted without fee, provided that the above copyright
6 //     notice appear in all copies and that both that copyright notice and this
7 //     permission notice appear in supporting documentation.
8 // The author makes no representations about the
9 //     suitability of this software for any purpose. It is provided "as is"
10 //     without express or implied warranty.
11 ////////////////////////////////////////////////////////////////////////////////
12 
13 #ifndef FLEX_STRING_DETAILS_INC_
14 #define FLEX_STRING_DETAILS_INC_
15 
16 // $Id: flex_string_details.h 754 2006-10-17 19:59:11Z syntheticpp $
17 
18 
19 #include <memory>
20 
21 namespace flex_string_details
22 {
23     template <class InIt, class OutIt>
copy_n(InIt b,typename std::iterator_traits<InIt>::difference_type n,OutIt d)24     OutIt copy_n(InIt b, typename std::iterator_traits<InIt>::difference_type n, OutIt d)
25     {
26         for (; n != 0; --n, ++b, ++d)
27         {
28             *d = *b;
29         }
30         return d;
31     }
32 
33     template <class Pod, class T>
pod_fill(Pod * b,Pod * e,T c)34     inline void pod_fill(Pod* b, Pod* e, T c)
35     {
36         switch ((e - b) & 7)
37         {
38         case 0:
39             while (b != e)
40             {
41                 *b = c; ++b;
42         case 7: *b = c; ++b;
43         case 6: *b = c; ++b;
44         case 5: *b = c; ++b;
45         case 4: *b = c; ++b;
46         case 3: *b = c; ++b;
47         case 2: *b = c; ++b;
48         case 1: *b = c; ++b;
49             }
50         }
51     }
52 
53     template <class Pod>
pod_move(const Pod * b,const Pod * e,Pod * d)54     inline void pod_move(const Pod* b, const Pod* e, Pod* d)
55     {
56         using namespace std;
57         memmove(d, b, (e - b) * sizeof(*b));
58     }
59 
60     template <class Pod>
pod_copy(const Pod * b,const Pod * e,Pod * d)61     inline Pod* pod_copy(const Pod* b, const Pod* e, Pod* d)
62     {
63         const size_t s = e - b;
64         using namespace std;
65         memcpy(d, b, s * sizeof(*b));
66         return d + s;
67     }
68 
69     template <typename T> struct get_unsigned
70     {
71         typedef T result;
72     };
73 
74     template <> struct get_unsigned<char>
75     {
76         typedef unsigned char result;
77     };
78 
79     template <> struct get_unsigned<signed char>
80     {
81         typedef unsigned char result;
82     };
83 
84     template <> struct get_unsigned<short int>
85     {
86         typedef unsigned short int result;
87     };
88 
89     template <> struct get_unsigned<int>
90     {
91         typedef unsigned int result;
92     };
93 
94     template <> struct get_unsigned<long int>
95     {
96         typedef unsigned long int result;
97     };
98 
99     enum Shallow {};
100 }
101 
102 #endif // FLEX_STRING_DETAILS_INC_
103