1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef REFERENT_STORAGE_DWA200278_HPP
6 # define REFERENT_STORAGE_DWA200278_HPP
7 # include <boost/mpl/if.hpp>
10 namespace boost { namespace python { namespace detail {
12 struct alignment_dummy;
13 typedef void (*function_ptr)();
14 typedef int (alignment_dummy::*member_ptr);
15 typedef int (alignment_dummy::*member_function_ptr)();
17 # define BOOST_PYTHON_ALIGNER(T, n) \
19 sizeof(T) <= size, T, char>::type t##n
21 // Storage for size bytes, aligned to all fundamental types no larger than size
22 template <std::size_t size>
25 BOOST_PYTHON_ALIGNER(char, 0);
26 BOOST_PYTHON_ALIGNER(short, 1);
27 BOOST_PYTHON_ALIGNER(int, 2);
28 BOOST_PYTHON_ALIGNER(long, 3);
29 BOOST_PYTHON_ALIGNER(float, 4);
30 BOOST_PYTHON_ALIGNER(double, 5);
31 BOOST_PYTHON_ALIGNER(long double, 6);
32 BOOST_PYTHON_ALIGNER(void*, 7);
33 BOOST_PYTHON_ALIGNER(function_ptr, 8);
34 BOOST_PYTHON_ALIGNER(member_ptr, 9);
35 BOOST_PYTHON_ALIGNER(member_function_ptr, 10);
39 # undef BOOST_PYTHON_ALIGNER
41 // Compute the size of T's referent. We wouldn't need this at all,
42 // but sizeof() is broken in CodeWarriors <= 8.0
43 template <class T> struct referent_size;
47 struct referent_size<T&>
49 BOOST_STATIC_CONSTANT(
50 std::size_t, value = sizeof(T));
54 // A metafunction returning a POD type which can store U, where T ==
55 // U&. If T is not a reference type, returns a POD which can store T.
57 struct referent_storage
59 typedef aligned_storage<
60 ::boost::python::detail::referent_size<T>::value
64 }}} // namespace boost::python::detail
66 #endif // REFERENT_STORAGE_DWA200278_HPP