Home | History | Annotate | Download | only in vector.modifiers
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <vector>
     11 
     12 // iterator insert(const_iterator position, const value_type& x);
     13 
     14 #if _LIBCPP_DEBUG >= 1
     15 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
     16 #endif
     17 
     18 #include <vector>
     19 #include <cassert>
     20 #include "../../../stack_allocator.h"
     21 #include "min_allocator.h"
     22 #include "asan_testing.h"
     23 
     24 int main()
     25 {
     26     {
     27         std::vector<int> v(100);
     28         std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1);
     29         assert(v.size() == 101);
     30         assert(is_contiguous_container_asan_correct(v));
     31         assert(i == v.begin() + 10);
     32         int j;
     33         for (j = 0; j < 10; ++j)
     34             assert(v[j] == 0);
     35         assert(v[j] == 1);
     36         for (++j; j < 101; ++j)
     37             assert(v[j] == 0);
     38     }
     39     {
     40         std::vector<int, stack_allocator<int, 300> > v(100);
     41         std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 1);
     42         assert(v.size() == 101);
     43         assert(is_contiguous_container_asan_correct(v));
     44         assert(i == v.begin() + 10);
     45         int j;
     46         for (j = 0; j < 10; ++j)
     47             assert(v[j] == 0);
     48         assert(v[j] == 1);
     49         for (++j; j < 101; ++j)
     50             assert(v[j] == 0);
     51     }
     52 #if _LIBCPP_DEBUG >= 1
     53     {
     54         std::vector<int> v1(3);
     55         std::vector<int> v2(3);
     56         int i = 4;
     57         v1.insert(v2.begin(), i);
     58         assert(false);
     59     }
     60 #endif
     61 #if __cplusplus >= 201103L
     62     {
     63         std::vector<int, min_allocator<int>> v(100);
     64         std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 1);
     65         assert(v.size() == 101);
     66         assert(is_contiguous_container_asan_correct(v));
     67         assert(i == v.begin() + 10);
     68         int j;
     69         for (j = 0; j < 10; ++j)
     70             assert(v[j] == 0);
     71         assert(v[j] == 1);
     72         for (++j; j < 101; ++j)
     73             assert(v[j] == 0);
     74     }
     75 #if _LIBCPP_DEBUG >= 1
     76     {
     77         std::vector<int, min_allocator<int>> v1(3);
     78         std::vector<int, min_allocator<int>> v2(3);
     79         int i = 4;
     80         v1.insert(v2.begin(), i);
     81         assert(false);
     82     }
     83 #endif
     84 #endif
     85 }
     86