williamr@4
|
1 |
/*
|
williamr@4
|
2 |
* Copyright (c) 2005
|
williamr@4
|
3 |
* Francois Dumont
|
williamr@4
|
4 |
*
|
williamr@4
|
5 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
6 |
* or implied. Any use is at your own risk.
|
williamr@4
|
7 |
*
|
williamr@4
|
8 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
9 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
10 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
11 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
12 |
* modified is included with the above copyright notice.
|
williamr@4
|
13 |
*
|
williamr@4
|
14 |
*/
|
williamr@4
|
15 |
|
williamr@4
|
16 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@4
|
17 |
* You should not attempt to use it directly.
|
williamr@4
|
18 |
*/
|
williamr@4
|
19 |
|
williamr@4
|
20 |
#ifndef _STLP_CARRAY_H
|
williamr@4
|
21 |
#define _STLP_CARRAY_H
|
williamr@4
|
22 |
|
williamr@4
|
23 |
/* Purpose: Mimic a pur C array with the additionnal feature of
|
williamr@4
|
24 |
* being able to be used with type not default constructible.
|
williamr@4
|
25 |
*/
|
williamr@4
|
26 |
|
williamr@4
|
27 |
#ifndef _STLP_INTERNAL_CONSTRUCT_H
|
williamr@4
|
28 |
# include <stl/_construct.h>
|
williamr@4
|
29 |
#endif
|
williamr@4
|
30 |
|
williamr@4
|
31 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
32 |
|
williamr@4
|
33 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
34 |
|
williamr@4
|
35 |
template <class _Tp, size_t _Nb>
|
williamr@4
|
36 |
struct _CArray {
|
williamr@4
|
37 |
_CArray (const _Tp& __val) {
|
williamr@4
|
38 |
for (size_t __i = 0; __i < _Nb; ++__i) {
|
williamr@4
|
39 |
_Copy_Construct(__REINTERPRET_CAST(_Tp*, _M_data + __i * sizeof(_Tp)), __val);
|
williamr@4
|
40 |
}
|
williamr@4
|
41 |
}
|
williamr@4
|
42 |
|
williamr@4
|
43 |
~_CArray() {
|
williamr@4
|
44 |
_Destroy_Range(__REINTERPRET_CAST(_Tp*, _M_data + 0),
|
williamr@4
|
45 |
__REINTERPRET_CAST(_Tp*, _M_data + _Nb * sizeof(_Tp)));
|
williamr@4
|
46 |
}
|
williamr@4
|
47 |
|
williamr@4
|
48 |
_Tp& operator [] (size_t __i) {
|
williamr@4
|
49 |
_STLP_ASSERT(__i < _Nb)
|
williamr@4
|
50 |
return *__REINTERPRET_CAST(_Tp*, _M_data + __i * sizeof(_Tp));
|
williamr@4
|
51 |
}
|
williamr@4
|
52 |
|
williamr@4
|
53 |
private:
|
williamr@4
|
54 |
char _M_data[sizeof(_Tp) * _Nb];
|
williamr@4
|
55 |
};
|
williamr@4
|
56 |
|
williamr@4
|
57 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
58 |
|
williamr@4
|
59 |
_STLP_END_NAMESPACE
|
williamr@4
|
60 |
|
williamr@4
|
61 |
#endif //_STLP_CARRAY_H
|