]> git.lyx.org Git - lyx.git/blob - boost/boost/aligned_storage.hpp
Fixed some lines that were too long. It compiled afterwards.
[lyx.git] / boost / boost / aligned_storage.hpp
1 //-----------------------------------------------------------------------------
2 // boost aligned_storage.hpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
5 //
6 // Copyright (c) 2002-2003
7 // Eric Friedman, Itay Maman
8 //
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12
13 #ifndef BOOST_ALIGNED_STORAGE_HPP
14 #define BOOST_ALIGNED_STORAGE_HPP
15
16 #include <cstddef> // for std::size_t
17
18 #include "boost/config.hpp"
19 #include "boost/detail/workaround.hpp"
20 #include "boost/type_traits/alignment_of.hpp"
21 #include "boost/type_traits/type_with_alignment.hpp"
22 #include "boost/type_traits/is_pod.hpp"
23
24 #include "boost/mpl/eval_if.hpp"
25 #include "boost/mpl/identity.hpp"
26
27 #include "boost/type_traits/detail/bool_trait_def.hpp"
28
29 namespace boost {
30
31 namespace detail { namespace aligned_storage {
32
33 BOOST_STATIC_CONSTANT(
34       std::size_t
35     , alignment_of_max_align = ::boost::alignment_of<max_align>::value
36     );
37
38 //
39 // To be TR1 conforming this must be a POD type:
40 //
41 template <
42       std::size_t size_
43     , std::size_t alignment_
44 >
45 struct aligned_storage_imp
46 {
47     union data_t
48     {
49         char buf[size_];
50
51         typename mpl::eval_if_c<
52               alignment_ == std::size_t(-1)
53             , mpl::identity<detail::max_align>
54             , type_with_alignment<alignment_>
55             >::type align_;
56     } data_;
57 };
58
59 }} // namespace detail::aligned_storage
60
61 template <
62       std::size_t size_
63     , std::size_t alignment_ = std::size_t(-1)
64 >
65 class aligned_storage
66 {
67 private: // representation
68
69    detail::aligned_storage::aligned_storage_imp<size_, alignment_> data_;
70
71 public: // constants
72
73     typedef detail::aligned_storage::aligned_storage_imp<size_, alignment_> type;
74
75     BOOST_STATIC_CONSTANT(
76           std::size_t
77         , size = size_
78         );
79     BOOST_STATIC_CONSTANT(
80           std::size_t
81         , alignment = (
82               alignment_ == std::size_t(-1)
83             ? ::boost::detail::aligned_storage::alignment_of_max_align
84             : alignment_
85             )
86         );
87
88 #if defined(__GNUC__) &&\
89     (__GNUC__ >  3) ||\
90     (__GNUC__ == 3 && (__GNUC_MINOR__ >  2 ||\
91                       (__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ >=3)))
92
93 private: // noncopyable
94
95     aligned_storage(const aligned_storage&);
96     aligned_storage& operator=(const aligned_storage&);
97
98 #else // gcc less than 3.2.3
99
100 public: // _should_ be noncopyable, but GCC compiler emits error
101
102     aligned_storage(const aligned_storage&);
103     aligned_storage& operator=(const aligned_storage&);
104
105 #endif // gcc < 3.2.3 workaround
106
107 public: // structors
108
109     aligned_storage()
110     {
111     }
112
113     ~aligned_storage()
114     {
115     }
116
117 public: // accessors
118
119     void* address()
120     {
121         return this;
122     }
123
124 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
125
126     const void* address() const
127     {
128         return this;
129     }
130
131 #else // MSVC6
132
133     const void* address() const;
134
135 #endif // MSVC6 workaround
136
137 };
138
139 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
140
141 // MSVC6 seems not to like inline functions with const void* returns, so we
142 // declare the following here:
143
144 template <std::size_t S, std::size_t A>
145 const void* aligned_storage<S,A>::address() const
146 {
147     return const_cast< aligned_storage<S,A>* >(this)->address();
148 }
149
150 #endif // MSVC6 workaround
151
152 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
153 //
154 // Make sure that is_pod recognises aligned_storage<>::type
155 // as a POD (Note that aligned_storage<> itself is not a POD):
156 //
157 template <std::size_t size_, std::size_t alignment_>
158 struct is_pod<boost::detail::aligned_storage::aligned_storage_imp<size_,alignment_> >
159    BOOST_TT_AUX_BOOL_C_BASE(true)
160
161     BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(true)
162 }; 
163 #endif
164
165
166 } // namespace boost
167
168 #include "boost/type_traits/detail/bool_trait_undef.hpp"
169
170 #endif // BOOST_ALIGNED_STORAGE_HPP