blob: dc62b03741c0c0425263bc4f11035cb2ee9e545c [file] [log] [blame]
Chandler Carruthe8529c22016-08-19 02:07:51 +00001//===- 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
13using namespace llvm;
14
15namespace {
16
17int f(rank<0>) { return 0; }
18int f(rank<1>) { return 1; }
19int f(rank<2>) { return 2; }
20int f(rank<4>) { return 4; }
21
22TEST(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 Carruthe8529c22016-08-19 02:07:51 +000040}