referent_storage.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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>
  8. # include <boost/type_traits/aligned_storage.hpp>
  9. # include <cstddef>
  10. namespace boost { namespace python { namespace detail {
  11. template <std::size_t size, std::size_t alignment = std::size_t(-1)>
  12. struct aligned_storage
  13. {
  14. union type
  15. {
  16. typename ::boost::aligned_storage<size, alignment>::type data;
  17. char bytes[size];
  18. };
  19. };
  20. // Compute the size of T's referent. We wouldn't need this at all,
  21. // but sizeof() is broken in CodeWarriors <= 8.0
  22. template <class T> struct referent_size;
  23. template <class T>
  24. struct referent_size<T&>
  25. {
  26. BOOST_STATIC_CONSTANT(
  27. std::size_t, value = sizeof(T));
  28. };
  29. // A metafunction returning a POD type which can store U, where T ==
  30. // U&. If T is not a reference type, returns a POD which can store T.
  31. template <class T>
  32. struct referent_storage
  33. {
  34. typedef typename aligned_storage<referent_size<T>::value, alignment_of<T>::value>::type type;
  35. };
  36. }}} // namespace boost::python::detail
  37. #endif // REFERENT_STORAGE_DWA200278_HPP