emplace_test.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2008. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_CONTAINER_TEST_EMPLACE_TEST_HPP
  11. #define BOOST_CONTAINER_TEST_EMPLACE_TEST_HPP
  12. #include <iostream>
  13. #include <typeinfo>
  14. #include <boost/container/detail/config_begin.hpp>
  15. #include <boost/container/detail/workaround.hpp>
  16. #include <boost/container/detail/mpl.hpp>
  17. #include <boost/move/utility_core.hpp>
  18. #include <boost/container/detail/type_traits.hpp>
  19. namespace boost{
  20. namespace container {
  21. namespace test{
  22. class EmplaceInt
  23. {
  24. BOOST_MOVABLE_BUT_NOT_COPYABLE(EmplaceInt)
  25. public:
  26. EmplaceInt(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0)
  27. : a_(a), b_(b), c_(c), d_(d), e_(e)
  28. {}
  29. EmplaceInt(BOOST_RV_REF(EmplaceInt) o)
  30. : a_(o.a_), b_(o.b_), c_(o.c_), d_(o.d_), e_(o.e_)
  31. {}
  32. EmplaceInt& operator=(BOOST_RV_REF(EmplaceInt) o)
  33. {
  34. this->a_ = o.a_;
  35. this->b_ = o.b_;
  36. this->c_ = o.c_;
  37. this->d_ = o.d_;
  38. this->e_ = o.e_;
  39. return *this;
  40. }
  41. friend bool operator==(const EmplaceInt &l, const EmplaceInt &r)
  42. {
  43. return l.a_ == r.a_ &&
  44. l.b_ == r.b_ &&
  45. l.c_ == r.c_ &&
  46. l.d_ == r.d_ &&
  47. l.e_ == r.e_;
  48. }
  49. friend bool operator<(const EmplaceInt &l, const EmplaceInt &r)
  50. { return l.sum() < r.sum(); }
  51. friend bool operator>(const EmplaceInt &l, const EmplaceInt &r)
  52. { return l.sum() > r.sum(); }
  53. friend bool operator!=(const EmplaceInt &l, const EmplaceInt &r)
  54. { return !(l == r); }
  55. friend std::size_t hash_value(const EmplaceInt &v)
  56. { return std::size_t(v.a_); }
  57. friend std::ostream &operator <<(std::ostream &os, const EmplaceInt &v)
  58. {
  59. os << "EmplaceInt: " << v.a_ << ' ' << v.b_ << ' ' << v.c_ << ' ' << v.d_ << ' ' << v.e_;
  60. return os;
  61. }
  62. ~EmplaceInt()
  63. { a_ = b_ = c_ = d_ = e_ = 0; }
  64. //private:
  65. int sum() const
  66. { return this->a_ + this->b_ + this->c_ + this->d_ + this->e_; }
  67. int a_, b_, c_, d_, e_;
  68. int padding[6];
  69. };
  70. } //namespace test {
  71. namespace test {
  72. enum EmplaceOptions{
  73. EMPLACE_BACK = 1 << 0,
  74. EMPLACE_FRONT = 1 << 1,
  75. EMPLACE_BEFORE = 1 << 2,
  76. EMPLACE_AFTER = 1 << 3,
  77. EMPLACE_ASSOC = 1 << 4,
  78. EMPLACE_HINT = 1 << 5,
  79. EMPLACE_ASSOC_PAIR = 1 << 6,
  80. EMPLACE_HINT_PAIR = 1 << 7
  81. };
  82. template<class Container>
  83. bool test_expected_container(const Container &ec, const EmplaceInt *Expected, unsigned int only_first_n, unsigned int cont_offset = 0)
  84. {
  85. typedef typename Container::const_iterator const_iterator;
  86. const_iterator itb(ec.begin()), ite(ec.end());
  87. unsigned int cur = 0;
  88. if(cont_offset > ec.size()){
  89. return false;
  90. }
  91. if(only_first_n > (ec.size() - cont_offset)){
  92. return false;
  93. }
  94. while(cont_offset--){
  95. ++itb;
  96. }
  97. for(; itb != ite && only_first_n--; ++itb, ++cur){
  98. const EmplaceInt & cr = *itb;
  99. if(cr != Expected[cur]){
  100. return false;
  101. }
  102. }
  103. return true;
  104. }
  105. template<class Container>
  106. bool test_expected_container(const Container &ec, const std::pair<EmplaceInt, EmplaceInt> *Expected, unsigned int only_first_n)
  107. {
  108. typedef typename Container::const_iterator const_iterator;
  109. const_iterator itb(ec.begin()), ite(ec.end());
  110. unsigned int cur = 0;
  111. if(only_first_n > ec.size()){
  112. return false;
  113. }
  114. for(; itb != ite && only_first_n--; ++itb, ++cur){
  115. if(itb->first != Expected[cur].first){
  116. std::cout << "Error in first: " << itb->first << ' ' << Expected[cur].first << std::endl;
  117. return false;
  118. }
  119. else if(itb->second != Expected[cur].second){
  120. std::cout << "Error in second: " << itb->second << ' ' << Expected[cur].second << std::endl;
  121. return false;
  122. }
  123. }
  124. return true;
  125. }
  126. typedef std::pair<EmplaceInt, EmplaceInt> EmplaceIntPair;
  127. static boost::container::dtl::aligned_storage<sizeof(EmplaceIntPair)*10>::type pair_storage;
  128. static EmplaceIntPair* initialize_emplace_int_pair()
  129. {
  130. EmplaceIntPair* ret = reinterpret_cast<EmplaceIntPair*>(&pair_storage);
  131. for(unsigned int i = 0; i != 10; ++i){
  132. new(&ret->first)EmplaceInt();
  133. new(&ret->second)EmplaceInt();
  134. }
  135. return ret;
  136. }
  137. static EmplaceIntPair * expected_pair = initialize_emplace_int_pair();
  138. template<class Container>
  139. bool test_emplace_back(dtl::true_)
  140. {
  141. std::cout << "Starting test_emplace_back." << std::endl << " Class: "
  142. << typeid(Container).name() << std::endl;
  143. static EmplaceInt expected [10];
  144. {
  145. new(&expected [0]) EmplaceInt();
  146. new(&expected [1]) EmplaceInt(1);
  147. new(&expected [2]) EmplaceInt(1, 2);
  148. new(&expected [3]) EmplaceInt(1, 2, 3);
  149. new(&expected [4]) EmplaceInt(1, 2, 3, 4);
  150. new(&expected [5]) EmplaceInt(1, 2, 3, 4, 5);
  151. Container c;
  152. typedef typename Container::reference reference;
  153. {
  154. reference r = c.emplace_back();
  155. if(&r != &c.back() && !test_expected_container(c, &expected[0], 1)){
  156. return false;
  157. }
  158. }
  159. {
  160. reference r = c.emplace_back(1);
  161. if(&r != &c.back() && !test_expected_container(c, &expected[0], 2)){
  162. return false;
  163. }
  164. }
  165. c.emplace_back(1, 2);
  166. if(!test_expected_container(c, &expected[0], 3)){
  167. return false;
  168. }
  169. c.emplace_back(1, 2, 3);
  170. if(!test_expected_container(c, &expected[0], 4)){
  171. return false;
  172. }
  173. c.emplace_back(1, 2, 3, 4);
  174. if(!test_expected_container(c, &expected[0], 5)){
  175. return false;
  176. }
  177. c.emplace_back(1, 2, 3, 4, 5);
  178. if(!test_expected_container(c, &expected[0], 6)){
  179. return false;
  180. }
  181. }
  182. std::cout << "...OK" << std::endl;
  183. return true;
  184. }
  185. template<class Container>
  186. bool test_emplace_back(dtl::false_)
  187. { return true; }
  188. template<class Container>
  189. bool test_emplace_front(dtl::true_)
  190. {
  191. std::cout << "Starting test_emplace_front." << std::endl << " Class: "
  192. << typeid(Container).name() << std::endl;
  193. static EmplaceInt expected [10];
  194. {
  195. new(&expected [0]) EmplaceInt(1, 2, 3, 4, 5);
  196. new(&expected [1]) EmplaceInt(1, 2, 3, 4);
  197. new(&expected [2]) EmplaceInt(1, 2, 3);
  198. new(&expected [3]) EmplaceInt(1, 2);
  199. new(&expected [4]) EmplaceInt(1);
  200. new(&expected [5]) EmplaceInt();
  201. Container c;
  202. typedef typename Container::reference reference;
  203. {
  204. reference r = c.emplace_front();
  205. if(&r != &c.front() && !test_expected_container(c, &expected[0] + 5, 1)){
  206. return false;
  207. }
  208. }
  209. {
  210. reference r = c.emplace_front(1);
  211. if(&r != &c.front() && !test_expected_container(c, &expected[0] + 4, 2)){
  212. return false;
  213. }
  214. }
  215. c.emplace_front(1, 2);
  216. if(!test_expected_container(c, &expected[0] + 3, 3)){
  217. return false;
  218. }
  219. c.emplace_front(1, 2, 3);
  220. if(!test_expected_container(c, &expected[0] + 2, 4)){
  221. return false;
  222. }
  223. c.emplace_front(1, 2, 3, 4);
  224. if(!test_expected_container(c, &expected[0] + 1, 5)){
  225. return false;
  226. }
  227. c.emplace_front(1, 2, 3, 4, 5);
  228. if(!test_expected_container(c, &expected[0] + 0, 6)){
  229. return false;
  230. }
  231. }
  232. std::cout << "...OK" << std::endl;
  233. return true;
  234. }
  235. template<class Container>
  236. bool test_emplace_front(dtl::false_)
  237. { return true; }
  238. template<class Container>
  239. bool test_emplace_before(dtl::true_)
  240. {
  241. std::cout << "Starting test_emplace_before." << std::endl << " Class: "
  242. << typeid(Container).name() << std::endl;
  243. static EmplaceInt expected [10];
  244. {
  245. new(&expected [0]) EmplaceInt();
  246. new(&expected [1]) EmplaceInt(1);
  247. new(&expected [2]) EmplaceInt();
  248. Container c;
  249. c.emplace(c.cend(), 1);
  250. c.emplace(c.cbegin());
  251. if(!test_expected_container(c, &expected[0], 2)){
  252. return false;
  253. }
  254. c.emplace(c.cend());
  255. if(!test_expected_container(c, &expected[0], 3)){
  256. return false;
  257. }
  258. }
  259. {
  260. new(&expected [0]) EmplaceInt();
  261. new(&expected [1]) EmplaceInt(1);
  262. new(&expected [2]) EmplaceInt(1, 2);
  263. new(&expected [3]) EmplaceInt(1, 2, 3);
  264. new(&expected [4]) EmplaceInt(1, 2, 3, 4);
  265. new(&expected [5]) EmplaceInt(1, 2, 3, 4, 5);
  266. //emplace_front-like
  267. Container c;
  268. c.emplace(c.cbegin(), 1, 2, 3, 4, 5);
  269. c.emplace(c.cbegin(), 1, 2, 3, 4);
  270. c.emplace(c.cbegin(), 1, 2, 3);
  271. c.emplace(c.cbegin(), 1, 2);
  272. c.emplace(c.cbegin(), 1);
  273. c.emplace(c.cbegin());
  274. if(!test_expected_container(c, &expected[0], 6)){
  275. return false;
  276. }
  277. c.clear();
  278. //emplace_back-like
  279. typename Container::const_iterator i = c.emplace(c.cend());
  280. if(!test_expected_container(c, &expected[0], 1)){
  281. return false;
  282. }
  283. i = c.emplace(++i, 1);
  284. if(!test_expected_container(c, &expected[0], 2)){
  285. return false;
  286. }
  287. i = c.emplace(++i, 1, 2);
  288. if(!test_expected_container(c, &expected[0], 3)){
  289. return false;
  290. }
  291. i = c.emplace(++i, 1, 2, 3);
  292. if(!test_expected_container(c, &expected[0], 4)){
  293. return false;
  294. }
  295. i = c.emplace(++i, 1, 2, 3, 4);
  296. if(!test_expected_container(c, &expected[0], 5)){
  297. return false;
  298. }
  299. i = c.emplace(++i, 1, 2, 3, 4, 5);
  300. if(!test_expected_container(c, &expected[0], 6)){
  301. return false;
  302. }
  303. c.clear();
  304. //emplace in the middle
  305. c.emplace(c.cbegin());
  306. if(!test_expected_container(c, &expected[0], 1)){
  307. return false;
  308. }
  309. i = c.emplace(c.cend(), 1, 2, 3, 4, 5);
  310. if(!test_expected_container(c, &expected[0], 1)){
  311. return false;
  312. }
  313. if(!test_expected_container(c, &expected[5], 1, 1)){
  314. return false;
  315. }
  316. i = c.emplace(i, 1, 2, 3, 4);
  317. if(!test_expected_container(c, &expected[0], 1)){
  318. return false;
  319. }
  320. if(!test_expected_container(c, &expected[4], 2, 1)){
  321. return false;
  322. }
  323. i = c.emplace(i, 1, 2, 3);
  324. if(!test_expected_container(c, &expected[0], 1)){
  325. return false;
  326. }
  327. if(!test_expected_container(c, &expected[3], 3, 1)){
  328. return false;
  329. }
  330. i = c.emplace(i, 1, 2);
  331. if(!test_expected_container(c, &expected[0], 1)){
  332. return false;
  333. }
  334. if(!test_expected_container(c, &expected[2], 4, 1)){
  335. return false;
  336. }
  337. i = c.emplace(i, 1);
  338. if(!test_expected_container(c, &expected[0], 6)){
  339. return false;
  340. }
  341. std::cout << "...OK" << std::endl;
  342. }
  343. return true;
  344. }
  345. template<class Container>
  346. bool test_emplace_before(dtl::false_)
  347. { return true; }
  348. template<class Container>
  349. bool test_emplace_after(dtl::true_)
  350. {
  351. std::cout << "Starting test_emplace_after." << std::endl << " Class: "
  352. << typeid(Container).name() << std::endl;
  353. static EmplaceInt expected [10];
  354. {
  355. new(&expected [0]) EmplaceInt();
  356. new(&expected [1]) EmplaceInt(1);
  357. new(&expected [2]) EmplaceInt();
  358. Container c;
  359. typename Container::const_iterator i = c.emplace_after(c.cbefore_begin(), 1);
  360. c.emplace_after(c.cbefore_begin());
  361. if(!test_expected_container(c, &expected[0], 2)){
  362. return false;
  363. }
  364. c.emplace_after(i);
  365. if(!test_expected_container(c, &expected[0], 3)){
  366. return false;
  367. }
  368. }
  369. {
  370. new(&expected [0]) EmplaceInt();
  371. new(&expected [1]) EmplaceInt(1);
  372. new(&expected [2]) EmplaceInt(1, 2);
  373. new(&expected [3]) EmplaceInt(1, 2, 3);
  374. new(&expected [4]) EmplaceInt(1, 2, 3, 4);
  375. new(&expected [5]) EmplaceInt(1, 2, 3, 4, 5);
  376. //emplace_front-like
  377. Container c;
  378. c.emplace_after(c.cbefore_begin(), 1, 2, 3, 4, 5);
  379. c.emplace_after(c.cbefore_begin(), 1, 2, 3, 4);
  380. c.emplace_after(c.cbefore_begin(), 1, 2, 3);
  381. c.emplace_after(c.cbefore_begin(), 1, 2);
  382. c.emplace_after(c.cbefore_begin(), 1);
  383. c.emplace_after(c.cbefore_begin());
  384. if(!test_expected_container(c, &expected[0], 6)){
  385. return false;
  386. }
  387. c.clear();
  388. //emplace_back-like
  389. typename Container::const_iterator i = c.emplace_after(c.cbefore_begin());
  390. if(!test_expected_container(c, &expected[0], 1)){
  391. return false;
  392. }
  393. i = c.emplace_after(i, 1);
  394. if(!test_expected_container(c, &expected[0], 2)){
  395. return false;
  396. }
  397. i = c.emplace_after(i, 1, 2);
  398. if(!test_expected_container(c, &expected[0], 3)){
  399. return false;
  400. }
  401. i = c.emplace_after(i, 1, 2, 3);
  402. if(!test_expected_container(c, &expected[0], 4)){
  403. return false;
  404. }
  405. i = c.emplace_after(i, 1, 2, 3, 4);
  406. if(!test_expected_container(c, &expected[0], 5)){
  407. return false;
  408. }
  409. i = c.emplace_after(i, 1, 2, 3, 4, 5);
  410. if(!test_expected_container(c, &expected[0], 6)){
  411. return false;
  412. }
  413. c.clear();
  414. //emplace_after in the middle
  415. i = c.emplace_after(c.cbefore_begin());
  416. c.emplace_after(i, 1, 2, 3, 4, 5);
  417. c.emplace_after(i, 1, 2, 3, 4);
  418. c.emplace_after(i, 1, 2, 3);
  419. c.emplace_after(i, 1, 2);
  420. c.emplace_after(i, 1);
  421. if(!test_expected_container(c, &expected[0], 6)){
  422. return false;
  423. }
  424. std::cout << "...OK" << std::endl;
  425. }
  426. return true;
  427. }
  428. template<class Container>
  429. bool test_emplace_after(dtl::false_)
  430. { return true; }
  431. template<class Container>
  432. bool test_emplace_assoc(dtl::true_)
  433. {
  434. std::cout << "Starting test_emplace_assoc." << std::endl << " Class: "
  435. << typeid(Container).name() << std::endl;
  436. static EmplaceInt expected [10];
  437. new(&expected [0]) EmplaceInt();
  438. new(&expected [1]) EmplaceInt(1);
  439. new(&expected [2]) EmplaceInt(1, 2);
  440. new(&expected [3]) EmplaceInt(1, 2, 3);
  441. new(&expected [4]) EmplaceInt(1, 2, 3, 4);
  442. new(&expected [5]) EmplaceInt(1, 2, 3, 4, 5);
  443. {
  444. Container c;
  445. c.emplace();
  446. if(!test_expected_container(c, &expected[0], 1)){
  447. return false;
  448. }
  449. c.emplace(1);
  450. if(!test_expected_container(c, &expected[0], 2)){
  451. return false;
  452. }
  453. c.emplace(1, 2);
  454. if(!test_expected_container(c, &expected[0], 3)){
  455. return false;
  456. }
  457. c.emplace(1, 2, 3);
  458. if(!test_expected_container(c, &expected[0], 4)){
  459. return false;
  460. }
  461. c.emplace(1, 2, 3, 4);
  462. if(!test_expected_container(c, &expected[0], 5)){
  463. return false;
  464. }
  465. c.emplace(1, 2, 3, 4, 5);
  466. if(!test_expected_container(c, &expected[0], 6)){
  467. return false;
  468. }
  469. std::cout << "...OK" << std::endl;
  470. }
  471. return true;
  472. }
  473. template<class Container>
  474. bool test_emplace_assoc(dtl::false_)
  475. { return true; }
  476. template<class Container>
  477. bool test_emplace_hint(dtl::true_)
  478. {
  479. std::cout << "Starting test_emplace_hint." << std::endl << " Class: "
  480. << typeid(Container).name() << std::endl;
  481. static EmplaceInt expected [10];
  482. new(&expected [0]) EmplaceInt();
  483. new(&expected [1]) EmplaceInt(1);
  484. new(&expected [2]) EmplaceInt(1, 2);
  485. new(&expected [3]) EmplaceInt(1, 2, 3);
  486. new(&expected [4]) EmplaceInt(1, 2, 3, 4);
  487. new(&expected [5]) EmplaceInt(1, 2, 3, 4, 5);
  488. {
  489. Container c;
  490. typename Container::const_iterator it;
  491. it = c.emplace_hint(c.begin());
  492. if(!test_expected_container(c, &expected[0], 1)){
  493. return false;
  494. }
  495. it = c.emplace_hint(it, 1);
  496. if(!test_expected_container(c, &expected[0], 2)){
  497. return false;
  498. }
  499. it = c.emplace_hint(it, 1, 2);
  500. if(!test_expected_container(c, &expected[0], 3)){
  501. return false;
  502. }
  503. it = c.emplace_hint(it, 1, 2, 3);
  504. if(!test_expected_container(c, &expected[0], 4)){
  505. return false;
  506. }
  507. it = c.emplace_hint(it, 1, 2, 3, 4);
  508. if(!test_expected_container(c, &expected[0], 5)){
  509. return false;
  510. }
  511. it = c.emplace_hint(it, 1, 2, 3, 4, 5);
  512. if(!test_expected_container(c, &expected[0], 6)){
  513. return false;
  514. }
  515. std::cout << "...OK" << std::endl;
  516. }
  517. return true;
  518. }
  519. template<class Container>
  520. bool test_emplace_hint(dtl::false_)
  521. { return true; }
  522. template<class Container>
  523. bool test_emplace_assoc_pair(dtl::true_)
  524. {
  525. std::cout << "Starting test_emplace_assoc_pair." << std::endl << " Class: "
  526. << typeid(Container).name() << std::endl;
  527. new(&expected_pair[0].first) EmplaceInt();
  528. new(&expected_pair[0].second) EmplaceInt();
  529. new(&expected_pair[1].first) EmplaceInt(1);
  530. new(&expected_pair[1].second) EmplaceInt(1);
  531. new(&expected_pair[2].first) EmplaceInt(2);
  532. new(&expected_pair[2].second) EmplaceInt(2);
  533. {
  534. Container c;
  535. c.emplace();
  536. if(!test_expected_container(c, &expected_pair[0], 1)){
  537. std::cout << "Error after c.emplace();\n";
  538. return false;
  539. }
  540. c.emplace(1, 1);
  541. if(!test_expected_container(c, &expected_pair[0], 2)){
  542. std::cout << "Error after c.emplace(1);\n";
  543. return false;
  544. }
  545. c.emplace(2, 2);
  546. if(!test_expected_container(c, &expected_pair[0], 3)){
  547. std::cout << "Error after c.emplace(2, 2);\n";
  548. return false;
  549. }
  550. std::cout << "...OK" << std::endl;
  551. }
  552. return true;
  553. }
  554. template<class Container>
  555. bool test_emplace_assoc_pair(dtl::false_)
  556. { return true; }
  557. template<class Container>
  558. bool test_emplace_hint_pair(dtl::true_)
  559. {
  560. std::cout << "Starting test_emplace_hint_pair." << std::endl << " Class: "
  561. << typeid(Container).name() << std::endl;
  562. new(&expected_pair[0].first) EmplaceInt();
  563. new(&expected_pair[0].second) EmplaceInt();
  564. new(&expected_pair[1].first) EmplaceInt(1);
  565. new(&expected_pair[1].second) EmplaceInt(1);
  566. new(&expected_pair[2].first) EmplaceInt(2);
  567. new(&expected_pair[2].second) EmplaceInt(2);
  568. {
  569. Container c;
  570. typename Container::const_iterator it;
  571. it = c.emplace_hint(c.begin());
  572. if(!test_expected_container(c, &expected_pair[0], 1)){
  573. std::cout << "Error after c.emplace(1);\n";
  574. return false;
  575. }
  576. it = c.emplace_hint(it, 1, 1);
  577. if(!test_expected_container(c, &expected_pair[0], 2)){
  578. std::cout << "Error after c.emplace(it, 1);\n";
  579. return false;
  580. }
  581. it = c.emplace_hint(it, 2, 2);
  582. if(!test_expected_container(c, &expected_pair[0], 3)){
  583. std::cout << "Error after c.emplace(it, 2, 2);\n";
  584. return false;
  585. }
  586. std::cout << "...OK" << std::endl;
  587. }
  588. return true;
  589. }
  590. template<class Container>
  591. bool test_emplace_hint_pair(dtl::false_)
  592. { return true; }
  593. template <EmplaceOptions O, EmplaceOptions Mask>
  594. struct emplace_active
  595. {
  596. static const bool value = (0 != (O & Mask));
  597. typedef dtl::bool_<value> type;
  598. operator type() const{ return type(); }
  599. };
  600. template<class Container, EmplaceOptions O>
  601. bool test_emplace()
  602. {
  603. if(!test_emplace_back<Container>(emplace_active<O, EMPLACE_BACK>())){
  604. return false;
  605. }
  606. if(!test_emplace_front<Container>(emplace_active<O, EMPLACE_FRONT>())){
  607. return false;
  608. }
  609. if(!test_emplace_before<Container>(emplace_active<O, EMPLACE_BEFORE>())){
  610. return false;
  611. }
  612. if(!test_emplace_after<Container>(emplace_active<O, EMPLACE_AFTER>())){
  613. return false;
  614. }
  615. if(!test_emplace_assoc<Container>(emplace_active<O, EMPLACE_ASSOC>())){
  616. return false;
  617. }
  618. if(!test_emplace_hint<Container>(emplace_active<O, EMPLACE_HINT>())){
  619. return false;
  620. }
  621. if(!test_emplace_assoc_pair<Container>(emplace_active<O, EMPLACE_ASSOC_PAIR>())){
  622. return false;
  623. }
  624. if(!test_emplace_hint_pair<Container>(emplace_active<O, EMPLACE_HINT_PAIR>())){
  625. return false;
  626. }
  627. return true;
  628. }
  629. } //namespace test{
  630. } //namespace container {
  631. } //namespace boost{
  632. #include <boost/container/detail/config_end.hpp>
  633. #endif //#ifndef BOOST_CONTAINER_TEST_EMPLACE_TEST_HPP