container_tests.hpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. /*=============================================================================
  2. Copyright (c) 2004 Angus Leeming
  3. Copyright (c) 2017 Kohei Takahashi
  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(CONTAINER_TESTS_HPP)
  8. #define CONTAINER_TESTS_HPP
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/phoenix/core.hpp>
  11. #include <boost/phoenix/stl/container/container.hpp>
  12. #include <iostream>
  13. #include <typeinfo>
  14. #include <deque>
  15. #include <list>
  16. #include <map>
  17. #include <set>
  18. #include <vector>
  19. #include <utility>
  20. #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP
  21. #include <unordered_map>
  22. #endif
  23. #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET
  24. #include <unordered_set>
  25. #endif
  26. #ifdef BOOST_MSVC
  27. #pragma warning(disable : 4800)
  28. #endif
  29. using std::cerr;
  30. namespace phx = boost::phoenix;
  31. template <typename T> inline T const build_assoc();
  32. std::deque<int> const build_deque();
  33. std::list<int> const build_list();
  34. std::map<int, int> const build_map();
  35. std::multimap<int, int> const build_multimap();
  36. std::vector<int> const build_vector();
  37. std::set<int> const build_set();
  38. std::multiset<int> const build_multiset();
  39. template <> inline std::map<int, int> const build_assoc() { return build_map(); }
  40. template <> inline std::multimap<int, int> const build_assoc() { return build_multimap(); }
  41. template <> inline std::set<int> const build_assoc() { return build_set(); }
  42. template <> inline std::multiset<int> const build_assoc() { return build_multiset(); }
  43. #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP
  44. std::unordered_map<int, int> const build_unordered_map();
  45. std::unordered_multimap<int, int> const build_unordered_multimap();
  46. template <> inline std::unordered_map<int, int> const build_assoc() { return build_unordered_map(); }
  47. template <> inline std::unordered_multimap<int, int> const build_assoc() { return build_unordered_multimap(); }
  48. #endif
  49. #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET
  50. std::unordered_set<int> const build_unordered_set();
  51. std::unordered_multiset<int> const build_unordered_multiset();
  52. template <> inline std::unordered_set<int> const build_assoc() { return build_unordered_set(); }
  53. template <> inline std::unordered_multiset<int> const build_assoc() { return build_unordered_multiset(); }
  54. #endif
  55. inline bool
  56. test(bool fail)
  57. {
  58. BOOST_TEST(!fail);
  59. return fail;
  60. }
  61. template <typename Container>
  62. void test_assign(Container c)
  63. {
  64. using phx::arg_names::arg1;
  65. typename Container::size_type count = 2;
  66. typename Container::const_iterator first = c.begin();
  67. typename Container::const_iterator second = first;
  68. typename Container::value_type value = *first;
  69. phx::assign(arg1, count, value)(c);
  70. // iterators may be invalidated!
  71. first = c.begin();
  72. second = first;
  73. std::advance(second, 1);
  74. if (test(*first != *second)) {
  75. cerr << "Failed " << typeid(Container).name() << " test_assign 1\n";
  76. return;
  77. }
  78. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  79. // Should not --- does not, Yay! --- compile.
  80. Container const const_c = c;
  81. phx::assign(const_c, count, value);
  82. #endif
  83. }
  84. template <typename Container>
  85. void test_assign2(Container c)
  86. {
  87. using phx::arg_names::arg1;
  88. using phx::arg_names::arg2;
  89. using phx::arg_names::arg3;
  90. Container c2 = c;
  91. typename Container::const_iterator first = c2.begin();
  92. typename Container::const_iterator last = c2.end();
  93. typename Container::size_type size = c2.size();
  94. c.clear();
  95. phx::assign(arg1, arg2, arg3)(c, first, last);
  96. if (test(c.size() != size)) {
  97. cerr << "Failed " << typeid(Container).name()
  98. << " test_assign2 1\n"
  99. << "size == " << c.size() << '\n';
  100. return;
  101. }
  102. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  103. // Should not --- does not, Yay! --- compile.
  104. Container const const_c = c;
  105. phx::assign(const_c, first, second);
  106. #endif
  107. }
  108. template <typename Container>
  109. void test_at(Container c)
  110. {
  111. using phx::arg_names::arg1;
  112. using phx::at;
  113. typename Container::reference r1 = at(arg1, 0)(c);
  114. if (test(r1 != c.at(0))) {
  115. cerr << "Failed " << typeid(Container).name() << " test_at 1\n";
  116. return;
  117. }
  118. typename Container::const_reference r2 = at(arg1, 0)(c);
  119. if (test(r2 != c.at(0))) {
  120. cerr << "Failed " << typeid(Container).name() << " test_at 2\n";
  121. return;
  122. }
  123. Container const const_c = c;
  124. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  125. // Should not --- does not, Yay! --- compile.
  126. typename Container::reference r3 = at(arg1, 0)(const_c);
  127. #endif
  128. typename Container::const_reference r4 = at(arg1, 0)(const_c);
  129. if (test(r4 != c.at(0))) {
  130. cerr << "Failed " << typeid(Container).name() << " test_at 4\n";
  131. return;
  132. }
  133. }
  134. template <typename Container>
  135. void test_back(Container c)
  136. {
  137. using phx::arg_names::arg1;
  138. using phx::back;
  139. typename Container::reference r1 = back(arg1)(c);
  140. if (test(r1 != c.back())) {
  141. cerr << "Failed " << typeid(Container).name() << " test_back 1\n";
  142. return;
  143. }
  144. typename Container::const_reference r2 = back(arg1)(c);
  145. if (test(r2 != c.back())) {
  146. cerr << "Failed " << typeid(Container).name() << " test_back 2\n";
  147. return;
  148. }
  149. Container const const_c = c;
  150. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  151. // Should not --- does not, Yay! --- compile.
  152. typename Container::reference r3 = back(arg1)(const_c);
  153. #endif
  154. typename Container::const_reference r4 = back(arg1)(const_c);
  155. if (test(r4 != c.back())) {
  156. cerr << "Failed " << typeid(Container).name() << " test_back 4\n";
  157. return;
  158. }
  159. }
  160. template <typename Container>
  161. void test_begin(Container c)
  162. {
  163. using phx::arg_names::arg1;
  164. using phx::begin;
  165. typename Container::iterator it1 = begin(arg1)(c);
  166. if (test(it1 != c.begin())) {
  167. cerr << "Failed " << typeid(Container).name() << " test_begin 1\n";
  168. return;
  169. }
  170. typename Container::const_iterator it2 = begin(arg1)(c);
  171. if (test(it2 != c.begin())) {
  172. cerr << "Failed " << typeid(Container).name() << " test_begin 2\n";
  173. return;
  174. }
  175. Container const const_c = c;
  176. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  177. // Should not --- does not, Yay! --- compile.
  178. typename Container::iterator it3 = begin(arg1)(const_c);
  179. #endif
  180. typename Container::const_iterator it4 = begin(arg1)(const_c);
  181. if (test(it4 != const_c.begin())) {
  182. cerr << "Failed " << typeid(Container).name() << " test_begin 4\n";
  183. return;
  184. }
  185. }
  186. template <typename Container>
  187. void test_capacity(Container c)
  188. {
  189. using phx::arg_names::arg1;
  190. using phx::capacity;
  191. typename Container::size_type s1 = capacity(arg1)(c);
  192. if (test(s1 != c.capacity())) {
  193. cerr << "Failed " << typeid(Container).name() << " test_capacity 1\n";
  194. return;
  195. }
  196. Container const const_c = c;
  197. typename Container::size_type s2 = capacity(arg1)(const_c);
  198. if (test(s2 != const_c.capacity())) {
  199. cerr << "Failed " << typeid(Container).name() << " test_capacity 2\n";
  200. return;
  201. }
  202. }
  203. template <typename Container>
  204. void test_clear(Container c)
  205. {
  206. using phx::arg_names::arg1;
  207. using phx::clear;
  208. clear(arg1)(c);
  209. if (test(!c.empty())) {
  210. cerr << "Failed " << typeid(Container).name() << " test_clear 1\n";
  211. return;
  212. }
  213. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  214. Container const const_c = c;
  215. clear(arg1)(const_c);
  216. #endif
  217. }
  218. template <typename Container>
  219. void test_empty(Container c)
  220. {
  221. using phx::arg_names::arg1;
  222. using phx::empty;
  223. typename Container::size_type s1 = empty(arg1)(c);
  224. if (test(bool(s1) != c.empty())) {
  225. cerr << "Failed " << typeid(Container).name() << " test_empty 1\n";
  226. return;
  227. }
  228. Container const const_c = c;
  229. typename Container::size_type s2 = empty(arg1)(const_c);
  230. if (test(bool(s2) != const_c.empty())) {
  231. cerr << "Failed " << typeid(Container).name() << " test_empty 2\n";
  232. return;
  233. }
  234. }
  235. template <typename Container>
  236. void test_end(Container c)
  237. {
  238. using phx::arg_names::arg1;
  239. using phx::end;
  240. typename Container::iterator it1 = end(arg1)(c);
  241. if (test(it1 != c.end())) {
  242. cerr << "Failed " << typeid(Container).name() << " test_end 1\n";
  243. return;
  244. }
  245. typename Container::const_iterator it2 = end(arg1)(c);
  246. if (test(it2 != c.end())) {
  247. cerr << "Failed " << typeid(Container).name() << " test_end 2\n";
  248. return;
  249. }
  250. Container const const_c = c;
  251. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  252. // Should not --- does not, Yay! --- compile.
  253. typename Container::iterator it3 = end(arg1)(const_c);
  254. #endif
  255. typename Container::const_iterator it4 = end(arg1)(const_c);
  256. if (test(it4 != const_c.end())) {
  257. cerr << "Failed " << typeid(Container).name() << " test_end 4\n";
  258. return;
  259. }
  260. }
  261. template <typename Container>
  262. void test_erase(Container c)
  263. {
  264. using phx::arg_names::arg1;
  265. using phx::arg_names::arg2;
  266. using phx::arg_names::arg3;
  267. using phx::erase;
  268. Container const const_c = c;
  269. typename Container::size_type size = c.size();
  270. typename Container::iterator c_begin = c.begin();
  271. erase(arg1, arg2)(c, c_begin);
  272. if (test(c.size() + 1 != size)) {
  273. cerr << "Failed " << typeid(Container).name() << " test_erase 1\n";
  274. return;
  275. }
  276. c_begin = c.begin();
  277. typename Container::iterator c_end = c.end();
  278. erase(arg1, arg2, arg3)(c, c_begin, c_end);
  279. if (test(!c.empty())) {
  280. cerr << "Failed " << typeid(Container).name() << " test_erase 2\n";
  281. return;
  282. }
  283. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  284. erase(arg1, const_c.begin())(const_c);
  285. erase(arg1, const_c.begin(), const_c.end())(const_c);
  286. #endif
  287. }
  288. template <typename Container>
  289. void test_map_erase(Container c)
  290. {
  291. test_erase(c);
  292. if (boost::report_errors() != 0)
  293. return;
  294. using phx::arg_names::arg1;
  295. using phx::arg_names::arg2;
  296. using phx::erase;
  297. typename Container::value_type const value = *c.begin();
  298. typename Container::key_type const key = value.first;
  299. typename Container::size_type const removed =
  300. erase(arg1, arg2)(c, key);
  301. if (test(removed != 1)) {
  302. cerr << "Failed " << typeid(Container).name() << " test_map_erase 1\n";
  303. return;
  304. }
  305. }
  306. template <typename Container>
  307. void test_set_erase(Container c)
  308. {
  309. test_erase(c);
  310. if (boost::report_errors() != 0)
  311. return;
  312. using phx::arg_names::arg1;
  313. using phx::arg_names::arg2;
  314. using phx::erase;
  315. typename Container::value_type const value = *c.begin();
  316. typename Container::key_type const key = value;
  317. typename Container::size_type const removed =
  318. erase(arg1, arg2)(c, key);
  319. if (test(removed != 1)) {
  320. cerr << "Failed " << typeid(Container).name() << " test_set_erase 1\n";
  321. return;
  322. }
  323. }
  324. template <typename Container>
  325. void test_front(Container c)
  326. {
  327. using phx::arg_names::arg1;
  328. using phx::front;
  329. typename Container::reference r1 = front(arg1)(c);
  330. if (test(r1 != c.front())) {
  331. cerr << "Failed " << typeid(Container).name() << " test_front 1\n";
  332. return;
  333. }
  334. typename Container::const_reference r2 = front(arg1)(c);
  335. if (test(r2 != c.front())) {
  336. cerr << "Failed " << typeid(Container).name() << " test_front 2\n";
  337. return;
  338. }
  339. Container const const_c = c;
  340. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  341. // Should not --- does not, Yay! --- compile.
  342. typename Container::reference r3 = front(arg1)(const_c);
  343. #endif
  344. typename Container::const_reference r4 = front(arg1)(const_c);
  345. if (test(r4 != c.front())) {
  346. cerr << "Failed " << typeid(Container).name() << " test_front 4\n";
  347. return;
  348. }
  349. }
  350. template <typename Container>
  351. void test_get_allocator(Container c)
  352. {
  353. using phx::arg_names::arg1;
  354. using phx::get_allocator;
  355. Container const const_c = c;
  356. typename Container::allocator_type a1 = get_allocator(arg1)(c);
  357. if (test(a1 != c.get_allocator())) {
  358. cerr << "Failed " << typeid(Container).name() << " test_get_allocator 1\n";
  359. return;
  360. }
  361. typename Container::allocator_type a2 = get_allocator(arg1)(const_c);
  362. if (test(a2 != const_c.get_allocator())) {
  363. cerr << "Failed " << typeid(Container).name() << " test_get_allocator 2\n";
  364. return;
  365. }
  366. }
  367. template <typename Container>
  368. void test_insert(Container c)
  369. {
  370. using phx::arg_names::arg1;
  371. using phx::insert;
  372. typename Container::value_type const value = *c.begin();
  373. typename Container::iterator it = insert(arg1, c.begin(), value)(c);
  374. if (test(it != c.begin() || *it != *(++it))) {
  375. cerr << "Failed " << typeid(Container).name() << " test_insert 1\n";
  376. return;
  377. }
  378. typename Container::size_type size = c.size();
  379. insert(arg1, c.begin(), 3, value)(c);
  380. if (test(c.size() != size + 3)) {
  381. cerr << "Failed " << typeid(Container).name() << " test_insert 2\n";
  382. return;
  383. }
  384. Container const const_c = c;
  385. size = c.size();
  386. insert(arg1, c.begin(), const_c.begin(), const_c.end())(c);
  387. if (test(c.size() != 2 * size)) {
  388. cerr << "Failed " << typeid(Container).name() << " test_insert 3\n";
  389. return;
  390. }
  391. }
  392. template <typename Map>
  393. inline void test_map_insert(Map c)
  394. {
  395. using phx::arg_names::arg1;
  396. using phx::arg_names::arg2;
  397. using phx::arg_names::arg3;
  398. typename Map::value_type const value = *c.begin();
  399. typename Map::iterator c_begin = c.begin();
  400. // wrapper for
  401. // iterator insert(iterator where, const value_type& val);
  402. typename Map::iterator it =
  403. phx::insert(arg1, arg2, arg3)(c, c_begin, value);
  404. if (test(it != c.begin() /*|| *it != *(++it)*/)) {
  405. cerr << "Failed " << typeid(Map).name() << " test_map_insert 1\n";
  406. return;
  407. }
  408. // wrapper for
  409. // pair<iterator, bool> insert(const value_type& val);
  410. typename Map::value_type const value2(1400, 2200);
  411. std::pair<typename Map::iterator, bool> result =
  412. phx::insert(arg1, arg2)(c, value2);
  413. if (test(!result.second)) {
  414. cerr << "Failed " << typeid(Map).name() << " test_map_insert 2\n";
  415. return;
  416. }
  417. // wrapper for
  418. // template<class InIt>
  419. // void insert(InIt first, InIt last);
  420. Map const const_c = build_assoc<Map>();
  421. typename Map::size_type size = c.size();
  422. phx::insert(arg1, const_c.begin(), const_c.end())(c);
  423. if (test(c.size() != size + const_c.size())) {
  424. cerr << "Failed " << typeid(Map).name() << " test_map_insert 3\n";
  425. return;
  426. }
  427. }
  428. template <typename Multimap>
  429. inline void test_multimap_insert(Multimap c)
  430. {
  431. using phx::arg_names::arg1;
  432. using phx::arg_names::arg2;
  433. using phx::arg_names::arg3;
  434. typename Multimap::value_type const value = *c.begin();
  435. typename Multimap::iterator c_begin = c.begin();
  436. std::size_t old_size = c.size();
  437. // wrapper for
  438. // iterator insert(iterator where, const value_type& val);
  439. typename Multimap::iterator it =
  440. phx::insert(arg1, arg2, arg3)(c, c_begin, value);
  441. if (test(*it != value || c.size() != old_size + 1)) {
  442. cerr << "Failed " << typeid(Multimap).name()
  443. << " test_multimap_insert 1\n";
  444. return;
  445. }
  446. // wrapper for
  447. // iterator insert(const value_type& val);
  448. typename Multimap::value_type const value2(1400, 2200);
  449. it = phx::insert(arg1, arg2)(c, value2);
  450. if (test(it == c.end())) {
  451. cerr << "Failed " << typeid(Multimap).name()
  452. << " test_multimap_insert 2\n";
  453. return;
  454. }
  455. // wrapper for
  456. // template<class InIt>
  457. // void insert(InIt first, InIt last);
  458. Multimap const const_c = build_assoc<Multimap>();
  459. typename Multimap::size_type size = c.size();
  460. phx::insert(arg1, const_c.begin(), const_c.end())(c);
  461. if (test(c.size() != size + const_c.size())) {
  462. cerr << "Failed " << typeid(Multimap).name()
  463. << " test_multimap_insert 3\n";
  464. return;
  465. }
  466. }
  467. template <typename Set>
  468. inline void test_set_insert(Set c)
  469. {
  470. using phx::arg_names::arg1;
  471. using phx::arg_names::arg2;
  472. using phx::arg_names::arg3;
  473. typename Set::value_type const value = *c.begin();
  474. typename Set::iterator c_begin = c.begin();
  475. // wrapper for
  476. // iterator insert(iterator where, const value_type& val);
  477. typename Set::iterator it =
  478. phx::insert(arg1, arg2, arg3)(c, c_begin, value);
  479. if (test(it != c.begin() /*|| *it != *(++it)*/)) {
  480. cerr << "Failed " << typeid(Set).name() << " test_set_insert 1\n";
  481. return;
  482. }
  483. // wrapper for
  484. // pair<iterator, bool> insert(const value_type& val);
  485. typename Set::value_type const value2(1400);
  486. std::pair<typename Set::iterator, bool> result =
  487. phx::insert(arg1, arg2)(c, value2);
  488. if (test(!result.second)) {
  489. cerr << "Failed " << typeid(Set).name() << " test_set_insert 2\n";
  490. return;
  491. }
  492. // wrapper for
  493. // template<class InIt>
  494. // void insert(InIt first, InIt last);
  495. Set const const_c = build_assoc<Set>();
  496. typename Set::size_type size = c.size();
  497. phx::insert(arg1, const_c.begin(), const_c.end())(c);
  498. if (test(c.size() != size + const_c.size())) {
  499. cerr << "Failed " << typeid(Set).name() << " test_set_insert 3\n";
  500. return;
  501. }
  502. }
  503. template <typename Multiset>
  504. inline void test_multiset_insert(Multiset c)
  505. {
  506. using phx::arg_names::arg1;
  507. using phx::arg_names::arg2;
  508. using phx::arg_names::arg3;
  509. typename Multiset::value_type const value = *c.begin();
  510. typename Multiset::iterator c_begin = c.begin();
  511. std::size_t old_size = c.size();
  512. // wrapper for
  513. // iterator insert(iterator where, const value_type& val);
  514. typename Multiset::iterator it =
  515. phx::insert(arg1, arg2, arg3)(c, c_begin, value);
  516. if (test(*it != value || c.size() != old_size + 1)) {
  517. cerr << "Failed " << typeid(Multiset).name()
  518. << " test_multiset_insert 1\n";
  519. return;
  520. }
  521. // wrapper for
  522. // iterator insert(const value_type& val);
  523. typename Multiset::value_type const value2(1400);
  524. it = phx::insert(arg1, arg2)(c, value2);
  525. if (test(it == c.end())) {
  526. cerr << "Failed " << typeid(Multiset).name()
  527. << " test_multiset_insert 2\n";
  528. return;
  529. }
  530. // wrapper for
  531. // template<class InIt>
  532. // void insert(InIt first, InIt last);
  533. Multiset const const_c = build_assoc<Multiset>();
  534. typename Multiset::size_type size = c.size();
  535. phx::insert(arg1, const_c.begin(), const_c.end())(c);
  536. if (test(c.size() != size + const_c.size())) {
  537. cerr << "Failed " << typeid(Multiset).name()
  538. << " test_multiset_insert 3\n";
  539. return;
  540. }
  541. }
  542. template <typename Container>
  543. void test_key_comp(Container c)
  544. {
  545. using phx::arg_names::arg1;
  546. using phx::key_comp;
  547. typename Container::key_compare comp = key_comp(arg1)(c);
  548. Container const const_c = c;
  549. comp = key_comp(arg1)(const_c);
  550. }
  551. template <typename Container>
  552. void test_max_size(Container c)
  553. {
  554. using phx::arg_names::arg1;
  555. using phx::max_size;
  556. Container const const_c = c;
  557. typename Container::size_type s1 = max_size(arg1)(c);
  558. if (test(s1 != c.max_size())) {
  559. cerr << "Failed " << typeid(Container).name() << " test_max_size 1\n";
  560. return;
  561. }
  562. typename Container::size_type s2 = max_size(arg1)(const_c);
  563. if (test(s2 != const_c.max_size())) {
  564. cerr << "Failed " << typeid(Container).name() << " test_max_size 2\n";
  565. return;
  566. }
  567. }
  568. template <typename Container>
  569. void test_pop_back(Container c)
  570. {
  571. using phx::arg_names::arg1;
  572. using phx::pop_back;
  573. Container const const_c = c;
  574. typename Container::size_type size = c.size();
  575. pop_back(arg1)(c);
  576. if (test(c.size() + 1 != size)) {
  577. cerr << "Failed " << typeid(Container).name() << " test_pop_back 1\n";
  578. return;
  579. }
  580. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  581. pop_back(arg1)(const_c);
  582. #endif
  583. }
  584. template <typename Container>
  585. void test_pop_front(Container c)
  586. {
  587. using phx::arg_names::arg1;
  588. using phx::pop_front;
  589. Container const const_c = c;
  590. typename Container::size_type size = c.size();
  591. pop_front(arg1)(c);
  592. if (test(c.size() + 1 != size)) {
  593. cerr << "Failed " << typeid(Container).name() << " test_pop_front 1\n";
  594. return;
  595. }
  596. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  597. pop_front(arg1)(const_c);
  598. #endif
  599. }
  600. template <typename Container>
  601. void test_push_back(Container c)
  602. {
  603. using phx::arg_names::arg1;
  604. using phx::arg_names::arg2;
  605. using phx::push_back;
  606. Container const const_c = c;
  607. typename Container::value_type data = *c.begin();
  608. typename Container::size_type size = c.size();
  609. push_back(arg1, arg2)(c, data);
  610. if (test(c.size() != size + 1)) {
  611. cerr << "Failed " << typeid(Container).name() << " test_push_back 1\n";
  612. return;
  613. }
  614. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  615. push_back(arg1, arg2)(const_c, data);
  616. #endif
  617. }
  618. template <typename Container>
  619. void test_push_front(Container c)
  620. {
  621. using phx::arg_names::arg1;
  622. using phx::arg_names::arg2;
  623. using phx::push_front;
  624. Container const const_c = c;
  625. typename Container::value_type data = *c.begin();
  626. typename Container::size_type size = c.size();
  627. push_front(arg1, arg2)(c, data);
  628. if (test(c.size() != size + 1)) {
  629. cerr << "Failed " << typeid(Container).name() << " test_push_front 1\n";
  630. return;
  631. }
  632. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  633. push_front(arg1, arg2)(const_c, data);
  634. #endif
  635. }
  636. template <typename Container>
  637. void test_rbegin(Container c)
  638. {
  639. using phx::arg_names::arg1;
  640. using phx::rbegin;
  641. typename Container::reverse_iterator it1 = rbegin(arg1)(c);
  642. typename Container::reverse_iterator it1_test = c.rbegin();
  643. if (test(it1 != it1_test)) {
  644. cerr << "Failed " << typeid(Container).name() << " test_rbegin 1\n";
  645. return;
  646. }
  647. typename Container::const_reverse_iterator it2 = rbegin(arg1)(c);
  648. typename Container::const_reverse_iterator it2_test = c.rbegin();
  649. if (test(it2 != it2_test)) {
  650. cerr << "Failed " << typeid(Container).name() << " test_rbegin 2\n";
  651. return;
  652. }
  653. Container const const_c = c;
  654. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  655. // Should not --- does not, Yay! --- compile.
  656. typename Container::reverse_iterator it3 = rbegin(arg1)(const_c);
  657. #endif
  658. typename Container::const_reverse_iterator it4 = rbegin(arg1)(const_c);
  659. it2_test = const_c.rbegin();
  660. if (test(it4 != it2_test)) {
  661. cerr << "Failed " << typeid(Container).name() << " test_rbegin 4\n";
  662. return;
  663. }
  664. }
  665. template <typename Container>
  666. void test_rend(Container c)
  667. {
  668. using phx::arg_names::arg1;
  669. using phx::rend;
  670. typename Container::reverse_iterator it1 = rend(arg1)(c);
  671. typename Container::reverse_iterator it1_test = c.rend();
  672. if (test(it1 != it1_test)) {
  673. cerr << "Failed " << typeid(Container).name() << " test_rend 1\n";
  674. return;
  675. }
  676. typename Container::const_reverse_iterator it2 = rend(arg1)(c);
  677. typename Container::const_reverse_iterator it2_test = c.rend();
  678. if (test(it2 != it2_test)) {
  679. cerr << "Failed " << typeid(Container).name() << " test_rend 2\n";
  680. return;
  681. }
  682. Container const const_c = c;
  683. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  684. // Should not --- does not, Yay! --- compile.
  685. typename Container::reverse_iterator it3 = rend(arg1)(const_c);
  686. #endif
  687. typename Container::const_reverse_iterator it4 = rend(arg1)(const_c);
  688. it2_test = const_c.rend();
  689. if (test(it4 != it2_test)) {
  690. cerr << "Failed " << typeid(Container).name() << " test_rend 4\n";
  691. return;
  692. }
  693. }
  694. template <typename Container>
  695. void test_reserve(Container c)
  696. {
  697. using phx::arg_names::arg1;
  698. using phx::reserve;
  699. Container const const_c = c;
  700. typename Container::size_type count = 2 * c.size();
  701. reserve(arg1, count)(c);
  702. if (test(c.capacity() < count)) {
  703. cerr << "Failed " << typeid(Container).name() << " test_reserve 1\n";
  704. return;
  705. }
  706. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  707. reserve(arg1, count)(const_c)(const_c);
  708. #endif
  709. }
  710. template <typename Container>
  711. void test_resize(Container c)
  712. {
  713. using phx::arg_names::arg1;
  714. using phx::resize;
  715. Container const const_c = c;
  716. typename Container::size_type new_size = 2 * c.size();
  717. resize(arg1, new_size)(c);
  718. if (test(c.size() != new_size)) {
  719. cerr << "Failed " << typeid(Container).name() << " test_resize 1\n";
  720. return;
  721. }
  722. new_size = 2 * c.size();
  723. typename Container::value_type value = *c.begin();
  724. resize(arg1, new_size, value)(c);
  725. if (test(c.size() != new_size)) {
  726. cerr << "Failed " << typeid(Container).name() << " test_resize 2\n";
  727. return;
  728. }
  729. #if defined(BOOST_PHOENIX_COMPILE_FAIL_TEST)
  730. new_size = 2 * const_c.size();
  731. resize(arg1, new_size)(const_c);
  732. new_size = 2 * const_c.size();
  733. resize(arg1, new_size, value)(const_c);
  734. #endif
  735. }
  736. template <typename Container>
  737. void test_size(Container c)
  738. {
  739. using phx::arg_names::arg1;
  740. using phx::size;
  741. Container const const_c = c;
  742. typename Container::size_type s1 = size(arg1)(c);
  743. if (test(s1 != c.size())) {
  744. cerr << "Failed " << typeid(Container).name() << " test_size 1\n";
  745. return;
  746. }
  747. typename Container::size_type s2 = size(arg1)(const_c);
  748. if (test(s2 != const_c.size())) {
  749. cerr << "Failed " << typeid(Container).name() << " test_size 2\n";
  750. return;
  751. }
  752. }
  753. template <typename Container>
  754. void test_splice(Container c)
  755. {
  756. using phx::arg_names::arg1;
  757. using phx::arg_names::arg2;
  758. using phx::arg_names::arg3;
  759. using phx::arg_names::arg4;
  760. using phx::arg_names::arg5;
  761. using phx::splice;
  762. typename Container::iterator c_end;
  763. typename Container::iterator c2_begin;
  764. typename Container::iterator c2_end;
  765. typename Container::size_type size = c.size();
  766. Container const copy = c;
  767. Container const copy2 = build_list();
  768. Container c2 = copy2;
  769. size = c.size();
  770. c_end = c.end();
  771. splice(arg1, arg2, arg3)(c, c_end, c2);
  772. if (test(c.size() != 2 * size)) {
  773. cerr << "Failed " << typeid(Container).name() << " test_splice 1\n";
  774. return;
  775. }
  776. c = copy;
  777. c_end = c.end();
  778. c2 = copy2;
  779. c2_begin = c2.begin();
  780. size = c.size() + 1;
  781. splice(arg1, arg2, arg3, arg4)(c, c_end, c2, c2_begin);
  782. if (test(c.size() != size)) {
  783. cerr << "Failed " << typeid(Container).name() << " test_splice 2\n";
  784. return;
  785. }
  786. c = copy;
  787. c_end = c.end();
  788. c2 = copy2;
  789. c2_begin = c2.begin();
  790. c2_end = c2.end();
  791. size = c.size() + c2.size();
  792. /*
  793. splice(arg1, arg2, arg3, arg4, arg5)(c, c_end, c2, c2_begin, c2_end);
  794. if (test(c.size() != size)) {
  795. cerr << "Failed " << typeid(Container).name() << " test_splice 3\n";
  796. return;
  797. }
  798. */
  799. }
  800. template <typename Container>
  801. void test_value_comp(Container c)
  802. {
  803. using phx::arg_names::arg1;
  804. using phx::value_comp;
  805. typename Container::value_compare comp = value_comp(arg1)(c);
  806. Container const const_c = c;
  807. comp = value_comp(arg1)(const_c);
  808. }
  809. #endif