libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

header_map_synop.pass.cpp (2205B)


      1 // -*- C++ -*-
      2 //===----------------------------------------------------------------------===//
      3 //
      4 //                     The LLVM Compiler Infrastructure
      5 //
      6 // This file is dual licensed under the MIT and the University of Illinois Open
      7 // Source Licenses. See LICENSE.TXT for details.
      8 //
      9 //===----------------------------------------------------------------------===//
     10 
     11 // REQUIRES: c++experimental
     12 // UNSUPPORTED: c++98, c++03
     13 
     14 // <experimental/map>
     15 
     16 // namespace std { namespace experimental { namespace pmr {
     17 // template <class K, class V, class Compare = less<Key> >
     18 // using map =
     19 //     ::std::map<K, V, Compare, polymorphic_allocator<pair<const K, V>>>
     20 //
     21 // template <class K, class V, class Compare = less<Key> >
     22 // using multimap =
     23 //     ::std::multimap<K, V, Compare, polymorphic_allocator<pair<const K, V>>>
     24 //
     25 // }}} // namespace std::experimental::pmr
     26 
     27 #include <experimental/map>
     28 #include <experimental/memory_resource>
     29 #include <type_traits>
     30 #include <cassert>
     31 
     32 namespace pmr = std::experimental::pmr;
     33 
     34 int main()
     35 {
     36     using K = int;
     37     using V = char;
     38     using DC = std::less<int>;
     39     using OC = std::greater<int>;
     40     using P = std::pair<const K, V>;
     41     {
     42         using StdMap = std::map<K, V, DC, pmr::polymorphic_allocator<P>>;
     43         using PmrMap = pmr::map<K, V>;
     44         static_assert(std::is_same<StdMap, PmrMap>::value, "");
     45     }
     46     {
     47         using StdMap = std::map<K, V, OC, pmr::polymorphic_allocator<P>>;
     48         using PmrMap = pmr::map<K, V, OC>;
     49         static_assert(std::is_same<StdMap, PmrMap>::value, "");
     50     }
     51     {
     52         pmr::map<int, int> m;
     53         assert(m.get_allocator().resource() == pmr::get_default_resource());
     54     }
     55     {
     56         using StdMap = std::multimap<K, V, DC, pmr::polymorphic_allocator<P>>;
     57         using PmrMap = pmr::multimap<K, V>;
     58         static_assert(std::is_same<StdMap, PmrMap>::value, "");
     59     }
     60     {
     61         using StdMap = std::multimap<K, V, OC, pmr::polymorphic_allocator<P>>;
     62         using PmrMap = pmr::multimap<K, V, OC>;
     63         static_assert(std::is_same<StdMap, PmrMap>::value, "");
     64     }
     65     {
     66         pmr::multimap<int, int> m;
     67         assert(m.get_allocator().resource() == pmr::get_default_resource());
     68     }
     69 }