uintptr_type.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright 2003-2013 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/multi_index for library home page.
  7. */
  8. #ifndef BOOST_MULTI_INDEX_DETAIL_UINTPTR_TYPE_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_UINTPTR_TYPE_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  14. #include <boost/mpl/bool.hpp>
  15. namespace boost{
  16. namespace multi_index{
  17. namespace detail{
  18. /* has_uintptr_type is an MPL integral constant determining whether
  19. * there exists an unsigned integral type with the same size as
  20. * void *.
  21. * uintptr_type is such a type if has_uintptr is true, or unsigned int
  22. * otherwise.
  23. * Note that uintptr_type is more restrictive than C99 uintptr_t,
  24. * where an integral type with size greater than that of void *
  25. * would be conformant.
  26. */
  27. template<int N>struct uintptr_candidates;
  28. template<>struct uintptr_candidates<-1>{typedef unsigned int type;};
  29. template<>struct uintptr_candidates<0> {typedef unsigned int type;};
  30. template<>struct uintptr_candidates<1> {typedef unsigned short type;};
  31. template<>struct uintptr_candidates<2> {typedef unsigned long type;};
  32. #if defined(BOOST_HAS_LONG_LONG)
  33. template<>struct uintptr_candidates<3> {typedef boost::ulong_long_type type;};
  34. #else
  35. template<>struct uintptr_candidates<3> {typedef unsigned int type;};
  36. #endif
  37. #if defined(BOOST_HAS_MS_INT64)
  38. template<>struct uintptr_candidates<4> {typedef unsigned __int64 type;};
  39. #else
  40. template<>struct uintptr_candidates<4> {typedef unsigned int type;};
  41. #endif
  42. struct uintptr_aux
  43. {
  44. BOOST_STATIC_CONSTANT(int,index=
  45. sizeof(void*)==sizeof(uintptr_candidates<0>::type)?0:
  46. sizeof(void*)==sizeof(uintptr_candidates<1>::type)?1:
  47. sizeof(void*)==sizeof(uintptr_candidates<2>::type)?2:
  48. sizeof(void*)==sizeof(uintptr_candidates<3>::type)?3:
  49. sizeof(void*)==sizeof(uintptr_candidates<4>::type)?4:-1);
  50. BOOST_STATIC_CONSTANT(bool,has_uintptr_type=(index>=0));
  51. typedef uintptr_candidates<index>::type type;
  52. };
  53. typedef mpl::bool_<uintptr_aux::has_uintptr_type> has_uintptr_type;
  54. typedef uintptr_aux::type uintptr_type;
  55. } /* namespace multi_index::detail */
  56. } /* namespace multi_index */
  57. } /* namespace boost */
  58. #endif