Change signature of operator new in FlexArray
[openttd/fttd.git] / src / core / flexarray.h
blob87fa6e38c2101c49c492dbf83181f64d1407a242
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file flexarray.h Flexible array support. */
10 #ifndef FLEXARRAY_H
11 #define FLEXARRAY_H
13 /** Flexible array base struct to delete several methods. */
14 struct FlexArrayBase {
15 protected:
16 FlexArrayBase (void)
20 private:
21 FlexArrayBase (const FlexArrayBase &) DELETED;
23 FlexArrayBase & operator = (const FlexArrayBase &) DELETED;
25 void *operator new (size_t size) DELETED;
28 /** Flexible array base struct to provide custom operator new. */
29 template <typename T>
30 struct FlexArray : FlexArrayBase {
31 protected:
32 /** Custom operator new to account for the variable-length buffer. */
33 void *operator new (size_t size, size_t extra1, size_t extra2 = 1)
35 return ::operator new (size + extra1 * extra2 * sizeof(T));
39 #endif /* FLEXARRAY_H */