other.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef OTHER_DWA20020601_HPP
  2. # define OTHER_DWA20020601_HPP
  3. # include <boost/python/detail/prefix.hpp>
  4. // Copyright David Abrahams 2002.
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. # if _MSC_VER+0 >= 1020
  9. # pragma once
  10. # endif
  11. # include <boost/config.hpp>
  12. namespace boost { namespace python {
  13. template<class T> struct other
  14. {
  15. typedef T type;
  16. };
  17. # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  18. namespace detail
  19. {
  20. template<typename T>
  21. class is_other
  22. {
  23. public:
  24. BOOST_STATIC_CONSTANT(bool, value = false);
  25. };
  26. template<typename T>
  27. class is_other<other<T> >
  28. {
  29. public:
  30. BOOST_STATIC_CONSTANT(bool, value = true);
  31. };
  32. template<typename T>
  33. class unwrap_other
  34. {
  35. public:
  36. typedef T type;
  37. };
  38. template<typename T>
  39. class unwrap_other<other<T> >
  40. {
  41. public:
  42. typedef T type;
  43. };
  44. }
  45. # else // no partial specialization
  46. }} // namespace boost::python
  47. #include <boost/type.hpp>
  48. namespace boost { namespace python {
  49. namespace detail
  50. {
  51. typedef char (&yes_other_t)[1];
  52. typedef char (&no_other_t)[2];
  53. no_other_t is_other_test(...);
  54. template<typename T>
  55. yes_other_t is_other_test(type< other<T> >);
  56. template<bool wrapped>
  57. struct other_unwrapper
  58. {
  59. template <class T>
  60. struct apply
  61. {
  62. typedef T type;
  63. };
  64. };
  65. template<>
  66. struct other_unwrapper<true>
  67. {
  68. template <class T>
  69. struct apply
  70. {
  71. typedef typename T::type type;
  72. };
  73. };
  74. template<typename T>
  75. class is_other
  76. {
  77. public:
  78. BOOST_STATIC_CONSTANT(
  79. bool, value = (
  80. sizeof(detail::is_other_test(type<T>()))
  81. == sizeof(detail::yes_other_t)));
  82. };
  83. template <typename T>
  84. class unwrap_other
  85. : public detail::other_unwrapper<
  86. is_other<T>::value
  87. >::template apply<T>
  88. {};
  89. }
  90. # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
  91. }} // namespace boost::python
  92. #endif // #ifndef OTHER_DWA20020601_HPP