access_builder.hpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // Boost.Bimap
  2. //
  3. // Copyright (c) 2006-2007 Matias Capeletto
  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. /// \file relation/detail/access_builder.hpp
  9. /// \brief Define macros to help building metafunctions
  10. #ifndef BOOST_BIMAP_RELATION_ACCESS_BUILDER_HPP
  11. #define BOOST_BIMAP_RELATION_ACCESS_BUILDER_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp>
  16. #include <boost/bimap/relation/support/member_with_tag.hpp>
  17. #include <boost/bimap/relation/member_at.hpp>
  18. #include <boost/call_traits.hpp>
  19. #include <boost/type_traits/is_const.hpp>
  20. #include <boost/mpl/if.hpp>
  21. #include <boost/mpl/not.hpp>
  22. #include <boost/utility/enable_if.hpp>
  23. /******************************************************************************
  24. BIMAP SYMMETRIC ACCESS RESULT OF
  25. *******************************************************************************
  26. namespace result_of {
  27. template< class Tag, class SymmetricType >
  28. struct NAME
  29. {
  30. typedef -unspecified- type;
  31. };
  32. } // namespace result_of
  33. ******************************************************************************/
  34. /*===========================================================================*/
  35. #define BOOST_BIMAP_SYMMETRIC_ACCESS_RESULT_OF_BUILDER( \
  36. \
  37. NAME, \
  38. METAFUNCTION_BASE \
  39. ) \
  40. \
  41. namespace result_of { \
  42. \
  43. template< class Tag, class SymmetricType > \
  44. struct NAME \
  45. { \
  46. typedef BOOST_DEDUCED_TYPENAME METAFUNCTION_BASE \
  47. < \
  48. Tag,SymmetricType \
  49. \
  50. >::type value_type; \
  51. \
  52. typedef BOOST_DEDUCED_TYPENAME mpl::if_< is_const<SymmetricType>, \
  53. \
  54. BOOST_DEDUCED_TYPENAME call_traits<value_type>::const_reference, \
  55. \
  56. BOOST_DEDUCED_TYPENAME call_traits<value_type>::reference \
  57. \
  58. >::type type; \
  59. }; \
  60. \
  61. }
  62. /*===========================================================================*/
  63. /******************************************************************************
  64. BIMAP SYMMETRIC ACCESS IMPLEMENTATION
  65. *******************************************************************************
  66. namespace detail {
  67. template< class Tag, class SymmetricType >
  68. typename result_of::NAME<Tag,SymmetricType>::type
  69. NAME( Tag , const Relation & );
  70. } // namespace detail
  71. ******************************************************************************/
  72. /*===========================================================================*/
  73. #define BOOST_BIMAP_SYMMETRIC_ACCESS_IMPLEMENTATION_BUILDER( \
  74. \
  75. NAME, \
  76. TP_SYMMETRIC, \
  77. PARAMETER_NAME, \
  78. LEFT_BODY, \
  79. RIGHT_BODY \
  80. ) \
  81. \
  82. namespace detail { \
  83. \
  84. \
  85. \
  86. template< class TP_SYMMETRIC > \
  87. BOOST_DEDUCED_TYPENAME result_of::NAME \
  88. < \
  89. ::boost::bimaps::relation::member_at::left,TP_SYMMETRIC \
  90. \
  91. >::type \
  92. \
  93. NAME( ::boost::bimaps::relation::member_at::left, \
  94. TP_SYMMETRIC & PARAMETER_NAME ) \
  95. { \
  96. LEFT_BODY; \
  97. } \
  98. \
  99. template< class TP_SYMMETRIC > \
  100. BOOST_DEDUCED_TYPENAME result_of::NAME \
  101. < \
  102. ::boost::bimaps::relation::member_at::right,TP_SYMMETRIC \
  103. \
  104. >::type \
  105. \
  106. NAME( ::boost::bimaps::relation::member_at::right, \
  107. TP_SYMMETRIC & PARAMETER_NAME ) \
  108. { \
  109. RIGHT_BODY; \
  110. } \
  111. \
  112. }
  113. /*===========================================================================*/
  114. /******************************************************************************
  115. BIMAP RELATION ACCESS INTERFACE
  116. *******************************************************************************
  117. template< class Tag, class SymmetricType >
  118. typename result_of::NAME<Tag,SymmetricType>::type
  119. NAME( const SymmetricType & );
  120. ******************************************************************************/
  121. /*===========================================================================*/
  122. #define BOOST_BIMAP_SYMMETRIC_ACCESS_INTERFACE_BUILDER( \
  123. \
  124. NAME \
  125. ) \
  126. \
  127. template< class Tag, class SymmetricType > \
  128. BOOST_DEDUCED_TYPENAME result_of::NAME<Tag,SymmetricType>::type \
  129. NAME( SymmetricType & s ) \
  130. { \
  131. typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::relation::support:: \
  132. member_with_tag \
  133. < \
  134. Tag,SymmetricType \
  135. \
  136. >::type member_at_tag; \
  137. \
  138. return detail::NAME(member_at_tag(),s); \
  139. }
  140. /*===========================================================================*/
  141. #endif // BOOST_BIMAP_RELATION_ACCESS_BUILDER_HPP