1 | /* |
2 | Copyright (c) 2005-2021 Intel Corporation |
3 | |
4 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | you may not use this file except in compliance with the License. |
6 | You may obtain a copy of the License at |
7 | |
8 | http://www.apache.org/licenses/LICENSE-2.0 |
9 | |
10 | Unless required by applicable law or agreed to in writing, software |
11 | distributed under the License is distributed on an "AS IS" BASIS, |
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | See the License for the specific language governing permissions and |
14 | limitations under the License. |
15 | */ |
16 | #ifndef __TBB_aligned_space_H |
17 | #define __TBB_aligned_space_H |
18 | |
19 | #include <cstddef> |
20 | |
21 | #include "_template_helpers.h" |
22 | |
23 | namespace tbb { |
24 | namespace detail { |
25 | inline namespace d0 { |
26 | |
27 | //! Block of space aligned sufficiently to construct an array T with N elements. |
28 | /** The elements are not constructed or destroyed by this class. |
29 | @ingroup memory_allocation */ |
30 | template<typename T, std::size_t N = 1> |
31 | class aligned_space { |
32 | alignas(alignof(T)) std::uint8_t aligned_array[N * sizeof(T)]; |
33 | |
34 | public: |
35 | //! Pointer to beginning of array |
36 | T* begin() const { return punned_cast<T*>(&aligned_array); } |
37 | |
38 | //! Pointer to one past last element in array. |
39 | T* end() const { return begin() + N; } |
40 | }; |
41 | |
42 | } // namespace d0 |
43 | } // namespace detail |
44 | } // namespace tbb |
45 | |
46 | #endif /* __TBB_aligned_space_H */ |
47 | |