at_impl.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef BOOST_MPL_MAP_AUX_AT_IMPL_HPP_INCLUDED
  2. #define BOOST_MPL_MAP_AUX_AT_IMPL_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2003-2004
  4. // Copyright David Abrahams 2003-2004
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/mpl for documentation.
  11. // $Id$
  12. // $Date$
  13. // $Revision$
  14. #include <boost/mpl/at_fwd.hpp>
  15. #include <boost/mpl/long.hpp>
  16. #include <boost/mpl/map/aux_/tag.hpp>
  17. #include <boost/mpl/aux_/order_impl.hpp>
  18. #include <boost/mpl/aux_/overload_names.hpp>
  19. #include <boost/mpl/aux_/type_wrapper.hpp>
  20. #include <boost/mpl/aux_/ptr_to_ref.hpp>
  21. #include <boost/mpl/aux_/static_cast.hpp>
  22. #include <boost/mpl/aux_/config/typeof.hpp>
  23. #include <boost/mpl/aux_/config/ctps.hpp>
  24. #if !defined(BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES)
  25. # include <boost/mpl/eval_if.hpp>
  26. # include <boost/mpl/pair.hpp>
  27. # include <boost/mpl/void.hpp>
  28. # include <boost/mpl/aux_/config/static_constant.hpp>
  29. #endif
  30. namespace boost { namespace mpl {
  31. #if defined(BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES)
  32. template< typename Map, typename Key >
  33. struct m_at
  34. {
  35. typedef aux::type_wrapper<Key> key_;
  36. typedef __typeof__( BOOST_MPL_AUX_OVERLOAD_CALL_VALUE_BY_KEY(
  37. Map
  38. , BOOST_MPL_AUX_STATIC_CAST(key_*, 0)
  39. ) ) type;
  40. };
  41. template<>
  42. struct at_impl< aux::map_tag >
  43. {
  44. template< typename Map, typename Key > struct apply
  45. : aux::wrapped_type< typename m_at<
  46. Map
  47. , Key
  48. >::type >
  49. {
  50. };
  51. };
  52. // agurt 31/jan/04: two-step implementation for the sake of GCC 3.x
  53. template< typename Map, long order >
  54. struct item_by_order_impl
  55. {
  56. typedef __typeof__( BOOST_MPL_AUX_OVERLOAD_CALL_ITEM_BY_ORDER(
  57. Map
  58. , BOOST_MPL_AUX_STATIC_CAST(long_<order>*, 0)
  59. ) ) type;
  60. };
  61. template< typename Map, long order >
  62. struct item_by_order
  63. : aux::wrapped_type<
  64. typename item_by_order_impl<Map,order>::type
  65. >
  66. {
  67. };
  68. #else // BOOST_MPL_CFG_TYPEOF_BASED_SEQUENCES
  69. # if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  70. template< typename Map, long n > struct m_at
  71. {
  72. typedef void_ type;
  73. };
  74. # else
  75. template< long n > struct m_at_impl
  76. {
  77. template< typename Map > struct result_
  78. {
  79. typedef void_ type;
  80. };
  81. };
  82. template< typename Map, long n > struct m_at
  83. {
  84. typedef typename m_at_impl<n>::result_<Map>::type type;
  85. };
  86. # endif
  87. template<>
  88. struct at_impl< aux::map_tag >
  89. {
  90. template< typename Map, typename Key > struct apply
  91. {
  92. typedef typename m_at< Map, (x_order_impl<Map,Key>::value - 2) >::type item_;
  93. typedef typename eval_if<
  94. is_void_<item_>
  95. , void_
  96. , second<item_>
  97. >::type type;
  98. };
  99. };
  100. template< typename Map, long order > struct is_item_masked
  101. {
  102. BOOST_STATIC_CONSTANT(bool, value =
  103. sizeof( BOOST_MPL_AUX_OVERLOAD_CALL_IS_MASKED(
  104. Map
  105. , BOOST_MPL_AUX_STATIC_CAST(long_<order>*, 0)
  106. ) ) == sizeof(aux::yes_tag)
  107. );
  108. };
  109. template< typename Map, long order > struct item_by_order
  110. {
  111. typedef typename eval_if_c<
  112. is_item_masked<Map,order>::value
  113. , void_
  114. , m_at<Map,(order - 2)>
  115. >::type type;
  116. };
  117. #endif
  118. }}
  119. #endif // BOOST_MPL_SET_AUX_AT_IMPL_HPP_INCLUDED