llvm-project
69 строк · 1.7 Кб
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <map>
10
11// class map
12
13// iterator insert(const_iterator position, const value_type& v);
14
15#include <map>16#include <cassert>17
18#include "test_macros.h"19#include "min_allocator.h"20
21template <class Container>22void do_insert_iter_cv_test()23{
24typedef Container M;25typedef typename M::iterator R;26typedef typename M::value_type VT;27
28M m;29const VT v1(2, 2.5);30R r = m.insert(m.end(), v1);31assert(r == m.begin());32assert(m.size() == 1);33assert(r->first == 2);34assert(r->second == 2.5);35
36const VT v2(1, 1.5);37r = m.insert(m.end(), v2);38assert(r == m.begin());39assert(m.size() == 2);40assert(r->first == 1);41assert(r->second == 1.5);42
43const VT v3(3, 3.5);44r = m.insert(m.end(), v3);45assert(r == std::prev(m.end()));46assert(m.size() == 3);47assert(r->first == 3);48assert(r->second == 3.5);49
50const VT v4(3, 4.5);51r = m.insert(m.end(), v4);52assert(r == std::prev(m.end()));53assert(m.size() == 3);54assert(r->first == 3);55assert(r->second == 3.5);56}
57
58int main(int, char**)59{
60do_insert_iter_cv_test<std::map<int, double> >();61#if TEST_STD_VER >= 1162{63typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;64do_insert_iter_cv_test<M>();65}66#endif67
68return 0;69}
70