📄 l3_array.h
字号:
#ifndef _INCLUDED_L3_ARRAY_H#define _INCLUDED_L3_ARRAY_H// Copyright (C) Krzysztof Bosak, 1999-07-22...2001-01-10.// All rights reserved.// kbosak@box43.pl// http://www.kbosak.prv.pl// *Automatic Safe Arrays*// Content: autoarray, basearray, basearray_s/*WARNING: STL's clear() sets container's size to 0. L3's clear() behaves as its STL counterpart.Alternative naming conventions would be used:setsize => newsize, change_sizesize => dim, lengthThe three levels of exception safety:A. NOTHROW (EXTREME): guaranteed to not throw any exceptions.B. EXCEPTION NEUTRAL (STRONG): in case of error might throw itself. Will propagate all exceptions to the caller.C. EXCEPTION SAFE (BASIC): no resources leak guaranteed, but after an exception may leave container partially changed.*//*// Advanced, complex tests with STL (numerical OO realtime code of 13000 lines):// Replaced autoarray/basearray/basearray_s with std::vector<>.// gcc: larger +30KB (up to 250KB) executable size, equal speed.// msvc: +10% slower, larger +8KB (up to 148KB) executable size.// kcc: same speed, same size (420KB).// bcc: simply much slower than with autoarray/basearray.// And completely no access control + slightly longer compilation time.// And lots of Level4 warnings with msvc6.// With std::valarray<> gave even worse results.#include <vector>template <class type>class autoarray: public std::vector<type>{public: inline autoarray() { } inline explicit autoarray(int len) : std::vector<type>(len) { } inline void setsize(int len) { resize(0); reserve(len); resize(len); }};template <class type>class basearray: public autoarray<type>{public: inline basearray() { } inline explicit basearray(int len) : autoarray<type>(len) { } inline void fill(const type& value) { const int imax=size(); for(int i=0; i<imax; i++) operator[](i)=value; } inline void erase() { fill(0); }};#define basearray_s basearray*//////////////////////////////////////////////////////////////////////////////#include <string.h>#include <limits.h>#ifdef USE_ARRAY_EXCEPTIONS #include "l3_arrex.h"#endif#include "l3_array_common.h"#include "l3_array_auto.h"#include "l3_array_base.h"#include "l3_array_base_s.h"/////////////////////////////////////////////////////////////////////////////#ifdef USE_ARRAY_EXCEPTIONS#undef USE_ARRAY_EXCEPTIONS#endif#ifdef USE_RANDOMIZED_GARBAGE_FILL#undef USE_RANDOMIZED_GARBAGE_FILL#endif#ifdef _GarbageFillLoop#undef _GarbageFillLoop#endif#undef MEMORY_ALLOCATION_TEST#undef SENTINEL_TEST/////////////////////////////////////////////////////////////////////////////#endif //_INCLUDED_L3_ARRAY_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -