1951a39d68df598db08dfced8b4707755864a0492Ying Wang/* 2951a39d68df598db08dfced8b4707755864a0492Ying Wang * Copyright (c) 2005 3951a39d68df598db08dfced8b4707755864a0492Ying Wang * Francois Dumont 4951a39d68df598db08dfced8b4707755864a0492Ying Wang * 5951a39d68df598db08dfced8b4707755864a0492Ying Wang * This material is provided "as is", with absolutely no warranty expressed 6951a39d68df598db08dfced8b4707755864a0492Ying Wang * or implied. Any use is at your own risk. 7951a39d68df598db08dfced8b4707755864a0492Ying Wang * 8951a39d68df598db08dfced8b4707755864a0492Ying Wang * Permission to use or copy this software for any purpose is hereby granted 9951a39d68df598db08dfced8b4707755864a0492Ying Wang * without fee, provided the above notices are retained on all copies. 10951a39d68df598db08dfced8b4707755864a0492Ying Wang * Permission to modify the code and to distribute modified code is granted, 11951a39d68df598db08dfced8b4707755864a0492Ying Wang * provided the above notices are retained, and a notice that the code was 12951a39d68df598db08dfced8b4707755864a0492Ying Wang * modified is included with the above copyright notice. 13951a39d68df598db08dfced8b4707755864a0492Ying Wang * 14951a39d68df598db08dfced8b4707755864a0492Ying Wang */ 15951a39d68df598db08dfced8b4707755864a0492Ying Wang 16951a39d68df598db08dfced8b4707755864a0492Ying Wang/* NOTE: This is an internal header file, included by other STL headers. 17951a39d68df598db08dfced8b4707755864a0492Ying Wang * You should not attempt to use it directly. 18951a39d68df598db08dfced8b4707755864a0492Ying Wang */ 19951a39d68df598db08dfced8b4707755864a0492Ying Wang 20951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifndef _STLP_CARRAY_H 21951a39d68df598db08dfced8b4707755864a0492Ying Wang#define _STLP_CARRAY_H 22951a39d68df598db08dfced8b4707755864a0492Ying Wang 23951a39d68df598db08dfced8b4707755864a0492Ying Wang/* Purpose: Mimic a pur C array with the additionnal feature of 24951a39d68df598db08dfced8b4707755864a0492Ying Wang * being able to be used with type not default constructible. 25951a39d68df598db08dfced8b4707755864a0492Ying Wang */ 26951a39d68df598db08dfced8b4707755864a0492Ying Wang 27951a39d68df598db08dfced8b4707755864a0492Ying Wang#ifndef _STLP_INTERNAL_CONSTRUCT_H 28951a39d68df598db08dfced8b4707755864a0492Ying Wang# include <stl/_construct.h> 29951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif 30951a39d68df598db08dfced8b4707755864a0492Ying Wang 31951a39d68df598db08dfced8b4707755864a0492Ying Wang_STLP_BEGIN_NAMESPACE 32951a39d68df598db08dfced8b4707755864a0492Ying Wang 33951a39d68df598db08dfced8b4707755864a0492Ying Wang_STLP_MOVE_TO_PRIV_NAMESPACE 34951a39d68df598db08dfced8b4707755864a0492Ying Wang 35951a39d68df598db08dfced8b4707755864a0492Ying Wangtemplate <class _Tp, size_t _Nb> 36951a39d68df598db08dfced8b4707755864a0492Ying Wangstruct _CArray { 37951a39d68df598db08dfced8b4707755864a0492Ying Wang _CArray (const _Tp& __val) { 38951a39d68df598db08dfced8b4707755864a0492Ying Wang for (size_t __i = 0; __i < _Nb; ++__i) { 39951a39d68df598db08dfced8b4707755864a0492Ying Wang _Copy_Construct(__REINTERPRET_CAST(_Tp*, _M_data + __i * sizeof(_Tp)), __val); 40951a39d68df598db08dfced8b4707755864a0492Ying Wang } 41951a39d68df598db08dfced8b4707755864a0492Ying Wang } 42951a39d68df598db08dfced8b4707755864a0492Ying Wang 43951a39d68df598db08dfced8b4707755864a0492Ying Wang ~_CArray() { 44951a39d68df598db08dfced8b4707755864a0492Ying Wang _Destroy_Range(__REINTERPRET_CAST(_Tp*, _M_data + 0), 45951a39d68df598db08dfced8b4707755864a0492Ying Wang __REINTERPRET_CAST(_Tp*, _M_data + _Nb * sizeof(_Tp))); 46951a39d68df598db08dfced8b4707755864a0492Ying Wang } 47951a39d68df598db08dfced8b4707755864a0492Ying Wang 48951a39d68df598db08dfced8b4707755864a0492Ying Wang _Tp& operator [] (size_t __i) { 49951a39d68df598db08dfced8b4707755864a0492Ying Wang _STLP_ASSERT(__i < _Nb) 50951a39d68df598db08dfced8b4707755864a0492Ying Wang return *__REINTERPRET_CAST(_Tp*, _M_data + __i * sizeof(_Tp)); 51951a39d68df598db08dfced8b4707755864a0492Ying Wang } 52951a39d68df598db08dfced8b4707755864a0492Ying Wang 53951a39d68df598db08dfced8b4707755864a0492Ying Wangprivate: 54951a39d68df598db08dfced8b4707755864a0492Ying Wang char _M_data[sizeof(_Tp) * _Nb]; 55951a39d68df598db08dfced8b4707755864a0492Ying Wang}; 56951a39d68df598db08dfced8b4707755864a0492Ying Wang 57951a39d68df598db08dfced8b4707755864a0492Ying Wang_STLP_MOVE_TO_STD_NAMESPACE 58951a39d68df598db08dfced8b4707755864a0492Ying Wang 59951a39d68df598db08dfced8b4707755864a0492Ying Wang_STLP_END_NAMESPACE 60951a39d68df598db08dfced8b4707755864a0492Ying Wang 61951a39d68df598db08dfced8b4707755864a0492Ying Wang#endif //_STLP_CARRAY_H 62