libstdc++
aligned_buffer.h
Go to the documentation of this file.
00001 // Aligned memory buffer -*- C++ -*-
00002 
00003 // Copyright (C) 2013-2014 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       void*
00051       _M_addr() noexcept
00052       {
00053         return static_cast<void*>(&_M_storage);
00054       }
00055 
00056       const void*
00057       _M_addr() const noexcept
00058       {
00059         return static_cast<const void*>(&_M_storage);
00060       }
00061 
00062       _Tp*
00063       _M_ptr() noexcept
00064       { return static_cast<_Tp*>(_M_addr()); }
00065 
00066       const _Tp*
00067       _M_ptr() const noexcept
00068       { return static_cast<const _Tp*>(_M_addr()); }
00069     };
00070 
00071 } // namespace
00072 
00073 #endif /* _ALIGNED_BUFFER_H */