Home | History | Annotate | Download | only in map.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 // <map>
     11 
     12 // class map
     13 
     14 // iterator insert(const_iterator position, const value_type& v);
     15 
     16 #include <map>
     17 #include <cassert>
     18 
     19 #include "test_macros.h"
     20 #include "min_allocator.h"
     21 
     22 template <class Container>
     23 void do_insert_iter_cv_test()
     24 {
     25     typedef Container M;
     26     typedef typename M::iterator R;
     27     typedef typename M::value_type VT;
     28 
     29     M m;
     30     const VT v1(2, 2.5);
     31     R r = m.insert(m.end(), v1);
     32     assert(r == m.begin());
     33     assert(m.size() == 1);
     34     assert(r->first == 2);
     35     assert(r->second == 2.5);
     36 
     37     const VT v2(1, 1.5);
     38     r = m.insert(m.end(), v2);
     39     assert(r == m.begin());
     40     assert(m.size() == 2);
     41     assert(r->first == 1);
     42     assert(r->second == 1.5);
     43 
     44     const VT v3(3, 3.5);
     45     r = m.insert(m.end(), v3);
     46     assert(r == prev(m.end()));
     47     assert(m.size() == 3);
     48     assert(r->first == 3);
     49     assert(r->second == 3.5);
     50 
     51     const VT v4(3, 4.5);
     52     r = m.insert(m.end(), v4);
     53     assert(r == prev(m.end()));
     54     assert(m.size() == 3);
     55     assert(r->first == 3);
     56     assert(r->second == 3.5);
     57 }
     58 
     59 int main()
     60 {
     61     do_insert_iter_cv_test<std::map<int, double> >();
     62 #if TEST_STD_VER >= 11
     63     {
     64         typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
     65         do_insert_iter_cv_test<M>();
     66     }
     67 #endif
     68 }
     69