Chandler Carruth | e8529c2 | 2016-08-19 02:07:51 +0000 | [diff] [blame] | 1 | //===- STLExtrasTest.cpp - Unit tests for STL extras ----------------------===// |
| 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 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/ADT/STLExtras.h" |
| 11 | #include "gtest/gtest.h" |
| 12 | |
| 13 | using namespace llvm; |
| 14 | |
| 15 | namespace { |
| 16 | |
| 17 | int f(rank<0>) { return 0; } |
| 18 | int f(rank<1>) { return 1; } |
| 19 | int f(rank<2>) { return 2; } |
| 20 | int f(rank<4>) { return 4; } |
| 21 | |
| 22 | TEST(STLExtrasTest, Rank) { |
| 23 | // We shouldn't get ambiguities and should select the overload of the same |
| 24 | // rank as the argument. |
| 25 | EXPECT_EQ(0, f(rank<0>())); |
| 26 | EXPECT_EQ(1, f(rank<1>())); |
| 27 | EXPECT_EQ(2, f(rank<2>())); |
| 28 | |
| 29 | // This overload is missing so we end up back at 2. |
| 30 | EXPECT_EQ(2, f(rank<3>())); |
| 31 | |
| 32 | // But going past 3 should work fine. |
| 33 | EXPECT_EQ(4, f(rank<4>())); |
| 34 | |
| 35 | // And we can even go higher and just fall back to the last overload. |
| 36 | EXPECT_EQ(4, f(rank<5>())); |
| 37 | EXPECT_EQ(4, f(rank<6>())); |
| 38 | } |
| 39 | |
Chandler Carruth | e8529c2 | 2016-08-19 02:07:51 +0000 | [diff] [blame] | 40 | } |