Squid Web Cache master
Loading...
Searching...
No Matches
FlexibleArray.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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_SRC_IPC_MEM_FLEXIBLEARRAY_H
10#define SQUID_SRC_IPC_MEM_FLEXIBLEARRAY_H
11
12#include <cstddef>
13#include <new>
14
15namespace Ipc
16{
17
18namespace Mem
19{
20
25template <class Item>
27{
28public:
29 explicit FlexibleArray(const int capacity) {
30 new (raw()) Item[capacity];
31 }
32
33 Item &operator [](const int idx) { return *(raw() + idx); }
34
35 Item *raw() { return reinterpret_cast<Item*>(&start_); }
36
37private:
38 alignas(Item) std::byte start_;
39};
40
41} // namespace Mem
42
43} // namespace Ipc
44
45#endif /* SQUID_SRC_IPC_MEM_FLEXIBLEARRAY_H */
46
Item & operator[](const int idx)
std::byte start_
the first byte of the first array item
FlexibleArray(const int capacity)
Memory Management.
Definition Allocator.h:17