1 //===-- stl_extras_test.cpp ------------------------------------------===// 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 // This file is a part of the ORC runtime. 10 // 11 // Note: 12 // This unit test was adapted from tests in 13 // llvm/unittests/ADT/STLExtrasTest.cpp 14 // 15 //===----------------------------------------------------------------------===// 16 17 #include "stl_extras.h" 18 #include "gtest/gtest.h" 19 20 using namespace __orc_rt; 21 22 TEST(STLExtrasTest, ApplyTuple) { 23 auto T = std::make_tuple(1, 3, 7); 24 auto U = __orc_rt::apply_tuple( 25 [](int A, int B, int C) { return std::make_tuple(A - B, B - C, C - A); }, 26 T); 27 28 EXPECT_EQ(-2, std::get<0>(U)); 29 EXPECT_EQ(-4, std::get<1>(U)); 30 EXPECT_EQ(6, std::get<2>(U)); 31 32 auto V = __orc_rt::apply_tuple( 33 [](int A, int B, int C) { 34 return std::make_tuple(std::make_pair(A, char('A' + A)), 35 std::make_pair(B, char('A' + B)), 36 std::make_pair(C, char('A' + C))); 37 }, 38 T); 39 40 EXPECT_EQ(std::make_pair(1, 'B'), std::get<0>(V)); 41 EXPECT_EQ(std::make_pair(3, 'D'), std::get<1>(V)); 42 EXPECT_EQ(std::make_pair(7, 'H'), std::get<2>(V)); 43 } 44 45 class apply_variadic { 46 static int apply_one(int X) { return X + 1; } 47 static char apply_one(char C) { return C + 1; } 48 static std::string apply_one(std::string S) { 49 return S.substr(0, S.size() - 1); 50 } 51 52 public: 53 template <typename... Ts> auto operator()(Ts &&... Items) { 54 return std::make_tuple(apply_one(Items)...); 55 } 56 }; 57 58 TEST(STLExtrasTest, ApplyTupleVariadic) { 59 auto Items = std::make_tuple(1, std::string("Test"), 'X'); 60 auto Values = __orc_rt::apply_tuple(apply_variadic(), Items); 61 62 EXPECT_EQ(2, std::get<0>(Values)); 63 EXPECT_EQ("Tes", std::get<1>(Values)); 64 EXPECT_EQ('Y', std::get<2>(Values)); 65 } 66