emplace.pass.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // UNSUPPORTED: c++98, c++03, c++11
  9. // <vector>
  10. // vector<bool>
  11. // template <class... Args> iterator emplace(const_iterator pos, Args&&... args);
  12. #include <vector>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. #include "min_allocator.h"
  16. int main(int, char**)
  17. {
  18. {
  19. typedef std::vector<bool> C;
  20. C c;
  21. C::iterator i = c.emplace(c.cbegin());
  22. assert(i == c.begin());
  23. assert(c.size() == 1);
  24. assert(c.front() == false);
  25. i = c.emplace(c.cend(), true);
  26. assert(i == c.end()-1);
  27. assert(c.size() == 2);
  28. assert(c.front() == false);
  29. assert(c.back() == true);
  30. i = c.emplace(c.cbegin()+1, true);
  31. assert(i == c.begin()+1);
  32. assert(c.size() == 3);
  33. assert(c.front() == false);
  34. assert(c[1] == true);
  35. assert(c.back() == true);
  36. }
  37. {
  38. typedef std::vector<bool, min_allocator<bool>> C;
  39. C c;
  40. C::iterator i = c.emplace(c.cbegin());
  41. assert(i == c.begin());
  42. assert(c.size() == 1);
  43. assert(c.front() == false);
  44. i = c.emplace(c.cend(), true);
  45. assert(i == c.end()-1);
  46. assert(c.size() == 2);
  47. assert(c.front() == false);
  48. assert(c.back() == true);
  49. i = c.emplace(c.cbegin()+1, true);
  50. assert(i == c.begin()+1);
  51. assert(c.size() == 3);
  52. assert(c.size() == 3);
  53. assert(c.front() == false);
  54. assert(c[1] == true);
  55. assert(c.back() == true);
  56. }
  57. return 0;
  58. }