1 //===------ MappedIteratorTest.cpp - Unit tests for mapped_iterator -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/STLExtras.h"
11 #include "gtest/gtest.h"
17 TEST(MappedIteratorTest
, ApplyFunctionOnDereference
) {
18 std::vector
<int> V({0});
20 auto I
= map_iterator(V
.begin(), [](int X
) { return X
+ 1; });
22 EXPECT_EQ(*I
, 1) << "should have applied function in dereference";
25 TEST(MappedIteratorTest
, ApplyFunctionOnArrow
) {
30 std::vector
<int> V({0});
34 auto I
= map_iterator(V
.begin(), [&](int X
) -> S
& { return *(P
+ X
); });
38 EXPECT_EQ(Y
.Z
, 42) << "should have applied function during arrow";
41 TEST(MappedIteratorTest
, FunctionPreservesReferences
) {
42 std::vector
<int> V({1});
43 std::map
<int, int> M({ {1, 1} });
45 auto I
= map_iterator(V
.begin(), [&](int X
) -> int& { return M
[X
]; });
48 EXPECT_EQ(M
[1], 42) << "assignment should have modified M";
51 } // anonymous namespace