1/*
2 Copyright 2005-2013 Intel Corporation. All Rights Reserved.
3
4 This file is part of Threading Building Blocks.
5
6 Threading Building Blocks is free software; you can redistribute it
7 and/or modify it under the terms of the GNU General Public License
8 version 2 as published by the Free Software Foundation.
9
10 Threading Building Blocks is distributed in the hope that it will be
11 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Threading Building Blocks; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 As a special exception, you may use this file as part of a free software
20 library without restriction. Specifically, if other files instantiate
21 templates or use macros or inline functions from this file, or you compile
22 this file and link it with other files to produce an executable, this
23 file does not by itself cause the resulting executable to be covered by
24 the GNU General Public License. This exception does not however
25 invalidate any other reasons why the executable file might be covered by
26 the GNU General Public License.
27*/
28
29#ifndef __TBB_aligned_space_H
30#define __TBB_aligned_space_H
31
32#include "tbb_stddef.h"
33#include "tbb_machine.h"
34
35namespace tbb {
36
37//! Block of space aligned sufficiently to construct an array T with N elements.
38/** The elements are not constructed or destroyed by this class.
39 @ingroup memory_allocation */
40template<typename T,size_t N>
41class aligned_space {
42private:
43 typedef __TBB_TypeWithAlignmentAtLeastAsStrict(T) element_type;
44 element_type array[(sizeof(T)*N+sizeof(element_type)-1)/sizeof(element_type)];
45public:
46 //! Pointer to beginning of array
47 T* begin() {return internal::punned_cast<T*>(this);}
48
49 //! Pointer to one past last element in array.
50 T* end() {return begin()+N;}
51};
52
53} // namespace tbb
54
55#endif /* __TBB_aligned_space_H */
56