FlexibleArray.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_IPC_MEM_FLEXIBLE_ARRAY_H
10#define SQUID_IPC_MEM_FLEXIBLE_ARRAY_H
11
12// sometimes required for placement-new operator to be declared
13#include <new>
14
15namespace Ipc
16{
17
18namespace Mem
19{
20
25template <class Item>
27{
28public:
29 explicit FlexibleArray(const int capacity) {
30 if (capacity > 1) // the first item is initialized automatically
31 new (raw()+1) Item[capacity-1];
32 }
33
34 Item &operator [](const int idx) { return items[idx]; }
35 const Item &operator [](const int idx) const { return items[idx]; }
36
37 //const Item *operator ()() const { return items; }
38 //Item *operator ()() { return items; }
39
40 Item *raw() { return items; }
41
42private:
43 Item items[1]; // ensures proper alignment of array elements
44};
45
46} // namespace Mem
47
48} // namespace Ipc
49
50#endif /* SQUID_IPC_MEM_FLEXIBLE_ARRAY_H */
51
Item & operator[](const int idx)
Definition: FlexibleArray.h:34
FlexibleArray(const int capacity)
Definition: FlexibleArray.h:29
Definition: IpcIoFile.h:24
Memory Management.

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors