You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.1 KiB

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