typedef int V; typedef M::iterator I; V ar[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; M m(ar, ar + sizeof(ar)/sizeof(ar[0])); REQUIRE(m.size() == 8); I i = m.erase(next(m.cbegin(), 5), next(m.cbegin(), 5)); REQUIRE(m.size() == 8); REQUIRE(i == next(m.begin(), 5)); REQUIRE(*next(m.begin(), 0) == 1); REQUIRE(*next(m.begin(), 1) == 2); REQUIRE(*next(m.begin(), 2) == 3); REQUIRE(*next(m.begin(), 3) == 4); REQUIRE(*next(m.begin(), 4) == 5); REQUIRE(*next(m.begin(), 5) == 6); REQUIRE(*next(m.begin(), 6) == 7); REQUIRE(*next(m.begin(), 7) == 8); i = m.erase(next(m.cbegin(), 3), next(m.cbegin(), 4)); REQUIRE(m.size() == 7); REQUIRE(i == next(m.begin(), 3)); REQUIRE(*next(m.begin(), 0) == 1);
typedef std::pair<int, double> P; typedef M::iterator I; P ar[] = { P(1, 1.5), P(2, 2.5), P(3, 3.5), P(4, 4.5), P(5, 5.5), P(6, 6.5), P(7, 7.5), P(8, 8.5), }; M m(ar, ar + sizeof(ar)/sizeof(ar[0])); REQUIRE(m.size() == 8); I i = m.erase(next(m.cbegin(), 3)); REQUIRE(m.size() == 7); REQUIRE(i == next(m.begin(), 3)); REQUIRE(m.begin()->first == 1); REQUIRE(m.begin()->second == 1.5); REQUIRE(next(m.begin())->first == 2); REQUIRE(next(m.begin())->second == 2.5); REQUIRE(next(m.begin(), 2)->first == 3); REQUIRE(next(m.begin(), 2)->second == 3.5); REQUIRE(next(m.begin(), 3)->first == 5); REQUIRE(next(m.begin(), 3)->second == 5.5); REQUIRE(next(m.begin(), 4)->first == 6); REQUIRE(next(m.begin(), 4)->second == 6.5); REQUIRE(next(m.begin(), 5)->first == 7); REQUIRE(next(m.begin(), 5)->second == 7.5); REQUIRE(next(m.begin(), 6)->first == 8);