force_cast.hpp 998 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (C) 2001-2003
  2. // Mac Murrett
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org for most recent version including documentation.
  9. #ifndef BOOST_FORCE_CAST_MJM012402_HPP
  10. #define BOOST_FORCE_CAST_MJM012402_HPP
  11. #include <boost/thread/detail/config.hpp>
  12. namespace boost {
  13. namespace detail {
  14. namespace thread {
  15. // force_cast will convert anything to anything.
  16. // general case
  17. template<class Return_Type, class Argument_Type>
  18. inline Return_Type &force_cast(Argument_Type &rSrc)
  19. {
  20. return(*reinterpret_cast<Return_Type *>(&rSrc));
  21. }
  22. // specialization for const
  23. template<class Return_Type, class Argument_Type>
  24. inline const Return_Type &force_cast(const Argument_Type &rSrc)
  25. {
  26. return(*reinterpret_cast<const Return_Type *>(&rSrc));
  27. }
  28. } // namespace thread
  29. } // namespace detail
  30. } // namespace boost
  31. #endif // BOOST_FORCE_CAST_MJM012402_HPP