void_ptr.hpp 982 B

1234567891011121314151617181920212223242526272829303132333435
  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 VOID_PTR_DWA200239_HPP
  6. # define VOID_PTR_DWA200239_HPP
  7. # include <boost/python/detail/type_traits.hpp>
  8. namespace boost { namespace python { namespace detail {
  9. template <class U>
  10. inline U& void_ptr_to_reference(void const volatile* p, U&(*)())
  11. {
  12. return *(U*)p;
  13. }
  14. template <class T>
  15. inline void write_void_ptr(void const volatile* storage, void* ptr, T*)
  16. {
  17. *(T**)storage = (T*)ptr;
  18. }
  19. // writes U(ptr) into the storage
  20. template <class U>
  21. inline void write_void_ptr_reference(void const volatile* storage, void* ptr, U&(*)())
  22. {
  23. // stripping CV qualification suppresses warnings on older EDGs
  24. typedef typename remove_cv<U>::type u_stripped;
  25. write_void_ptr(storage, ptr, u_stripped(0));
  26. }
  27. }}} // namespace boost::python::detail
  28. #endif // VOID_PTR_DWA200239_HPP