Home | History | Annotate | Download | only in unord.map.elem
      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 // <unordered_map>
     11 
     12 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
     13 //           class Alloc = allocator<pair<const Key, T>>>
     14 // class unordered_map
     15 
     16 // mapped_type& operator[](const key_type& k);
     17 
     18 #include <unordered_map>
     19 #include <string>
     20 #include <cassert>
     21 
     22 #include "../../../MoveOnly.h"
     23 #include "min_allocator.h"
     24 
     25 int main()
     26 {
     27     {
     28         typedef std::unordered_map<int, std::string> C;
     29         typedef std::pair<int, std::string> P;
     30         P a[] =
     31         {
     32             P(1, "one"),
     33             P(2, "two"),
     34             P(3, "three"),
     35             P(4, "four"),
     36             P(1, "four"),
     37             P(2, "four"),
     38         };
     39         C c(a, a + sizeof(a)/sizeof(a[0]));
     40         assert(c.size() == 4);
     41         c[1] = "ONE";
     42         assert(c.at(1) == "ONE");
     43         c[11] = "eleven";
     44         assert(c.size() == 5);
     45         assert(c.at(11) == "eleven");
     46     }
     47 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     48     {
     49         typedef std::unordered_map<MoveOnly, std::string> C;
     50         typedef std::pair<int, std::string> P;
     51         P a[] =
     52         {
     53             P(1, "one"),
     54             P(2, "two"),
     55             P(3, "three"),
     56             P(4, "four"),
     57             P(1, "four"),
     58             P(2, "four"),
     59         };
     60         C c(a, a + sizeof(a)/sizeof(a[0]));
     61         assert(c.size() == 4);
     62         c[1] = "ONE";
     63         assert(c.at(1) == "ONE");
     64         c[11] = "eleven";
     65         assert(c.size() == 5);
     66         assert(c.at(11) == "eleven");
     67     }
     68 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     69 #if __cplusplus >= 201103L
     70     {
     71         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
     72                             min_allocator<std::pair<const int, std::string>>> C;
     73         typedef std::pair<int, std::string> P;
     74         P a[] =
     75         {
     76             P(1, "one"),
     77             P(2, "two"),
     78             P(3, "three"),
     79             P(4, "four"),
     80             P(1, "four"),
     81             P(2, "four"),
     82         };
     83         C c(a, a + sizeof(a)/sizeof(a[0]));
     84         assert(c.size() == 4);
     85         c[1] = "ONE";
     86         assert(c.at(1) == "ONE");
     87         c[11] = "eleven";
     88         assert(c.size() == 5);
     89         assert(c.at(11) == "eleven");
     90     }
     91 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     92     {
     93         typedef std::unordered_map<MoveOnly, std::string, std::hash<MoveOnly>, std::equal_to<MoveOnly>,
     94                             min_allocator<std::pair<const MoveOnly, std::string>>> C;
     95         typedef std::pair<int, std::string> P;
     96         P a[] =
     97         {
     98             P(1, "one"),
     99             P(2, "two"),
    100             P(3, "three"),
    101             P(4, "four"),
    102             P(1, "four"),
    103             P(2, "four"),
    104         };
    105         C c(a, a + sizeof(a)/sizeof(a[0]));
    106         assert(c.size() == 4);
    107         c[1] = "ONE";
    108         assert(c.at(1) == "ONE");
    109         c[11] = "eleven";
    110         assert(c.size() == 5);
    111         assert(c.at(11) == "eleven");
    112     }
    113 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    114 #endif
    115 }
    116