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 // pair<iterator, bool> insert(const value_type& v);
     15 
     16 #include <map>
     17 #include <cassert>
     18 
     19 #include "min_allocator.h"
     20 
     21 int main()
     22 {
     23     {
     24         typedef std::map<int, double> M;
     25         typedef std::pair<M::iterator, bool> R;
     26         M m;
     27         R r = m.insert(M::value_type(2, 2.5));
     28         assert(r.second);
     29         assert(r.first == m.begin());
     30         assert(m.size() == 1);
     31         assert(r.first->first == 2);
     32         assert(r.first->second == 2.5);
     33 
     34         r = m.insert(M::value_type(1, 1.5));
     35         assert(r.second);
     36         assert(r.first == m.begin());
     37         assert(m.size() == 2);
     38         assert(r.first->first == 1);
     39         assert(r.first->second == 1.5);
     40 
     41         r = m.insert(M::value_type(3, 3.5));
     42         assert(r.second);
     43         assert(r.first == prev(m.end()));
     44         assert(m.size() == 3);
     45         assert(r.first->first == 3);
     46         assert(r.first->second == 3.5);
     47 
     48         r = m.insert(M::value_type(3, 3.5));
     49         assert(!r.second);
     50         assert(r.first == prev(m.end()));
     51         assert(m.size() == 3);
     52         assert(r.first->first == 3);
     53         assert(r.first->second == 3.5);
     54     }
     55 #if __cplusplus >= 201103L
     56     {
     57         typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
     58         typedef std::pair<M::iterator, bool> R;
     59         M m;
     60         R r = m.insert(M::value_type(2, 2.5));
     61         assert(r.second);
     62         assert(r.first == m.begin());
     63         assert(m.size() == 1);
     64         assert(r.first->first == 2);
     65         assert(r.first->second == 2.5);
     66 
     67         r = m.insert(M::value_type(1, 1.5));
     68         assert(r.second);
     69         assert(r.first == m.begin());
     70         assert(m.size() == 2);
     71         assert(r.first->first == 1);
     72         assert(r.first->second == 1.5);
     73 
     74         r = m.insert(M::value_type(3, 3.5));
     75         assert(r.second);
     76         assert(r.first == prev(m.end()));
     77         assert(m.size() == 3);
     78         assert(r.first->first == 3);
     79         assert(r.first->second == 3.5);
     80 
     81         r = m.insert(M::value_type(3, 3.5));
     82         assert(!r.second);
     83         assert(r.first == prev(m.end()));
     84         assert(m.size() == 3);
     85         assert(r.first->first == 3);
     86         assert(r.first->second == 3.5);
     87     }
     88 #endif
     89 }
     90