Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:43:19

0001 // Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
0002 // Copyright (C) 2016 Andrzej Krzemienski.
0003 //
0004 // Use, modification, and distribution is subject to the Boost Software
0005 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // See http://www.boost.org/libs/optional for documentation.
0009 //
0010 // You are welcome to contact the author at:
0011 //  fernando_cacciola@hotmail.com
0012 //  akrzemi1@gmail.com
0013 
0014 #ifndef BOOST_OPTIONAL_OPTIONAL_DETAIL_OPTIONAL_ALIGNED_STORAGE_AJK_12FEB2016_HPP
0015 #define BOOST_OPTIONAL_OPTIONAL_DETAIL_OPTIONAL_ALIGNED_STORAGE_AJK_12FEB2016_HPP
0016 
0017 namespace boost {
0018 
0019 namespace optional_detail {
0020 // This local class is used instead of that in "aligned_storage.hpp"
0021 // because I've found the 'official' class to ICE BCB5.5
0022 // when some types are used with optional<>
0023 // (due to sizeof() passed down as a non-type template parameter)
0024 template <class T>
0025 class aligned_storage
0026 {
0027     // Borland ICEs if unnamed unions are used for this!
0028     // BOOST_MAY_ALIAS works around GCC warnings about breaking strict aliasing rules when casting storage address to T*
0029     union BOOST_MAY_ALIAS dummy_u
0030     {
0031         unsigned char data[ sizeof(T) ];
0032         BOOST_DEDUCED_TYPENAME type_with_alignment<
0033           ::boost::alignment_of<T>::value >::type aligner_;
0034     } dummy_ ;
0035 
0036   public:
0037 
0038 #if defined(BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS)
0039     void const* address() const { return &dummy_; }
0040     void      * address()       { return &dummy_; }
0041 #else
0042     void const* address() const { return dummy_.data; }
0043     void      * address()       { return dummy_.data; }
0044 #endif
0045 
0046 #if defined(BOOST_OPTIONAL_DETAIL_USE_ATTRIBUTE_MAY_ALIAS)
0047     // This workaround is supposed to silence GCC warnings about broken strict aliasing rules
0048     T const* ptr_ref() const
0049     {
0050         union { void const* ap_pvoid; T const* as_ptype; } caster = { address() };
0051         return caster.as_ptype;
0052     }
0053     T *      ptr_ref()
0054     {
0055         union { void* ap_pvoid; T* as_ptype; } caster = { address() };
0056         return caster.as_ptype;
0057     }
0058 #else
0059     T const* ptr_ref() const { return static_cast<T const*>(address()); }
0060     T *      ptr_ref()       { return static_cast<T *>     (address()); }
0061 #endif
0062 
0063     T const& ref() const { return *ptr_ref(); }
0064     T &      ref()       { return *ptr_ref(); }
0065   
0066 } ;
0067 
0068 } // namespace optional_detail
0069 } // namespace boost
0070 
0071 #endif // header guard