pair.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2006 Tobias Schwinger
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #if !defined(FUSION_PAIR_07222005_1203)
  8. #define FUSION_PAIR_07222005_1203
  9. #include <boost/fusion/support/config.hpp>
  10. #include <iosfwd>
  11. #include <boost/fusion/support/detail/access.hpp>
  12. #include <boost/fusion/support/detail/as_fusion_element.hpp>
  13. #include <boost/config.hpp>
  14. #include <boost/utility/enable_if.hpp>
  15. #include <boost/type_traits/is_convertible.hpp>
  16. #include <boost/type_traits/is_lvalue_reference.hpp>
  17. #if defined (BOOST_MSVC)
  18. # pragma warning(push)
  19. # pragma warning (disable: 4512) // assignment operator could not be generated.
  20. #endif
  21. namespace boost { namespace fusion
  22. {
  23. // A half runtime pair where the first type does not have data
  24. template <typename First, typename Second>
  25. struct pair
  26. {
  27. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  28. pair()
  29. : second() {}
  30. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  31. pair(pair const& rhs)
  32. : second(rhs.second) {}
  33. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  34. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  35. pair(pair&& rhs)
  36. : second(BOOST_FUSION_FWD_ELEM(Second, rhs.second)) {}
  37. #endif
  38. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  39. pair(typename detail::call_param<Second>::type val)
  40. : second(val) {}
  41. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  42. template <typename Second2>
  43. BOOST_FUSION_GPU_ENABLED
  44. pair(Second2&& val
  45. , typename boost::disable_if<is_lvalue_reference<Second2> >::type* /* dummy */ = 0
  46. , typename boost::enable_if<is_convertible<Second2, Second> >::type* /*dummy*/ = 0
  47. ) : second(BOOST_FUSION_FWD_ELEM(Second, val)) {}
  48. #endif
  49. template <typename Second2>
  50. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  51. pair(pair<First, Second2> const& rhs)
  52. : second(rhs.second) {}
  53. template <typename Second2>
  54. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  55. pair& operator=(pair<First, Second2> const& rhs)
  56. {
  57. second = rhs.second;
  58. return *this;
  59. }
  60. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  61. pair& operator=(pair const& rhs)
  62. {
  63. second = rhs.second;
  64. return *this;
  65. }
  66. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  67. BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  68. pair& operator=(pair&& rhs)
  69. {
  70. second = BOOST_FUSION_FWD_ELEM(Second, rhs.second);
  71. return *this;
  72. }
  73. #endif
  74. typedef First first_type;
  75. typedef Second second_type;
  76. Second second;
  77. };
  78. namespace result_of
  79. {
  80. template<typename First, typename Second>
  81. struct make_pair
  82. {
  83. typedef fusion::pair<First,
  84. typename detail::as_fusion_element<Second>::type> type;
  85. };
  86. template<class Pair>
  87. struct first
  88. {
  89. typedef typename Pair::first_type type;
  90. };
  91. template<class Pair>
  92. struct second
  93. {
  94. typedef typename Pair::second_type type;
  95. };
  96. }
  97. template <typename First, typename Second>
  98. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  99. inline typename result_of::make_pair<First,Second>::type
  100. make_pair(Second const& val)
  101. {
  102. return pair<First, typename detail::as_fusion_element<Second>::type>(val);
  103. }
  104. template <typename First, typename Second>
  105. inline std::ostream&
  106. operator<<(std::ostream& os, pair<First, Second> const& p)
  107. {
  108. os << p.second;
  109. return os;
  110. }
  111. template <typename First, typename Second>
  112. inline std::istream&
  113. operator>>(std::istream& is, pair<First, Second>& p)
  114. {
  115. is >> p.second;
  116. return is;
  117. }
  118. template <typename First, typename SecondL, typename SecondR>
  119. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  120. inline bool
  121. operator==(pair<First, SecondL> const& l, pair<First, SecondR> const& r)
  122. {
  123. return l.second == r.second;
  124. }
  125. template <typename First, typename SecondL, typename SecondR>
  126. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  127. inline bool
  128. operator!=(pair<First, SecondL> const& l, pair<First, SecondR> const& r)
  129. {
  130. return l.second != r.second;
  131. }
  132. template <typename First, typename SecondL, typename SecondR>
  133. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  134. inline bool
  135. operator<(pair<First, SecondL> const& l, pair<First, SecondR> const& r)
  136. {
  137. return l.second < r.second;
  138. }
  139. }}
  140. #if defined (BOOST_MSVC)
  141. # pragma warning(pop)
  142. #endif
  143. #endif