item.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef BOOST_MPL_MULTISET_AUX_ITEM_HPP_INCLUDED
  2. #define BOOST_MPL_MULTISET_AUX_ITEM_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2003-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/multiset/aux_/tag.hpp>
  14. #include <boost/mpl/int.hpp>
  15. #include <boost/mpl/aux_/type_wrapper.hpp>
  16. #include <boost/mpl/aux_/yes_no.hpp>
  17. #include <boost/mpl/aux_/value_wknd.hpp>
  18. #include <boost/mpl/aux_/static_cast.hpp>
  19. #include <boost/mpl/aux_/config/arrays.hpp>
  20. #include <boost/mpl/aux_/config/msvc.hpp>
  21. #include <boost/mpl/aux_/config/workaround.hpp>
  22. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  23. # include <boost/mpl/eval_if.hpp>
  24. # include <boost/mpl/next.hpp>
  25. # include <boost/type_traits/is_same.hpp>
  26. #endif
  27. namespace boost { namespace mpl {
  28. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  29. template< typename T, typename Base >
  30. struct ms_item
  31. {
  32. typedef aux::multiset_tag tag;
  33. template< typename U > struct prior_count
  34. {
  35. enum { msvc70_wknd_ = sizeof(Base::key_count(BOOST_MPL_AUX_STATIC_CAST(U*,0))) };
  36. typedef int_< msvc70_wknd_ > count_;
  37. typedef typename eval_if< is_same<T,U>, next<count_>, count_ >::type c_;
  38. #if defined(BOOST_MPL_CFG_NO_DEPENDENT_ARRAY_TYPES)
  39. typedef typename aux::weighted_tag<BOOST_MPL_AUX_MSVC_VALUE_WKND(c_)::value>::type type;
  40. #else
  41. typedef char (&type)[BOOST_MPL_AUX_MSVC_VALUE_WKND(c_)::value];
  42. #endif
  43. };
  44. template< typename U > struct prior_ref_count
  45. {
  46. typedef U (* u_)();
  47. enum { msvc70_wknd_ = sizeof(Base::ref_key_count(BOOST_MPL_AUX_STATIC_CAST(u_,0))) };
  48. typedef int_< msvc70_wknd_ > count_;
  49. typedef typename eval_if< is_same<T,U>, next<count_>, count_ >::type c_;
  50. #if defined(BOOST_MPL_CFG_NO_DEPENDENT_ARRAY_TYPES)
  51. typedef typename aux::weighted_tag<BOOST_MPL_AUX_MSVC_VALUE_WKND(c_)::value>::type type;
  52. #else
  53. typedef char (&type)[BOOST_MPL_AUX_MSVC_VALUE_WKND(c_)::value];
  54. #endif
  55. };
  56. template< typename U >
  57. static typename prior_count<U>::type key_count(U*);
  58. template< typename U >
  59. static typename prior_ref_count<U>::type ref_key_count(U (*)());
  60. };
  61. #else // BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  62. namespace aux {
  63. template< typename U, typename Base >
  64. struct prior_key_count
  65. {
  66. enum { msvc71_wknd_ = sizeof(Base::key_count(BOOST_MPL_AUX_STATIC_CAST(aux::type_wrapper<U>*,0))) };
  67. typedef int_< msvc71_wknd_ > count_;
  68. #if defined(BOOST_MPL_CFG_NO_DEPENDENT_ARRAY_TYPES)
  69. typedef typename aux::weighted_tag< BOOST_MPL_AUX_VALUE_WKND(count_)::value >::type type;
  70. #else
  71. typedef char (&type)[count_::value];
  72. #endif
  73. };
  74. }
  75. template< typename T, typename Base >
  76. struct ms_item
  77. {
  78. typedef aux::multiset_tag tag;
  79. enum { msvc71_wknd_ = sizeof(Base::key_count(BOOST_MPL_AUX_STATIC_CAST(aux::type_wrapper<T>*,0))) + 1 };
  80. typedef int_< msvc71_wknd_ > count_;
  81. #if defined(BOOST_MPL_CFG_NO_DEPENDENT_ARRAY_TYPES)
  82. static
  83. typename aux::weighted_tag< BOOST_MPL_AUX_VALUE_WKND(count_)::value >::type
  84. key_count(aux::type_wrapper<T>*);
  85. #else
  86. static char (& key_count(aux::type_wrapper<T>*) )[count_::value];
  87. #endif
  88. template< typename U >
  89. static typename aux::prior_key_count<U,Base>::type key_count(aux::type_wrapper<U>*);
  90. };
  91. #endif // BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  92. }}
  93. #endif // BOOST_MPL_MULTISET_AUX_ITEM_HPP_INCLUDED