zip_iterator_test_original.ipp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. // (C) Copyright Dave Abrahams and Thomas Becker 2003. Distributed
  2. // under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. // File:
  7. // =====
  8. // zip_iterator_test_main.cpp
  9. // Author:
  10. // =======
  11. // Thomas Becker
  12. // Created:
  13. // ========
  14. // Jul 15, 2003
  15. // Purpose:
  16. // ========
  17. // Test driver for zip_iterator.hpp
  18. // Compilers Tested:
  19. // =================
  20. // Metrowerks Codewarrior Pro 7.2, 8.3
  21. // gcc 2.95.3
  22. // gcc 3.2
  23. // Microsoft VC 6sp5 (test fails due to some compiler bug)
  24. // Microsoft VC 7 (works)
  25. // Microsoft VC 7.1
  26. // Intel 5
  27. // Intel 6
  28. // Intel 7.1
  29. // Intel 8
  30. // Borland 5.5.1 (broken due to lack of support from Boost.Tuples)
  31. /////////////////////////////////////////////////////////////////////////////
  32. //
  33. // Includes
  34. //
  35. /////////////////////////////////////////////////////////////////////////////
  36. #include <boost/iterator/zip_iterator.hpp>
  37. #include <boost/iterator/zip_iterator.hpp> // 2nd #include tests #include guard.
  38. #include <iostream>
  39. #include <vector>
  40. #include <list>
  41. #include <set>
  42. #include <string>
  43. #include <functional>
  44. #include <boost/iterator/transform_iterator.hpp>
  45. #include <boost/iterator/is_readable_iterator.hpp>
  46. #include <boost/type_traits/is_same.hpp>
  47. #include <boost/detail/workaround.hpp>
  48. #include <stddef.h>
  49. /// Tests for https://svn.boost.org/trac/boost/ticket/1517
  50. int to_value(int const &v)
  51. {
  52. return v;
  53. }
  54. void category_test()
  55. {
  56. std::list<int> rng1;
  57. std::string rng2;
  58. boost::make_zip_iterator(
  59. ZI_MAKE_TUPLE(
  60. boost::make_transform_iterator(rng1.begin(), &to_value), // BidirectionalInput
  61. rng2.begin() // RandomAccess
  62. )
  63. );
  64. }
  65. ///
  66. /////////////////////////////////////////////////////////////////////////////
  67. //
  68. // Das Main Funktion
  69. //
  70. /////////////////////////////////////////////////////////////////////////////
  71. int main( void )
  72. {
  73. category_test();
  74. std::cout << "\n"
  75. << "***********************************************\n"
  76. << "* *\n"
  77. << "* Test driver for boost::zip_iterator *\n"
  78. << "* Copyright Thomas Becker 2003 *\n"
  79. << "* *\n"
  80. << "***********************************************\n\n"
  81. << std::flush;
  82. size_t num_successful_tests = 0;
  83. size_t num_failed_tests = 0;
  84. /////////////////////////////////////////////////////////////////////////////
  85. //
  86. // Zip iterator construction and dereferencing
  87. //
  88. /////////////////////////////////////////////////////////////////////////////
  89. std::cout << "Zip iterator construction and dereferencing: "
  90. << std::flush;
  91. std::vector<double> vect1(3);
  92. vect1[0] = 42.;
  93. vect1[1] = 43.;
  94. vect1[2] = 44.;
  95. std::set<int> intset;
  96. intset.insert(52);
  97. intset.insert(53);
  98. intset.insert(54);
  99. //
  100. typedef
  101. boost::zip_iterator<
  102. ZI_TUPLE<
  103. std::set<int>::iterator
  104. , std::vector<double>::iterator
  105. >
  106. > zit_mixed;
  107. zit_mixed zip_it_mixed = zit_mixed(
  108. ZI_MAKE_TUPLE(
  109. intset.begin()
  110. , vect1.begin()
  111. )
  112. );
  113. ZI_TUPLE<int, double> val_tuple(
  114. *zip_it_mixed);
  115. ZI_TUPLE<const int&, double&> ref_tuple(
  116. *zip_it_mixed);
  117. double dblOldVal = ZI_TUPLE_GET(1)(ref_tuple);
  118. ZI_TUPLE_GET(1)(ref_tuple) -= 41.;
  119. if( 52 == ZI_TUPLE_GET(0)(val_tuple) &&
  120. 42. == ZI_TUPLE_GET(1)(val_tuple) &&
  121. 52 == ZI_TUPLE_GET(0)(ref_tuple) &&
  122. 1. == ZI_TUPLE_GET(1)(ref_tuple) &&
  123. 1. == *vect1.begin()
  124. )
  125. {
  126. ++num_successful_tests;
  127. std::cout << "OK" << std::endl;
  128. }
  129. else
  130. {
  131. ++num_failed_tests;
  132. std::cout << "not OK" << std::endl;
  133. }
  134. // Undo change to vect1
  135. ZI_TUPLE_GET(1)(ref_tuple) = dblOldVal;
  136. #if defined(ZI_USE_BOOST_TUPLE)
  137. /////////////////////////////////////////////////////////////////////////////
  138. //
  139. // Zip iterator with 12 components
  140. //
  141. /////////////////////////////////////////////////////////////////////////////
  142. std::cout << "Zip iterators with 12 components: "
  143. << std::flush;
  144. // Declare 12 containers
  145. //
  146. std::list<int> li1;
  147. li1.push_back(1);
  148. std::set<int> se1;
  149. se1.insert(2);
  150. std::vector<int> ve1;
  151. ve1.push_back(3);
  152. //
  153. std::list<int> li2;
  154. li2.push_back(4);
  155. std::set<int> se2;
  156. se2.insert(5);
  157. std::vector<int> ve2;
  158. ve2.push_back(6);
  159. //
  160. std::list<int> li3;
  161. li3.push_back(7);
  162. std::set<int> se3;
  163. se3.insert(8);
  164. std::vector<int> ve3;
  165. ve3.push_back(9);
  166. //
  167. std::list<int> li4;
  168. li4.push_back(10);
  169. std::set<int> se4;
  170. se4.insert(11);
  171. std::vector<int> ve4;
  172. ve4.push_back(12);
  173. // typedefs for cons lists of iterators.
  174. typedef boost::tuples::cons<
  175. std::set<int>::iterator,
  176. ZI_TUPLE<
  177. std::vector<int>::iterator,
  178. std::list<int>::iterator,
  179. std::set<int>::iterator,
  180. std::vector<int>::iterator,
  181. std::list<int>::iterator,
  182. std::set<int>::iterator,
  183. std::vector<int>::iterator,
  184. std::list<int>::iterator,
  185. std::set<int>::iterator,
  186. std::vector<int>::const_iterator
  187. >::inherited
  188. > cons_11_its_type;
  189. //
  190. typedef boost::tuples::cons<
  191. std::list<int>::const_iterator,
  192. cons_11_its_type
  193. > cons_12_its_type;
  194. // typedefs for cons lists for dereferencing the zip iterator
  195. // made from the cons list above.
  196. typedef boost::tuples::cons<
  197. const int&,
  198. ZI_TUPLE<
  199. int&,
  200. int&,
  201. const int&,
  202. int&,
  203. int&,
  204. const int&,
  205. int&,
  206. int&,
  207. const int&,
  208. const int&
  209. >::inherited
  210. > cons_11_refs_type;
  211. //
  212. typedef boost::tuples::cons<
  213. const int&,
  214. cons_11_refs_type
  215. > cons_12_refs_type;
  216. // typedef for zip iterator with 12 elements
  217. typedef boost::zip_iterator<cons_12_its_type> zip_it_12_type;
  218. // Declare a 12-element zip iterator.
  219. zip_it_12_type zip_it_12(
  220. cons_12_its_type(
  221. li1.begin(),
  222. cons_11_its_type(
  223. se1.begin(),
  224. ZI_MAKE_TUPLE(
  225. ve1.begin(),
  226. li2.begin(),
  227. se2.begin(),
  228. ve2.begin(),
  229. li3.begin(),
  230. se3.begin(),
  231. ve3.begin(),
  232. li4.begin(),
  233. se4.begin(),
  234. ve4.begin()
  235. )
  236. )
  237. )
  238. );
  239. // Dereference, mess with the result a little.
  240. cons_12_refs_type zip_it_12_dereferenced(*zip_it_12);
  241. ZI_TUPLE_GET(9)(zip_it_12_dereferenced) = 42;
  242. // Make a copy and move it a little to force some instantiations.
  243. zip_it_12_type zip_it_12_copy(zip_it_12);
  244. ++zip_it_12_copy;
  245. if( ZI_TUPLE_GET(11)(zip_it_12.get_iterator_tuple()) == ve4.begin() &&
  246. ZI_TUPLE_GET(11)(zip_it_12_copy.get_iterator_tuple()) == ve4.end() &&
  247. 1 == ZI_TUPLE_GET(0)(zip_it_12_dereferenced) &&
  248. 12 == ZI_TUPLE_GET(11)(zip_it_12_dereferenced) &&
  249. 42 == *(li4.begin())
  250. )
  251. {
  252. ++num_successful_tests;
  253. std::cout << "OK" << std::endl;
  254. }
  255. else
  256. {
  257. ++num_failed_tests;
  258. std::cout << "not OK" << std::endl;
  259. }
  260. #endif
  261. /////////////////////////////////////////////////////////////////////////////
  262. //
  263. // Zip iterator incrementing and dereferencing
  264. //
  265. /////////////////////////////////////////////////////////////////////////////
  266. std::cout << "Zip iterator ++ and *: "
  267. << std::flush;
  268. std::vector<double> vect2(3);
  269. vect2[0] = 2.2;
  270. vect2[1] = 3.3;
  271. vect2[2] = 4.4;
  272. boost::zip_iterator<
  273. ZI_TUPLE<
  274. std::vector<double>::const_iterator,
  275. std::vector<double>::const_iterator
  276. >
  277. >
  278. zip_it_begin(
  279. ZI_MAKE_TUPLE(
  280. vect1.begin(),
  281. vect2.begin()
  282. )
  283. );
  284. boost::zip_iterator<
  285. ZI_TUPLE<
  286. std::vector<double>::const_iterator,
  287. std::vector<double>::const_iterator
  288. >
  289. >
  290. zip_it_run(
  291. ZI_MAKE_TUPLE(
  292. vect1.begin(),
  293. vect2.begin()
  294. )
  295. );
  296. boost::zip_iterator<
  297. ZI_TUPLE<
  298. std::vector<double>::const_iterator,
  299. std::vector<double>::const_iterator
  300. >
  301. >
  302. zip_it_end(
  303. ZI_MAKE_TUPLE(
  304. vect1.end(),
  305. vect2.end()
  306. )
  307. );
  308. if( zip_it_run == zip_it_begin &&
  309. 42. == ZI_TUPLE_GET(0)(*zip_it_run) &&
  310. 2.2 == ZI_TUPLE_GET(1)(*zip_it_run) &&
  311. 43. == ZI_TUPLE_GET(0)(*(++zip_it_run)) &&
  312. 3.3 == ZI_TUPLE_GET(1)(*zip_it_run) &&
  313. 44. == ZI_TUPLE_GET(0)(*(++zip_it_run)) &&
  314. 4.4 == ZI_TUPLE_GET(1)(*zip_it_run) &&
  315. zip_it_end == ++zip_it_run
  316. )
  317. {
  318. ++num_successful_tests;
  319. std::cout << "OK" << std::endl;
  320. }
  321. else
  322. {
  323. ++num_failed_tests;
  324. std::cout << "not OK" << std::endl;
  325. }
  326. /////////////////////////////////////////////////////////////////////////////
  327. //
  328. // Zip iterator decrementing and dereferencing
  329. //
  330. /////////////////////////////////////////////////////////////////////////////
  331. std::cout << "Zip iterator -- and *: "
  332. << std::flush;
  333. if( zip_it_run == zip_it_end &&
  334. zip_it_end == zip_it_run-- &&
  335. 44. == ZI_TUPLE_GET(0)(*zip_it_run) &&
  336. 4.4 == ZI_TUPLE_GET(1)(*zip_it_run) &&
  337. 43. == ZI_TUPLE_GET(0)(*(--zip_it_run)) &&
  338. 3.3 == ZI_TUPLE_GET(1)(*zip_it_run) &&
  339. 42. == ZI_TUPLE_GET(0)(*(--zip_it_run)) &&
  340. 2.2 == ZI_TUPLE_GET(1)(*zip_it_run) &&
  341. zip_it_begin == zip_it_run
  342. )
  343. {
  344. ++num_successful_tests;
  345. std::cout << "OK" << std::endl;
  346. }
  347. else
  348. {
  349. ++num_failed_tests;
  350. std::cout << "not OK" << std::endl;
  351. }
  352. /////////////////////////////////////////////////////////////////////////////
  353. //
  354. // Zip iterator copy construction and equality
  355. //
  356. /////////////////////////////////////////////////////////////////////////////
  357. std::cout << "Zip iterator copy construction and equality: "
  358. << std::flush;
  359. boost::zip_iterator<
  360. ZI_TUPLE<
  361. std::vector<double>::const_iterator,
  362. std::vector<double>::const_iterator
  363. >
  364. > zip_it_run_copy(zip_it_run);
  365. if(zip_it_run == zip_it_run && zip_it_run == zip_it_run_copy)
  366. {
  367. ++num_successful_tests;
  368. std::cout << "OK" << std::endl;
  369. }
  370. else
  371. {
  372. ++num_failed_tests;
  373. std::cout << "not OK" << std::endl;
  374. }
  375. /////////////////////////////////////////////////////////////////////////////
  376. //
  377. // Zip iterator inequality
  378. //
  379. /////////////////////////////////////////////////////////////////////////////
  380. std::cout << "Zip iterator inequality: "
  381. << std::flush;
  382. if(!(zip_it_run != zip_it_run_copy) && zip_it_run != ++zip_it_run_copy)
  383. {
  384. ++num_successful_tests;
  385. std::cout << "OK" << std::endl;
  386. }
  387. else
  388. {
  389. ++num_failed_tests;
  390. std::cout << "not OK" << std::endl;
  391. }
  392. /////////////////////////////////////////////////////////////////////////////
  393. //
  394. // Zip iterator less than
  395. //
  396. /////////////////////////////////////////////////////////////////////////////
  397. std::cout << "Zip iterator less than: "
  398. << std::flush;
  399. // Note: zip_it_run_copy == zip_it_run + 1
  400. //
  401. if( zip_it_run < zip_it_run_copy &&
  402. !( zip_it_run < --zip_it_run_copy) &&
  403. zip_it_run == zip_it_run_copy
  404. )
  405. {
  406. ++num_successful_tests;
  407. std::cout << "OK" << std::endl;
  408. }
  409. else
  410. {
  411. ++num_failed_tests;
  412. std::cout << "not OK" << std::endl;
  413. }
  414. /////////////////////////////////////////////////////////////////////////////
  415. //
  416. // Zip iterator less than or equal
  417. //
  418. /////////////////////////////////////////////////////////////////////////////
  419. std::cout << "zip iterator less than or equal: "
  420. << std::flush;
  421. // Note: zip_it_run_copy == zip_it_run
  422. //
  423. ++zip_it_run;
  424. zip_it_run_copy += 2;
  425. if( zip_it_run <= zip_it_run_copy &&
  426. zip_it_run <= --zip_it_run_copy &&
  427. !( zip_it_run <= --zip_it_run_copy) &&
  428. zip_it_run <= zip_it_run
  429. )
  430. {
  431. ++num_successful_tests;
  432. std::cout << "OK" << std::endl;
  433. }
  434. else
  435. {
  436. ++num_failed_tests;
  437. std::cout << "not OK" << std::endl;
  438. }
  439. /////////////////////////////////////////////////////////////////////////////
  440. //
  441. // Zip iterator greater than
  442. //
  443. /////////////////////////////////////////////////////////////////////////////
  444. std::cout << "Zip iterator greater than: "
  445. << std::flush;
  446. // Note: zip_it_run_copy == zip_it_run - 1
  447. //
  448. if( zip_it_run > zip_it_run_copy &&
  449. !( zip_it_run > ++zip_it_run_copy) &&
  450. zip_it_run == zip_it_run_copy
  451. )
  452. {
  453. ++num_successful_tests;
  454. std::cout << "OK" << std::endl;
  455. }
  456. else
  457. {
  458. ++num_failed_tests;
  459. std::cout << "not OK" << std::endl;
  460. }
  461. /////////////////////////////////////////////////////////////////////////////
  462. //
  463. // Zip iterator greater than or equal
  464. //
  465. /////////////////////////////////////////////////////////////////////////////
  466. std::cout << "Zip iterator greater than or equal: "
  467. << std::flush;
  468. ++zip_it_run;
  469. // Note: zip_it_run == zip_it_run_copy + 1
  470. //
  471. if( zip_it_run >= zip_it_run_copy &&
  472. --zip_it_run >= zip_it_run_copy &&
  473. ! (zip_it_run >= ++zip_it_run_copy)
  474. )
  475. {
  476. ++num_successful_tests;
  477. std::cout << "OK" << std::endl;
  478. }
  479. else
  480. {
  481. ++num_failed_tests;
  482. std::cout << "not OK" << std::endl;
  483. }
  484. /////////////////////////////////////////////////////////////////////////////
  485. //
  486. // Zip iterator + int
  487. //
  488. /////////////////////////////////////////////////////////////////////////////
  489. std::cout << "Zip iterator + int: "
  490. << std::flush;
  491. // Note: zip_it_run == zip_it_run_copy - 1
  492. //
  493. zip_it_run = zip_it_run + 2;
  494. ++zip_it_run_copy;
  495. if( zip_it_run == zip_it_run_copy && zip_it_run == zip_it_begin + 3 )
  496. {
  497. ++num_successful_tests;
  498. std::cout << "OK" << std::endl;
  499. }
  500. else
  501. {
  502. ++num_failed_tests;
  503. std::cout << "not OK" << std::endl;
  504. }
  505. /////////////////////////////////////////////////////////////////////////////
  506. //
  507. // Zip iterator - int
  508. //
  509. /////////////////////////////////////////////////////////////////////////////
  510. std::cout << "Zip iterator - int: "
  511. << std::flush;
  512. // Note: zip_it_run == zip_it_run_copy, and both are at end position
  513. //
  514. zip_it_run = zip_it_run - 2;
  515. --zip_it_run_copy;
  516. --zip_it_run_copy;
  517. if( zip_it_run == zip_it_run_copy && (zip_it_run - 1) == zip_it_begin )
  518. {
  519. ++num_successful_tests;
  520. std::cout << "OK" << std::endl;
  521. }
  522. else
  523. {
  524. ++num_failed_tests;
  525. std::cout << "not OK" << std::endl;
  526. }
  527. /////////////////////////////////////////////////////////////////////////////
  528. //
  529. // Zip iterator +=
  530. //
  531. /////////////////////////////////////////////////////////////////////////////
  532. std::cout << "Zip iterator +=: "
  533. << std::flush;
  534. // Note: zip_it_run == zip_it_run_copy, and both are at begin + 1
  535. //
  536. zip_it_run += 2;
  537. if( zip_it_run == zip_it_begin + 3 )
  538. {
  539. ++num_successful_tests;
  540. std::cout << "OK" << std::endl;
  541. }
  542. else
  543. {
  544. ++num_failed_tests;
  545. std::cout << "not OK" << std::endl;
  546. }
  547. /////////////////////////////////////////////////////////////////////////////
  548. //
  549. // Zip iterator -=
  550. //
  551. /////////////////////////////////////////////////////////////////////////////
  552. std::cout << "Zip iterator -=: "
  553. << std::flush;
  554. // Note: zip_it_run is at end position, zip_it_run_copy is at
  555. // begin plus one.
  556. //
  557. zip_it_run -= 2;
  558. if( zip_it_run == zip_it_run_copy )
  559. {
  560. ++num_successful_tests;
  561. std::cout << "OK" << std::endl;
  562. }
  563. else
  564. {
  565. ++num_failed_tests;
  566. std::cout << "not OK" << std::endl;
  567. }
  568. /////////////////////////////////////////////////////////////////////////////
  569. //
  570. // Zip iterator getting member iterators
  571. //
  572. /////////////////////////////////////////////////////////////////////////////
  573. std::cout << "Zip iterator member iterators: "
  574. << std::flush;
  575. // Note: zip_it_run and zip_it_run_copy are both at
  576. // begin plus one.
  577. //
  578. if( ZI_TUPLE_GET(0)(zip_it_run.get_iterator_tuple()) == vect1.begin() + 1 &&
  579. ZI_TUPLE_GET(1)(zip_it_run.get_iterator_tuple()) == vect2.begin() + 1
  580. )
  581. {
  582. ++num_successful_tests;
  583. std::cout << "OK" << std::endl;
  584. }
  585. else
  586. {
  587. ++num_failed_tests;
  588. std::cout << "not OK" << std::endl;
  589. }
  590. /////////////////////////////////////////////////////////////////////////////
  591. //
  592. // Making zip iterators
  593. //
  594. /////////////////////////////////////////////////////////////////////////////
  595. std::cout << "Making zip iterators: "
  596. << std::flush;
  597. std::vector<ZI_TUPLE<double, double> >
  598. vect_of_tuples(3);
  599. std::copy(
  600. boost::make_zip_iterator(
  601. ZI_MAKE_TUPLE(
  602. vect1.begin(),
  603. vect2.begin()
  604. )
  605. ),
  606. boost::make_zip_iterator(
  607. ZI_MAKE_TUPLE(
  608. vect1.end(),
  609. vect2.end()
  610. )
  611. ),
  612. vect_of_tuples.begin()
  613. );
  614. if( 42. == ZI_TUPLE_GET(0)(*vect_of_tuples.begin()) &&
  615. 2.2 == ZI_TUPLE_GET(1)(*vect_of_tuples.begin()) &&
  616. 43. == ZI_TUPLE_GET(0)(*(vect_of_tuples.begin() + 1)) &&
  617. 3.3 == ZI_TUPLE_GET(1)(*(vect_of_tuples.begin() + 1)) &&
  618. 44. == ZI_TUPLE_GET(0)(*(vect_of_tuples.begin() + 2)) &&
  619. 4.4 == ZI_TUPLE_GET(1)(*(vect_of_tuples.begin() + 2))
  620. )
  621. {
  622. ++num_successful_tests;
  623. std::cout << "OK" << std::endl;
  624. }
  625. else
  626. {
  627. ++num_failed_tests;
  628. std::cout << "not OK" << std::endl;
  629. }
  630. /////////////////////////////////////////////////////////////////////////////
  631. //
  632. // Zip iterator non-const --> const conversion
  633. //
  634. /////////////////////////////////////////////////////////////////////////////
  635. std::cout << "Zip iterator non-const to const conversion: "
  636. << std::flush;
  637. boost::zip_iterator<
  638. ZI_TUPLE<
  639. std::set<int>::const_iterator,
  640. std::vector<double>::const_iterator
  641. >
  642. >
  643. zip_it_const(
  644. ZI_MAKE_TUPLE(
  645. intset.begin(),
  646. vect2.begin()
  647. )
  648. );
  649. //
  650. boost::zip_iterator<
  651. ZI_TUPLE<
  652. std::set<int>::iterator,
  653. std::vector<double>::const_iterator
  654. >
  655. >
  656. zip_it_half_const(
  657. ZI_MAKE_TUPLE(
  658. intset.begin(),
  659. vect2.begin()
  660. )
  661. );
  662. //
  663. boost::zip_iterator<
  664. ZI_TUPLE<
  665. std::set<int>::iterator,
  666. std::vector<double>::iterator
  667. >
  668. >
  669. zip_it_non_const(
  670. ZI_MAKE_TUPLE(
  671. intset.begin(),
  672. vect2.begin()
  673. )
  674. );
  675. zip_it_half_const = ++zip_it_non_const;
  676. zip_it_const = zip_it_half_const;
  677. ++zip_it_const;
  678. // zip_it_non_const = ++zip_it_const; // Error: can't convert from const to non-const
  679. if( 54 == ZI_TUPLE_GET(0)(*zip_it_const) &&
  680. 4.4 == ZI_TUPLE_GET(1)(*zip_it_const) &&
  681. 53 == ZI_TUPLE_GET(0)(*zip_it_half_const) &&
  682. 3.3 == ZI_TUPLE_GET(1)(*zip_it_half_const)
  683. )
  684. {
  685. ++num_successful_tests;
  686. std::cout << "OK" << std::endl;
  687. }
  688. else
  689. {
  690. ++num_failed_tests;
  691. std::cout << "not OK" << std::endl;
  692. }
  693. #if defined(ZI_USE_BOOST_TUPLE)
  694. /////////////////////////////////////////////////////////////////////////////
  695. //
  696. // Zip iterator categories
  697. //
  698. /////////////////////////////////////////////////////////////////////////////
  699. std::cout << "Zip iterator categories: "
  700. << std::flush;
  701. // The big iterator of the previous test has vector, list, and set iterators.
  702. // Therefore, it must be bidirectional, but not random access.
  703. bool bBigItIsBidirectionalIterator = boost::is_convertible<
  704. boost::iterator_traversal<zip_it_12_type>::type
  705. , boost::bidirectional_traversal_tag
  706. >::value;
  707. bool bBigItIsRandomAccessIterator = boost::is_convertible<
  708. boost::iterator_traversal<zip_it_12_type>::type
  709. , boost::random_access_traversal_tag
  710. >::value;
  711. // A combining iterator with all vector iterators must have random access
  712. // traversal.
  713. //
  714. typedef boost::zip_iterator<
  715. ZI_TUPLE<
  716. std::vector<double>::const_iterator,
  717. std::vector<double>::const_iterator
  718. >
  719. > all_vects_type;
  720. bool bAllVectsIsRandomAccessIterator = boost::is_convertible<
  721. boost::iterator_traversal<all_vects_type>::type
  722. , boost::random_access_traversal_tag
  723. >::value;
  724. // The big test.
  725. if( bBigItIsBidirectionalIterator &&
  726. ! bBigItIsRandomAccessIterator &&
  727. bAllVectsIsRandomAccessIterator
  728. )
  729. {
  730. ++num_successful_tests;
  731. std::cout << "OK" << std::endl;
  732. }
  733. else
  734. {
  735. ++num_failed_tests;
  736. std::cout << "not OK" << std::endl;
  737. }
  738. #endif
  739. // Done
  740. //
  741. std::cout << "\nTest Result:"
  742. << "\n============"
  743. << "\nNumber of successful tests: " << static_cast<unsigned int>(num_successful_tests)
  744. << "\nNumber of failed tests: " << static_cast<unsigned int>(num_failed_tests)
  745. << std::endl;
  746. return num_failed_tests;
  747. }