1 //===------ MappedIteratorTest.cpp - Unit tests for mapped_iterator -------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/STLExtras.h"
10 #include "gtest/gtest.h"
16 TEST(MappedIteratorTest
, ApplyFunctionOnDereference
) {
17 std::vector
<int> V({0});
19 auto I
= map_iterator(V
.begin(), [](int X
) { return X
+ 1; });
21 EXPECT_EQ(*I
, 1) << "should have applied function in dereference";
24 TEST(MappedIteratorTest
, ApplyFunctionOnArrow
) {
29 std::vector
<int> V({0});
33 auto I
= map_iterator(V
.begin(), [&](int X
) -> S
& { return *(P
+ X
); });
37 EXPECT_EQ(Y
.Z
, 42) << "should have applied function during arrow";
40 TEST(MappedIteratorTest
, FunctionPreservesReferences
) {
41 std::vector
<int> V({1});
42 std::map
<int, int> M({ {1, 1} });
44 auto I
= map_iterator(V
.begin(), [&](int X
) -> int& { return M
[X
]; });
47 EXPECT_EQ(M
[1], 42) << "assignment should have modified M";
50 } // anonymous namespace