map_allocator_requirement_test_templates.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef MAP_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
  9. #define MAP_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
  10. // <map>
  11. // <unordered_map>
  12. // class map
  13. // class unordered_map
  14. // insert(...);
  15. // emplace(...);
  16. // emplace_hint(...);
  17. // UNSUPPORTED: c++98, c++03
  18. #include <cassert>
  19. #include "test_macros.h"
  20. #include "count_new.h"
  21. #include "container_test_types.h"
  22. #include "assert_checkpoint.h"
  23. template <class Container>
  24. void testMapInsert()
  25. {
  26. typedef typename Container::value_type ValueTp;
  27. ConstructController* cc = getConstructController();
  28. cc->reset();
  29. {
  30. CHECKPOINT("Testing C::insert(const value_type&)");
  31. Container c;
  32. const ValueTp v(42, 1);
  33. cc->expect<const ValueTp&>();
  34. assert(c.insert(v).second);
  35. assert(!cc->unchecked());
  36. {
  37. DisableAllocationGuard g;
  38. const ValueTp v2(42, 1);
  39. assert(c.insert(v2).second == false);
  40. }
  41. }
  42. {
  43. CHECKPOINT("Testing C::insert(value_type&)");
  44. Container c;
  45. ValueTp v(42, 1);
  46. cc->expect<const ValueTp&>();
  47. assert(c.insert(v).second);
  48. assert(!cc->unchecked());
  49. {
  50. DisableAllocationGuard g;
  51. ValueTp v2(42, 1);
  52. assert(c.insert(v2).second == false);
  53. }
  54. }
  55. {
  56. CHECKPOINT("Testing C::insert(value_type&&)");
  57. Container c;
  58. ValueTp v(42, 1);
  59. cc->expect<ValueTp&&>();
  60. assert(c.insert(std::move(v)).second);
  61. assert(!cc->unchecked());
  62. {
  63. DisableAllocationGuard g;
  64. ValueTp v2(42, 1);
  65. assert(c.insert(std::move(v2)).second == false);
  66. }
  67. }
  68. {
  69. CHECKPOINT("Testing C::insert(const value_type&&)");
  70. Container c;
  71. const ValueTp v(42, 1);
  72. cc->expect<const ValueTp&>();
  73. assert(c.insert(std::move(v)).second);
  74. assert(!cc->unchecked());
  75. {
  76. DisableAllocationGuard g;
  77. const ValueTp v2(42, 1);
  78. assert(c.insert(std::move(v2)).second == false);
  79. }
  80. }
  81. {
  82. CHECKPOINT("Testing C::insert({key, value})");
  83. Container c;
  84. cc->expect<ValueTp&&>();
  85. assert(c.insert({42, 1}).second);
  86. assert(!cc->unchecked());
  87. {
  88. DisableAllocationGuard g;
  89. const ValueTp v2(42, 1);
  90. assert(c.insert(std::move(v2)).second == false);
  91. }
  92. }
  93. {
  94. CHECKPOINT("Testing C::insert(std::initializer_list<ValueTp>)");
  95. Container c;
  96. std::initializer_list<ValueTp> il = { ValueTp(1, 1), ValueTp(2, 1) };
  97. cc->expect<ValueTp const&>(2);
  98. c.insert(il);
  99. assert(!cc->unchecked());
  100. {
  101. DisableAllocationGuard g;
  102. c.insert(il);
  103. }
  104. }
  105. {
  106. CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type const&");
  107. Container c;
  108. const ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1), ValueTp(3, 1) };
  109. cc->expect<ValueTp const&>(3);
  110. c.insert(std::begin(ValueList), std::end(ValueList));
  111. assert(!cc->unchecked());
  112. {
  113. DisableAllocationGuard g;
  114. c.insert(std::begin(ValueList), std::end(ValueList));
  115. }
  116. }
  117. {
  118. CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&&");
  119. Container c;
  120. ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
  121. cc->expect<ValueTp&&>(3);
  122. c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)),
  123. std::move_iterator<ValueTp*>(std::end(ValueList)));
  124. assert(!cc->unchecked());
  125. {
  126. DisableAllocationGuard g;
  127. ValueTp ValueList2[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
  128. c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList2)),
  129. std::move_iterator<ValueTp*>(std::end(ValueList2)));
  130. }
  131. }
  132. {
  133. CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&");
  134. Container c;
  135. ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
  136. cc->expect<ValueTp const&>(3);
  137. c.insert(std::begin(ValueList), std::end(ValueList));
  138. assert(!cc->unchecked());
  139. {
  140. DisableAllocationGuard g;
  141. c.insert(std::begin(ValueList), std::end(ValueList));
  142. }
  143. }
  144. }
  145. template <class Container>
  146. void testMapInsertHint()
  147. {
  148. typedef typename Container::value_type ValueTp;
  149. typedef typename Container::key_type Key;
  150. typedef typename Container::mapped_type Mapped;
  151. typedef typename std::pair<Key, Mapped> NonConstKeyPair;
  152. typedef Container C;
  153. typedef typename C::iterator It;
  154. ConstructController* cc = getConstructController();
  155. cc->reset();
  156. {
  157. CHECKPOINT("Testing C::insert(p, const value_type&)");
  158. Container c;
  159. const ValueTp v(42, 1);
  160. cc->expect<const ValueTp&>();
  161. It ret = c.insert(c.end(), v);
  162. assert(ret != c.end());
  163. assert(c.size() == 1);
  164. assert(!cc->unchecked());
  165. {
  166. DisableAllocationGuard g;
  167. const ValueTp v2(42, 1);
  168. It ret2 = c.insert(c.begin(), v2);
  169. assert(&(*ret2) == &(*ret));
  170. assert(c.size() == 1);
  171. }
  172. }
  173. {
  174. CHECKPOINT("Testing C::insert(p, value_type&)");
  175. Container c;
  176. ValueTp v(42, 1);
  177. cc->expect<ValueTp const&>();
  178. It ret = c.insert(c.end(), v);
  179. assert(ret != c.end());
  180. assert(c.size() == 1);
  181. assert(!cc->unchecked());
  182. {
  183. DisableAllocationGuard g;
  184. ValueTp v2(42, 1);
  185. It ret2 = c.insert(c.begin(), v2);
  186. assert(&(*ret2) == &(*ret));
  187. assert(c.size() == 1);
  188. }
  189. }
  190. {
  191. CHECKPOINT("Testing C::insert(p, value_type&&)");
  192. Container c;
  193. ValueTp v(42, 1);
  194. cc->expect<ValueTp&&>();
  195. It ret = c.insert(c.end(), std::move(v));
  196. assert(ret != c.end());
  197. assert(c.size() == 1);
  198. assert(!cc->unchecked());
  199. {
  200. DisableAllocationGuard g;
  201. ValueTp v2(42, 1);
  202. It ret2 = c.insert(c.begin(), std::move(v2));
  203. assert(&(*ret2) == &(*ret));
  204. assert(c.size() == 1);
  205. }
  206. }
  207. {
  208. CHECKPOINT("Testing C::insert(p, {key, value})");
  209. Container c;
  210. cc->expect<ValueTp&&>();
  211. It ret = c.insert(c.end(), {42, 1});
  212. assert(ret != c.end());
  213. assert(c.size() == 1);
  214. assert(!cc->unchecked());
  215. {
  216. DisableAllocationGuard g;
  217. It ret2 = c.insert(c.begin(), {42, 1});
  218. assert(&(*ret2) == &(*ret));
  219. assert(c.size() == 1);
  220. }
  221. }
  222. {
  223. CHECKPOINT("Testing C::insert(p, const value_type&&)");
  224. Container c;
  225. const ValueTp v(42, 1);
  226. cc->expect<const ValueTp&>();
  227. It ret = c.insert(c.end(), std::move(v));
  228. assert(ret != c.end());
  229. assert(c.size() == 1);
  230. assert(!cc->unchecked());
  231. {
  232. DisableAllocationGuard g;
  233. const ValueTp v2(42, 1);
  234. It ret2 = c.insert(c.begin(), std::move(v2));
  235. assert(&(*ret2) == &(*ret));
  236. assert(c.size() == 1);
  237. }
  238. }
  239. {
  240. CHECKPOINT("Testing C::insert(p, pair<Key, Mapped> const&)");
  241. Container c;
  242. const NonConstKeyPair v(42, 1);
  243. cc->expect<const NonConstKeyPair&>();
  244. It ret = c.insert(c.end(), v);
  245. assert(ret != c.end());
  246. assert(c.size() == 1);
  247. assert(!cc->unchecked());
  248. {
  249. DisableAllocationGuard g;
  250. const NonConstKeyPair v2(42, 1);
  251. It ret2 = c.insert(c.begin(), v2);
  252. assert(&(*ret2) == &(*ret));
  253. assert(c.size() == 1);
  254. }
  255. }
  256. {
  257. CHECKPOINT("Testing C::insert(p, pair<Key, Mapped>&&)");
  258. Container c;
  259. NonConstKeyPair v(42, 1);
  260. cc->expect<NonConstKeyPair&&>();
  261. It ret = c.insert(c.end(), std::move(v));
  262. assert(ret != c.end());
  263. assert(c.size() == 1);
  264. assert(!cc->unchecked());
  265. {
  266. DisableAllocationGuard g;
  267. NonConstKeyPair v2(42, 1);
  268. It ret2 = c.insert(c.begin(), std::move(v2));
  269. assert(&(*ret2) == &(*ret));
  270. assert(c.size() == 1);
  271. }
  272. }
  273. }
  274. template <class Container>
  275. void testMapEmplace()
  276. {
  277. typedef typename Container::value_type ValueTp;
  278. typedef typename Container::key_type Key;
  279. typedef typename Container::mapped_type Mapped;
  280. typedef typename std::pair<Key, Mapped> NonConstKeyPair;
  281. ConstructController* cc = getConstructController();
  282. cc->reset();
  283. {
  284. CHECKPOINT("Testing C::emplace(const value_type&)");
  285. Container c;
  286. const ValueTp v(42, 1);
  287. cc->expect<const ValueTp&>();
  288. assert(c.emplace(v).second);
  289. assert(!cc->unchecked());
  290. {
  291. DisableAllocationGuard g;
  292. const ValueTp v2(42, 1);
  293. assert(c.emplace(v2).second == false);
  294. }
  295. }
  296. {
  297. CHECKPOINT("Testing C::emplace(value_type&)");
  298. Container c;
  299. ValueTp v(42, 1);
  300. cc->expect<ValueTp&>();
  301. assert(c.emplace(v).second);
  302. assert(!cc->unchecked());
  303. {
  304. DisableAllocationGuard g;
  305. ValueTp v2(42, 1);
  306. assert(c.emplace(v2).second == false);
  307. }
  308. }
  309. {
  310. CHECKPOINT("Testing C::emplace(value_type&&)");
  311. Container c;
  312. ValueTp v(42, 1);
  313. cc->expect<ValueTp&&>();
  314. assert(c.emplace(std::move(v)).second);
  315. assert(!cc->unchecked());
  316. {
  317. DisableAllocationGuard g;
  318. ValueTp v2(42, 1);
  319. assert(c.emplace(std::move(v2)).second == false);
  320. }
  321. }
  322. {
  323. CHECKPOINT("Testing C::emplace(const value_type&&)");
  324. Container c;
  325. const ValueTp v(42, 1);
  326. cc->expect<const ValueTp&&>();
  327. assert(c.emplace(std::move(v)).second);
  328. assert(!cc->unchecked());
  329. {
  330. DisableAllocationGuard g;
  331. const ValueTp v2(42, 1);
  332. assert(c.emplace(std::move(v2)).second == false);
  333. }
  334. }
  335. {
  336. CHECKPOINT("Testing C::emplace(pair<Key, Mapped> const&)");
  337. Container c;
  338. const NonConstKeyPair v(42, 1);
  339. cc->expect<const NonConstKeyPair&>();
  340. assert(c.emplace(v).second);
  341. assert(!cc->unchecked());
  342. {
  343. DisableAllocationGuard g;
  344. const NonConstKeyPair v2(42, 1);
  345. assert(c.emplace(v2).second == false);
  346. }
  347. }
  348. {
  349. CHECKPOINT("Testing C::emplace(pair<Key, Mapped> &&)");
  350. Container c;
  351. NonConstKeyPair v(42, 1);
  352. cc->expect<NonConstKeyPair&&>();
  353. assert(c.emplace(std::move(v)).second);
  354. assert(!cc->unchecked());
  355. {
  356. DisableAllocationGuard g;
  357. NonConstKeyPair v2(42, 1);
  358. assert(c.emplace(std::move(v2)).second == false);
  359. }
  360. }
  361. {
  362. CHECKPOINT("Testing C::emplace(const Key&, ConvertibleToMapped&&)");
  363. Container c;
  364. const Key k(42);
  365. cc->expect<Key const&, int&&>();
  366. assert(c.emplace(k, 1).second);
  367. assert(!cc->unchecked());
  368. {
  369. DisableAllocationGuard g;
  370. const Key k2(42);
  371. assert(c.emplace(k2, 2).second == false);
  372. }
  373. }
  374. {
  375. CHECKPOINT("Testing C::emplace(Key&, Mapped&)");
  376. Container c;
  377. Key k(42);
  378. Mapped m(1);
  379. cc->expect<Key&, Mapped&>();
  380. assert(c.emplace(k, m).second);
  381. assert(!cc->unchecked());
  382. {
  383. DisableAllocationGuard g;
  384. Key k2(42);
  385. assert(c.emplace(k2, m).second == false);
  386. }
  387. }
  388. {
  389. CHECKPOINT("Testing C::emplace(Key&&, Mapped&&)");
  390. Container c;
  391. Key k(42);
  392. Mapped m(1);
  393. cc->expect<Key&&, Mapped&&>();
  394. assert(c.emplace(std::move(k), std::move(m)).second);
  395. assert(!cc->unchecked());
  396. {
  397. DisableAllocationGuard g;
  398. Key k2(42);
  399. Mapped m2(2);
  400. assert(c.emplace(std::move(k2), std::move(m2)).second == false);
  401. }
  402. }
  403. {
  404. CHECKPOINT("Testing C::emplace(ConvertibleToKey&&, ConvertibleToMapped&&)");
  405. Container c;
  406. cc->expect<int&&, int&&>();
  407. assert(c.emplace(42, 1).second);
  408. assert(!cc->unchecked());
  409. {
  410. // test that emplacing a duplicate item allocates. We cannot optimize
  411. // this case because int&& does not match the type of key exactly.
  412. cc->expect<int&&, int&&>();
  413. assert(c.emplace(42, 1).second == false);
  414. assert(!cc->unchecked());
  415. }
  416. }
  417. }
  418. template <class Container>
  419. void testMapEmplaceHint()
  420. {
  421. typedef typename Container::value_type ValueTp;
  422. typedef typename Container::key_type Key;
  423. typedef typename Container::mapped_type Mapped;
  424. typedef typename std::pair<Key, Mapped> NonConstKeyPair;
  425. typedef Container C;
  426. typedef typename C::iterator It;
  427. ConstructController* cc = getConstructController();
  428. cc->reset();
  429. {
  430. CHECKPOINT("Testing C::emplace_hint(p, const value_type&)");
  431. Container c;
  432. const ValueTp v(42, 1);
  433. cc->expect<const ValueTp&>();
  434. It ret = c.emplace_hint(c.end(), v);
  435. assert(ret != c.end());
  436. assert(c.size() == 1);
  437. assert(!cc->unchecked());
  438. {
  439. DisableAllocationGuard g;
  440. const ValueTp v2(42, 1);
  441. It ret2 = c.emplace_hint(c.begin(), v2);
  442. assert(&(*ret2) == &(*ret));
  443. assert(c.size() == 1);
  444. }
  445. }
  446. {
  447. CHECKPOINT("Testing C::emplace_hint(p, value_type&)");
  448. Container c;
  449. ValueTp v(42, 1);
  450. cc->expect<ValueTp&>();
  451. It ret = c.emplace_hint(c.end(), v);
  452. assert(ret != c.end());
  453. assert(c.size() == 1);
  454. assert(!cc->unchecked());
  455. {
  456. DisableAllocationGuard g;
  457. ValueTp v2(42, 1);
  458. It ret2 = c.emplace_hint(c.begin(), v2);
  459. assert(&(*ret2) == &(*ret));
  460. assert(c.size() == 1);
  461. }
  462. }
  463. {
  464. CHECKPOINT("Testing C::emplace_hint(p, value_type&&)");
  465. Container c;
  466. ValueTp v(42, 1);
  467. cc->expect<ValueTp&&>();
  468. It ret = c.emplace_hint(c.end(), std::move(v));
  469. assert(ret != c.end());
  470. assert(c.size() == 1);
  471. assert(!cc->unchecked());
  472. {
  473. DisableAllocationGuard g;
  474. ValueTp v2(42, 1);
  475. It ret2 = c.emplace_hint(c.begin(), std::move(v2));
  476. assert(&(*ret2) == &(*ret));
  477. assert(c.size() == 1);
  478. }
  479. }
  480. {
  481. CHECKPOINT("Testing C::emplace_hint(p, const value_type&&)");
  482. Container c;
  483. const ValueTp v(42, 1);
  484. cc->expect<const ValueTp&&>();
  485. It ret = c.emplace_hint(c.end(), std::move(v));
  486. assert(ret != c.end());
  487. assert(c.size() == 1);
  488. assert(!cc->unchecked());
  489. {
  490. DisableAllocationGuard g;
  491. const ValueTp v2(42, 1);
  492. It ret2 = c.emplace_hint(c.begin(), std::move(v2));
  493. assert(&(*ret2) == &(*ret));
  494. assert(c.size() == 1);
  495. }
  496. }
  497. {
  498. CHECKPOINT("Testing C::emplace_hint(p, pair<Key, Mapped> const&)");
  499. Container c;
  500. const NonConstKeyPair v(42, 1);
  501. cc->expect<const NonConstKeyPair&>();
  502. It ret = c.emplace_hint(c.end(), v);
  503. assert(ret != c.end());
  504. assert(c.size() == 1);
  505. assert(!cc->unchecked());
  506. {
  507. DisableAllocationGuard g;
  508. const NonConstKeyPair v2(42, 1);
  509. It ret2 = c.emplace_hint(c.begin(), v2);
  510. assert(&(*ret2) == &(*ret));
  511. assert(c.size() == 1);
  512. }
  513. }
  514. {
  515. CHECKPOINT("Testing C::emplace_hint(p, pair<Key, Mapped>&&)");
  516. Container c;
  517. NonConstKeyPair v(42, 1);
  518. cc->expect<NonConstKeyPair&&>();
  519. It ret = c.emplace_hint(c.end(), std::move(v));
  520. assert(ret != c.end());
  521. assert(c.size() == 1);
  522. assert(!cc->unchecked());
  523. {
  524. DisableAllocationGuard g;
  525. NonConstKeyPair v2(42, 1);
  526. It ret2 = c.emplace_hint(c.begin(), std::move(v2));
  527. assert(&(*ret2) == &(*ret));
  528. assert(c.size() == 1);
  529. }
  530. }
  531. {
  532. CHECKPOINT("Testing C::emplace_hint(p, const Key&, ConvertibleToMapped&&)");
  533. Container c;
  534. const Key k(42);
  535. cc->expect<Key const&, int&&>();
  536. It ret = c.emplace_hint(c.end(), k, 42);
  537. assert(ret != c.end());
  538. assert(c.size() == 1);
  539. assert(!cc->unchecked());
  540. {
  541. DisableAllocationGuard g;
  542. const Key k2(42);
  543. It ret2 = c.emplace_hint(c.begin(), k2, 1);
  544. assert(&(*ret2) == &(*ret));
  545. assert(c.size() == 1);
  546. }
  547. }
  548. {
  549. CHECKPOINT("Testing C::emplace_hint(p, Key&, Mapped&)");
  550. Container c;
  551. Key k(42);
  552. Mapped m(1);
  553. cc->expect<Key&, Mapped&>();
  554. It ret = c.emplace_hint(c.end(), k, m);
  555. assert(ret != c.end());
  556. assert(c.size() == 1);
  557. assert(!cc->unchecked());
  558. {
  559. DisableAllocationGuard g;
  560. Key k2(42);
  561. Mapped m2(2);
  562. It ret2 = c.emplace_hint(c.begin(), k2, m2);
  563. assert(&(*ret2) == &(*ret));
  564. assert(c.size() == 1);
  565. }
  566. }
  567. {
  568. CHECKPOINT("Testing C::emplace_hint(p, Key&&, Mapped&&)");
  569. Container c;
  570. Key k(42);
  571. Mapped m(1);
  572. cc->expect<Key&&, Mapped&&>();
  573. It ret = c.emplace_hint(c.end(), std::move(k), std::move(m));
  574. assert(ret != c.end());
  575. assert(c.size() == 1);
  576. assert(!cc->unchecked());
  577. {
  578. DisableAllocationGuard g;
  579. Key k2(42);
  580. Mapped m2(2);
  581. It ret2 = c.emplace_hint(c.begin(), std::move(k2), std::move(m2));
  582. assert(&(*ret2) == &(*ret));
  583. assert(c.size() == 1);
  584. }
  585. }
  586. {
  587. CHECKPOINT("Testing C::emplace_hint(p, ConvertibleToKey&&, ConvertibleToMapped&&)");
  588. Container c;
  589. cc->expect<int&&, int&&>();
  590. It ret = c.emplace_hint(c.end(), 42, 1);
  591. assert(ret != c.end());
  592. assert(c.size() == 1);
  593. assert(!cc->unchecked());
  594. {
  595. cc->expect<int&&, int&&>();
  596. It ret2 = c.emplace_hint(c.begin(), 42, 2);
  597. assert(&(*ret2) == &(*ret));
  598. assert(c.size() == 1);
  599. assert(!cc->unchecked());
  600. }
  601. }
  602. }
  603. template <class Container>
  604. void testMultimapInsert()
  605. {
  606. typedef typename Container::value_type ValueTp;
  607. ConstructController* cc = getConstructController();
  608. cc->reset();
  609. {
  610. CHECKPOINT("Testing C::insert(const value_type&)");
  611. Container c;
  612. const ValueTp v(42, 1);
  613. cc->expect<const ValueTp&>();
  614. c.insert(v);
  615. assert(!cc->unchecked());
  616. }
  617. {
  618. CHECKPOINT("Testing C::insert(value_type&)");
  619. Container c;
  620. ValueTp v(42, 1);
  621. cc->expect<ValueTp&>();
  622. c.insert(v);
  623. assert(!cc->unchecked());
  624. }
  625. {
  626. CHECKPOINT("Testing C::insert(value_type&&)");
  627. Container c;
  628. ValueTp v(42, 1);
  629. cc->expect<ValueTp&&>();
  630. c.insert(std::move(v));
  631. assert(!cc->unchecked());
  632. }
  633. {
  634. CHECKPOINT("Testing C::insert({key, value})");
  635. Container c;
  636. cc->expect<ValueTp&&>();
  637. c.insert({42, 1});
  638. assert(!cc->unchecked());
  639. }
  640. {
  641. CHECKPOINT("Testing C::insert(std::initializer_list<ValueTp>)");
  642. Container c;
  643. std::initializer_list<ValueTp> il = { ValueTp(1, 1), ValueTp(2, 1) };
  644. cc->expect<ValueTp const&>(2);
  645. c.insert(il);
  646. assert(!cc->unchecked());
  647. }
  648. {
  649. CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type const&");
  650. Container c;
  651. const ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1), ValueTp(3, 1) };
  652. cc->expect<ValueTp const&>(3);
  653. c.insert(std::begin(ValueList), std::end(ValueList));
  654. assert(!cc->unchecked());
  655. }
  656. {
  657. CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&&");
  658. Container c;
  659. ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
  660. cc->expect<ValueTp&&>(3);
  661. c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)),
  662. std::move_iterator<ValueTp*>(std::end(ValueList)));
  663. assert(!cc->unchecked());
  664. }
  665. {
  666. CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&");
  667. Container c;
  668. ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
  669. cc->expect<ValueTp&>(3);
  670. c.insert(std::begin(ValueList), std::end(ValueList));
  671. assert(!cc->unchecked());
  672. }
  673. }
  674. template <class Container>
  675. void testMultimapInsertHint()
  676. {
  677. typedef typename Container::value_type ValueTp;
  678. ConstructController* cc = getConstructController();
  679. cc->reset();
  680. {
  681. CHECKPOINT("Testing C::insert(p, const value_type&)");
  682. Container c;
  683. const ValueTp v(42, 1);
  684. cc->expect<const ValueTp&>();
  685. c.insert(c.begin(), v);
  686. assert(!cc->unchecked());
  687. }
  688. {
  689. CHECKPOINT("Testing C::insert(p, value_type&)");
  690. Container c;
  691. ValueTp v(42, 1);
  692. cc->expect<ValueTp&>();
  693. c.insert(c.begin(), v);
  694. assert(!cc->unchecked());
  695. }
  696. {
  697. CHECKPOINT("Testing C::insert(p, value_type&&)");
  698. Container c;
  699. ValueTp v(42, 1);
  700. cc->expect<ValueTp&&>();
  701. c.insert(c.begin(), std::move(v));
  702. assert(!cc->unchecked());
  703. }
  704. {
  705. CHECKPOINT("Testing C::insert(p, {key, value})");
  706. Container c;
  707. cc->expect<ValueTp&&>();
  708. c.insert(c.begin(), {42, 1});
  709. assert(!cc->unchecked());
  710. }
  711. }
  712. #endif