1 | /* |
2 | Copyright (c) 2005-2019 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 | |
17 | #ifndef __TBB_aligned_space_H |
18 | #define __TBB_aligned_space_H |
19 | |
20 | #include "tbb_stddef.h" |
21 | #include "tbb_machine.h" |
22 | |
23 | namespace tbb { |
24 | |
25 | //! Block of space aligned sufficiently to construct an array T with N elements. |
26 | /** The elements are not constructed or destroyed by this class. |
27 | @ingroup memory_allocation */ |
28 | template<typename T,size_t N=1> |
29 | class aligned_space { |
30 | private: |
31 | typedef __TBB_TypeWithAlignmentAtLeastAsStrict(T) element_type; |
32 | element_type array[(sizeof(T)*N+sizeof(element_type)-1)/sizeof(element_type)]; |
33 | public: |
34 | //! Pointer to beginning of array |
35 | T* begin() const {return internal::punned_cast<T*>(this);} |
36 | |
37 | //! Pointer to one past last element in array. |
38 | T* end() const {return begin()+N;} |
39 | }; |
40 | |
41 | } // namespace tbb |
42 | |
43 | #endif /* __TBB_aligned_space_H */ |
44 | |