]> git.cworth.org Git - vogl/blob - src/extlib/loki/include/loki/flex/flex_string_details.h
Initial vogl checkin
[vogl] / src / extlib / loki / include / loki / flex / flex_string_details.h
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>
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>
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;
42                         ++b;
43                 case 7:
44                         *b = c;
45                         ++b;
46                 case 6:
47                         *b = c;
48                         ++b;
49                 case 5:
50                         *b = c;
51                         ++b;
52                 case 4:
53                         *b = c;
54                         ++b;
55                 case 3:
56                         *b = c;
57                         ++b;
58                 case 2:
59                         *b = c;
60                         ++b;
61                 case 1:
62                         *b = c;
63                         ++b;
64                 }
65         }
66 }
67
68 template <class Pod>
69 inline void pod_move(const Pod *b, const Pod *e, Pod *d)
70 {
71         using namespace std;
72         memmove(d, b, (e - b) * sizeof(*b));
73 }
74
75 template <class Pod>
76 inline Pod *pod_copy(const Pod *b, const Pod *e, Pod *d)
77 {
78         const size_t s = e - b;
79         using namespace std;
80         memcpy(d, b, s * sizeof(*b));
81         return d + s;
82 }
83
84 template <typename T> struct get_unsigned
85 {
86         typedef T result;
87 };
88
89 template <> struct get_unsigned<char>
90 {
91         typedef unsigned char result;
92 };
93
94 template <> struct get_unsigned<signed char>
95 {
96         typedef unsigned char result;
97 };
98
99 template <> struct get_unsigned<short int>
100 {
101         typedef unsigned short int result;
102 };
103
104 template <> struct get_unsigned<int>
105 {
106         typedef unsigned int result;
107 };
108
109 template <> struct get_unsigned<long int>
110 {
111         typedef unsigned long int result;
112 };
113
114 enum Shallow {};
115 }
116
117 #endif // FLEX_STRING_DETAILS_INC_