mem_fn_eq_test.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. #include <boost/config.hpp>
  2. #if defined(BOOST_MSVC)
  3. #pragma warning(disable: 4786) // identifier truncated in debug info
  4. #pragma warning(disable: 4710) // function not inlined
  5. #pragma warning(disable: 4711) // function selected for automatic inline expansion
  6. #pragma warning(disable: 4514) // unreferenced inline removed
  7. #endif
  8. //
  9. // mem_fn_eq_test.cpp - boost::mem_fn equality operator
  10. //
  11. // Copyright (c) 2004 Peter Dimov
  12. //
  13. // Distributed under the Boost Software License, Version 1.0. (See
  14. // accompanying file LICENSE_1_0.txt or copy at
  15. // http://www.boost.org/LICENSE_1_0.txt)
  16. //
  17. #include <boost/mem_fn.hpp>
  18. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  19. #pragma warning(push, 3)
  20. #endif
  21. #include <iostream>
  22. #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
  23. #pragma warning(pop)
  24. #endif
  25. #include <boost/detail/lightweight_test.hpp>
  26. struct X
  27. {
  28. int dm_1;
  29. int dm_2;
  30. // 0
  31. int mf0_1() { return 0; }
  32. int mf0_2() { return 1; }
  33. int cmf0_1() const { return 0; }
  34. int cmf0_2() const { return 1; }
  35. void mf0v_1() {}
  36. void mf0v_2() { static int x; ++x; }
  37. void cmf0v_1() const {}
  38. void cmf0v_2() const { static int x; ++x; }
  39. // 1
  40. int mf1_1(int) { return 0; }
  41. int mf1_2(int) { return 1; }
  42. int cmf1_1(int) const { return 0; }
  43. int cmf1_2(int) const { return 1; }
  44. void mf1v_1(int) {}
  45. void mf1v_2(int) { static int x; ++x; }
  46. void cmf1v_1(int) const {}
  47. void cmf1v_2(int) const { static int x; ++x; }
  48. // 2
  49. int mf2_1(int, int) { return 0; }
  50. int mf2_2(int, int) { return 1; }
  51. int cmf2_1(int, int) const { return 0; }
  52. int cmf2_2(int, int) const { return 1; }
  53. void mf2v_1(int, int) {}
  54. void mf2v_2(int, int) { static int x; ++x; }
  55. void cmf2v_1(int, int) const {}
  56. void cmf2v_2(int, int) const { static int x; ++x; }
  57. // 3
  58. int mf3_1(int, int, int) { return 0; }
  59. int mf3_2(int, int, int) { return 1; }
  60. int cmf3_1(int, int, int) const { return 0; }
  61. int cmf3_2(int, int, int) const { return 1; }
  62. void mf3v_1(int, int, int) {}
  63. void mf3v_2(int, int, int) { static int x; ++x; }
  64. void cmf3v_1(int, int, int) const {}
  65. void cmf3v_2(int, int, int) const { static int x; ++x; }
  66. // 4
  67. int mf4_1(int, int, int, int) { return 0; }
  68. int mf4_2(int, int, int, int) { return 1; }
  69. int cmf4_1(int, int, int, int) const { return 0; }
  70. int cmf4_2(int, int, int, int) const { return 1; }
  71. void mf4v_1(int, int, int, int) {}
  72. void mf4v_2(int, int, int, int) { static int x; ++x; }
  73. void cmf4v_1(int, int, int, int) const {}
  74. void cmf4v_2(int, int, int, int) const { static int x; ++x; }
  75. // 5
  76. int mf5_1(int, int, int, int, int) { return 0; }
  77. int mf5_2(int, int, int, int, int) { return 1; }
  78. int cmf5_1(int, int, int, int, int) const { return 0; }
  79. int cmf5_2(int, int, int, int, int) const { return 1; }
  80. void mf5v_1(int, int, int, int, int) {}
  81. void mf5v_2(int, int, int, int, int) { static int x; ++x; }
  82. void cmf5v_1(int, int, int, int, int) const {}
  83. void cmf5v_2(int, int, int, int, int) const { static int x; ++x; }
  84. // 6
  85. int mf6_1(int, int, int, int, int, int) { return 0; }
  86. int mf6_2(int, int, int, int, int, int) { return 1; }
  87. int cmf6_1(int, int, int, int, int, int) const { return 0; }
  88. int cmf6_2(int, int, int, int, int, int) const { return 1; }
  89. void mf6v_1(int, int, int, int, int, int) {}
  90. void mf6v_2(int, int, int, int, int, int) { static int x; ++x; }
  91. void cmf6v_1(int, int, int, int, int, int) const {}
  92. void cmf6v_2(int, int, int, int, int, int) const { static int x; ++x; }
  93. // 7
  94. int mf7_1(int, int, int, int, int, int, int) { return 0; }
  95. int mf7_2(int, int, int, int, int, int, int) { return 1; }
  96. int cmf7_1(int, int, int, int, int, int, int) const { return 0; }
  97. int cmf7_2(int, int, int, int, int, int, int) const { return 1; }
  98. void mf7v_1(int, int, int, int, int, int, int) {}
  99. void mf7v_2(int, int, int, int, int, int, int) { static int x; ++x; }
  100. void cmf7v_1(int, int, int, int, int, int, int) const {}
  101. void cmf7v_2(int, int, int, int, int, int, int) const { static int x; ++x; }
  102. // 8
  103. int mf8_1(int, int, int, int, int, int, int, int) { return 0; }
  104. int mf8_2(int, int, int, int, int, int, int, int) { return 1; }
  105. int cmf8_1(int, int, int, int, int, int, int, int) const { return 0; }
  106. int cmf8_2(int, int, int, int, int, int, int, int) const { return 1; }
  107. void mf8v_1(int, int, int, int, int, int, int, int) {}
  108. void mf8v_2(int, int, int, int, int, int, int, int) { static int x; ++x; }
  109. void cmf8v_1(int, int, int, int, int, int, int, int) const {}
  110. void cmf8v_2(int, int, int, int, int, int, int, int) const { static int x; ++x; }
  111. };
  112. int main()
  113. {
  114. BOOST_TEST( boost::mem_fn(&X::dm_1) == boost::mem_fn(&X::dm_1) );
  115. BOOST_TEST( boost::mem_fn(&X::dm_1) != boost::mem_fn(&X::dm_2) );
  116. // 0
  117. BOOST_TEST( boost::mem_fn(&X::mf0_1) == boost::mem_fn(&X::mf0_1) );
  118. BOOST_TEST( boost::mem_fn(&X::mf0_1) != boost::mem_fn(&X::mf0_2) );
  119. BOOST_TEST( boost::mem_fn(&X::cmf0_1) == boost::mem_fn(&X::cmf0_1) );
  120. BOOST_TEST( boost::mem_fn(&X::cmf0_1) != boost::mem_fn(&X::cmf0_2) );
  121. BOOST_TEST( boost::mem_fn(&X::mf0v_1) == boost::mem_fn(&X::mf0v_1) );
  122. BOOST_TEST( boost::mem_fn(&X::mf0v_1) != boost::mem_fn(&X::mf0v_2) );
  123. BOOST_TEST( boost::mem_fn(&X::cmf0v_1) == boost::mem_fn(&X::cmf0v_1) );
  124. BOOST_TEST( boost::mem_fn(&X::cmf0v_1) != boost::mem_fn(&X::cmf0v_2) );
  125. // 1
  126. BOOST_TEST( boost::mem_fn(&X::mf1_1) == boost::mem_fn(&X::mf1_1) );
  127. BOOST_TEST( boost::mem_fn(&X::mf1_1) != boost::mem_fn(&X::mf1_2) );
  128. BOOST_TEST( boost::mem_fn(&X::cmf1_1) == boost::mem_fn(&X::cmf1_1) );
  129. BOOST_TEST( boost::mem_fn(&X::cmf1_1) != boost::mem_fn(&X::cmf1_2) );
  130. BOOST_TEST( boost::mem_fn(&X::mf1v_1) == boost::mem_fn(&X::mf1v_1) );
  131. BOOST_TEST( boost::mem_fn(&X::mf1v_1) != boost::mem_fn(&X::mf1v_2) );
  132. BOOST_TEST( boost::mem_fn(&X::cmf1v_1) == boost::mem_fn(&X::cmf1v_1) );
  133. BOOST_TEST( boost::mem_fn(&X::cmf1v_1) != boost::mem_fn(&X::cmf1v_2) );
  134. // 2
  135. BOOST_TEST( boost::mem_fn(&X::mf2_1) == boost::mem_fn(&X::mf2_1) );
  136. BOOST_TEST( boost::mem_fn(&X::mf2_1) != boost::mem_fn(&X::mf2_2) );
  137. BOOST_TEST( boost::mem_fn(&X::cmf2_1) == boost::mem_fn(&X::cmf2_1) );
  138. BOOST_TEST( boost::mem_fn(&X::cmf2_1) != boost::mem_fn(&X::cmf2_2) );
  139. BOOST_TEST( boost::mem_fn(&X::mf2v_1) == boost::mem_fn(&X::mf2v_1) );
  140. BOOST_TEST( boost::mem_fn(&X::mf2v_1) != boost::mem_fn(&X::mf2v_2) );
  141. BOOST_TEST( boost::mem_fn(&X::cmf2v_1) == boost::mem_fn(&X::cmf2v_1) );
  142. BOOST_TEST( boost::mem_fn(&X::cmf2v_1) != boost::mem_fn(&X::cmf2v_2) );
  143. // 3
  144. BOOST_TEST( boost::mem_fn(&X::mf3_1) == boost::mem_fn(&X::mf3_1) );
  145. BOOST_TEST( boost::mem_fn(&X::mf3_1) != boost::mem_fn(&X::mf3_2) );
  146. BOOST_TEST( boost::mem_fn(&X::cmf3_1) == boost::mem_fn(&X::cmf3_1) );
  147. BOOST_TEST( boost::mem_fn(&X::cmf3_1) != boost::mem_fn(&X::cmf3_2) );
  148. BOOST_TEST( boost::mem_fn(&X::mf3v_1) == boost::mem_fn(&X::mf3v_1) );
  149. BOOST_TEST( boost::mem_fn(&X::mf3v_1) != boost::mem_fn(&X::mf3v_2) );
  150. BOOST_TEST( boost::mem_fn(&X::cmf3v_1) == boost::mem_fn(&X::cmf3v_1) );
  151. BOOST_TEST( boost::mem_fn(&X::cmf3v_1) != boost::mem_fn(&X::cmf3v_2) );
  152. // 4
  153. BOOST_TEST( boost::mem_fn(&X::mf4_1) == boost::mem_fn(&X::mf4_1) );
  154. BOOST_TEST( boost::mem_fn(&X::mf4_1) != boost::mem_fn(&X::mf4_2) );
  155. BOOST_TEST( boost::mem_fn(&X::cmf4_1) == boost::mem_fn(&X::cmf4_1) );
  156. BOOST_TEST( boost::mem_fn(&X::cmf4_1) != boost::mem_fn(&X::cmf4_2) );
  157. BOOST_TEST( boost::mem_fn(&X::mf4v_1) == boost::mem_fn(&X::mf4v_1) );
  158. BOOST_TEST( boost::mem_fn(&X::mf4v_1) != boost::mem_fn(&X::mf4v_2) );
  159. BOOST_TEST( boost::mem_fn(&X::cmf4v_1) == boost::mem_fn(&X::cmf4v_1) );
  160. BOOST_TEST( boost::mem_fn(&X::cmf4v_1) != boost::mem_fn(&X::cmf4v_2) );
  161. // 5
  162. BOOST_TEST( boost::mem_fn(&X::mf5_1) == boost::mem_fn(&X::mf5_1) );
  163. BOOST_TEST( boost::mem_fn(&X::mf5_1) != boost::mem_fn(&X::mf5_2) );
  164. BOOST_TEST( boost::mem_fn(&X::cmf5_1) == boost::mem_fn(&X::cmf5_1) );
  165. BOOST_TEST( boost::mem_fn(&X::cmf5_1) != boost::mem_fn(&X::cmf5_2) );
  166. BOOST_TEST( boost::mem_fn(&X::mf5v_1) == boost::mem_fn(&X::mf5v_1) );
  167. BOOST_TEST( boost::mem_fn(&X::mf5v_1) != boost::mem_fn(&X::mf5v_2) );
  168. BOOST_TEST( boost::mem_fn(&X::cmf5v_1) == boost::mem_fn(&X::cmf5v_1) );
  169. BOOST_TEST( boost::mem_fn(&X::cmf5v_1) != boost::mem_fn(&X::cmf5v_2) );
  170. // 6
  171. BOOST_TEST( boost::mem_fn(&X::mf6_1) == boost::mem_fn(&X::mf6_1) );
  172. BOOST_TEST( boost::mem_fn(&X::mf6_1) != boost::mem_fn(&X::mf6_2) );
  173. BOOST_TEST( boost::mem_fn(&X::cmf6_1) == boost::mem_fn(&X::cmf6_1) );
  174. BOOST_TEST( boost::mem_fn(&X::cmf6_1) != boost::mem_fn(&X::cmf6_2) );
  175. BOOST_TEST( boost::mem_fn(&X::mf6v_1) == boost::mem_fn(&X::mf6v_1) );
  176. BOOST_TEST( boost::mem_fn(&X::mf6v_1) != boost::mem_fn(&X::mf6v_2) );
  177. BOOST_TEST( boost::mem_fn(&X::cmf6v_1) == boost::mem_fn(&X::cmf6v_1) );
  178. BOOST_TEST( boost::mem_fn(&X::cmf6v_1) != boost::mem_fn(&X::cmf6v_2) );
  179. // 7
  180. BOOST_TEST( boost::mem_fn(&X::mf7_1) == boost::mem_fn(&X::mf7_1) );
  181. BOOST_TEST( boost::mem_fn(&X::mf7_1) != boost::mem_fn(&X::mf7_2) );
  182. BOOST_TEST( boost::mem_fn(&X::cmf7_1) == boost::mem_fn(&X::cmf7_1) );
  183. BOOST_TEST( boost::mem_fn(&X::cmf7_1) != boost::mem_fn(&X::cmf7_2) );
  184. BOOST_TEST( boost::mem_fn(&X::mf7v_1) == boost::mem_fn(&X::mf7v_1) );
  185. BOOST_TEST( boost::mem_fn(&X::mf7v_1) != boost::mem_fn(&X::mf7v_2) );
  186. BOOST_TEST( boost::mem_fn(&X::cmf7v_1) == boost::mem_fn(&X::cmf7v_1) );
  187. BOOST_TEST( boost::mem_fn(&X::cmf7v_1) != boost::mem_fn(&X::cmf7v_2) );
  188. // 8
  189. BOOST_TEST( boost::mem_fn(&X::mf8_1) == boost::mem_fn(&X::mf8_1) );
  190. BOOST_TEST( boost::mem_fn(&X::mf8_1) != boost::mem_fn(&X::mf8_2) );
  191. BOOST_TEST( boost::mem_fn(&X::cmf8_1) == boost::mem_fn(&X::cmf8_1) );
  192. BOOST_TEST( boost::mem_fn(&X::cmf8_1) != boost::mem_fn(&X::cmf8_2) );
  193. BOOST_TEST( boost::mem_fn(&X::mf8v_1) == boost::mem_fn(&X::mf8v_1) );
  194. BOOST_TEST( boost::mem_fn(&X::mf8v_1) != boost::mem_fn(&X::mf8v_2) );
  195. BOOST_TEST( boost::mem_fn(&X::cmf8v_1) == boost::mem_fn(&X::cmf8v_1) );
  196. BOOST_TEST( boost::mem_fn(&X::cmf8v_1) != boost::mem_fn(&X::cmf8v_2) );
  197. return boost::report_errors();
  198. }