//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03 // // class map // pair insert( value_type&& v); // C++17 and later // template // pair insert(P&& p); #include #include #include "MoveOnly.h" #include "min_allocator.h" #include "test_macros.h" template void do_insert_rv_test() { typedef Container M; typedef Pair P; typedef std::pair R; M m; R r = m.insert(P(2, 2)); assert(r.second); assert(r.first == m.begin()); assert(m.size() == 1); assert(r.first->first == 2); assert(r.first->second == 2); r = m.insert(P(1, 1)); assert(r.second); assert(r.first == m.begin()); assert(m.size() == 2); assert(r.first->first == 1); assert(r.first->second == 1); r = m.insert(P(3, 3)); assert(r.second); assert(r.first == std::prev(m.end())); assert(m.size() == 3); assert(r.first->first == 3); assert(r.first->second == 3); r = m.insert(P(3, 3)); assert(!r.second); assert(r.first == std::prev(m.end())); assert(m.size() == 3); assert(r.first->first == 3); assert(r.first->second == 3); } int main(int, char**) { do_insert_rv_test, std::pair>(); do_insert_rv_test, std::pair>(); { typedef std::map, min_allocator>> M; typedef std::pair P; typedef std::pair CP; do_insert_rv_test(); do_insert_rv_test(); } { typedef std::map M; typedef std::pair R; M m; R r = m.insert({2, MoveOnly(2)}); assert(r.second); assert(r.first == m.begin()); assert(m.size() == 1); assert(r.first->first == 2); assert(r.first->second == 2); r = m.insert({1, MoveOnly(1)}); assert(r.second); assert(r.first == m.begin()); assert(m.size() == 2); assert(r.first->first == 1); assert(r.first->second == 1); r = m.insert({3, MoveOnly(3)}); assert(r.second); assert(r.first == std::prev(m.end())); assert(m.size() == 3); assert(r.first->first == 3); assert(r.first->second == 3); r = m.insert({3, MoveOnly(3)}); assert(!r.second); assert(r.first == std::prev(m.end())); assert(m.size() == 3); assert(r.first->first == 3); assert(r.first->second == 3); } return 0; }