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