cast_storage.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //-----------------------------------------------------------------------------
  2. // boost variant/detail/cast_storage.hpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2003
  7. // Eric Friedman
  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. #ifndef BOOST_VARIANT_DETAIL_CAST_STORAGE_HPP
  13. #define BOOST_VARIANT_DETAIL_CAST_STORAGE_HPP
  14. #include "boost/config.hpp"
  15. namespace boost {
  16. namespace detail { namespace variant {
  17. ///////////////////////////////////////////////////////////////////////////////
  18. // (detail) function template cast_storage
  19. //
  20. // Casts the given storage to the specified type, but with qualification.
  21. //
  22. template <typename T>
  23. inline T& cast_storage(
  24. void* storage
  25. BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)
  26. )
  27. {
  28. return *static_cast<T*>(storage);
  29. }
  30. template <typename T>
  31. inline const T& cast_storage(
  32. const void* storage
  33. BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)
  34. )
  35. {
  36. return *static_cast<const T*>(storage);
  37. }
  38. }} // namespace detail::variant
  39. } // namespace boost
  40. #endif // BOOST_VARIANT_DETAIL_CAST_STORAGE_HPP