[DAGCombiner] Expand combining of FP logical ops to sign-setting FP ops
[llvm-core.git] / unittests / ADT / MappedIteratorTest.cpp
blobd8c48a7d6257cf686f7d2ff7410d8f7901fdaef5
1 //===------ MappedIteratorTest.cpp - Unit tests for mapped_iterator -------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/STLExtras.h"
11 #include "gtest/gtest.h"
13 using namespace llvm;
15 namespace {
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) {
26 struct S {
27 int Z = 0;
30 std::vector<int> V({0});
31 S Y;
32 S* P = &Y;
34 auto I = map_iterator(V.begin(), [&](int X) -> S& { return *(P + X); });
36 I->Z = 42;
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]; });
46 *I = 42;
48 EXPECT_EQ(M[1], 42) << "assignment should have modified M";
51 } // anonymous namespace