count_impl.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef BOOST_MPL_MULTISET_AUX_COUNT_IMPL_HPP_INCLUDED
  2. #define BOOST_MPL_MULTISET_AUX_COUNT_IMPL_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/count_fwd.hpp>
  15. #include <boost/mpl/int.hpp>
  16. #include <boost/mpl/aux_/type_wrapper.hpp>
  17. #include <boost/mpl/aux_/static_cast.hpp>
  18. #include <boost/mpl/aux_/config/static_constant.hpp>
  19. #include <boost/mpl/aux_/config/workaround.hpp>
  20. #include <boost/mpl/aux_/config/msvc.hpp>
  21. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  22. # include <boost/mpl/if.hpp>
  23. # include <boost/type_traits/is_reference.hpp>
  24. #endif
  25. namespace boost { namespace mpl {
  26. #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  27. namespace aux {
  28. template< typename S, typename U >
  29. struct multiset_count_impl
  30. : int_< sizeof(S::key_count(BOOST_MPL_AUX_STATIC_CAST(U*,0))) - 1 >
  31. {
  32. };
  33. template< typename S, typename U >
  34. struct multiset_count_ref_impl
  35. {
  36. typedef U (* u_)();
  37. typedef int_< sizeof(S::ref_key_count(BOOST_MPL_AUX_STATIC_CAST(u_,0))) - 1 > type_;
  38. BOOST_STATIC_CONSTANT(int, value = type_::value);
  39. typedef type_ type;
  40. };
  41. }
  42. template<>
  43. struct count_impl< aux::multiset_tag >
  44. {
  45. template< typename Set, typename Key > struct apply
  46. : if_<
  47. is_reference<Key>
  48. , aux::multiset_count_ref_impl<Set,Key>
  49. , aux::multiset_count_impl<Set,Key>
  50. >::type
  51. {
  52. };
  53. };
  54. #else
  55. template<>
  56. struct count_impl< aux::multiset_tag >
  57. {
  58. template< typename Set, typename Key > struct apply
  59. {
  60. enum { msvc71_wknd_ = sizeof(Set::key_count(BOOST_MPL_AUX_STATIC_CAST(aux::type_wrapper<Key>*,0))) - 1 };
  61. typedef int_< msvc71_wknd_ > type;
  62. BOOST_STATIC_CONSTANT(int, value = msvc71_wknd_);
  63. };
  64. };
  65. #endif // BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  66. }}
  67. #endif // BOOST_MPL_MULTISET_AUX_COUNT_IMPL_HPP_INCLUDED