|
libstdc++
|
00001 // Aligned memory buffer -*- C++ -*- 00002 00003 // Copyright (C) 2013-2015 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file ext/aligned_buffer.h 00026 * This file is a GNU extension to the Standard C++ Library. 00027 */ 00028 00029 #ifndef _ALIGNED_BUFFER_H 00030 #define _ALIGNED_BUFFER_H 1 00031 00032 #pragma GCC system_header 00033 00034 #if __cplusplus >= 201103L 00035 # include <type_traits> 00036 #else 00037 # include <bits/c++0x_warning.h> 00038 #endif 00039 00040 namespace __gnu_cxx 00041 { 00042 template<typename _Tp> 00043 struct __aligned_buffer 00044 : std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value> 00045 { 00046 typename 00047 std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value>::type 00048 _M_storage; 00049 00050 __aligned_buffer() = default; 00051 00052 // Can be used to avoid value-initialization 00053 __aligned_buffer(std::nullptr_t) { } 00054 00055 void* 00056 _M_addr() noexcept 00057 { 00058 return static_cast<void*>(&_M_storage); 00059 } 00060 00061 const void* 00062 _M_addr() const noexcept 00063 { 00064 return static_cast<const void*>(&_M_storage); 00065 } 00066 00067 _Tp* 00068 _M_ptr() noexcept 00069 { return static_cast<_Tp*>(_M_addr()); } 00070 00071 const _Tp* 00072 _M_ptr() const noexcept 00073 { return static_cast<const _Tp*>(_M_addr()); } 00074 }; 00075 00076 } // namespace 00077 00078 #endif /* _ALIGNED_BUFFER_H */