blob: 0f90ae5c1cab53e4fb66e3eef7fce1aeed11f8af [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
8//===----------------------------------------------------------------------===//
9
10// type_traits
11
12// is_base_of
13
14#include <type_traits>
15
16template <class T, class U>
17void test_is_base_of()
18{
19 static_assert((std::is_base_of<T, U>::value), "");
20 static_assert((std::is_base_of<const T, U>::value), "");
21 static_assert((std::is_base_of<T, const U>::value), "");
22 static_assert((std::is_base_of<const T, const U>::value), "");
23}
24
25template <class T, class U>
26void test_is_not_base_of()
27{
28 static_assert((!std::is_base_of<T, U>::value), "");
29}
30
31struct B {};
32struct B1 : B {};
33struct B2 : B {};
34struct D : private B1, private B2 {};
35
36int main()
37{
38 test_is_base_of<B, D>();
39 test_is_base_of<B1, D>();
40 test_is_base_of<B2, D>();
41 test_is_base_of<B, B1>();
42 test_is_base_of<B, B2>();
43 test_is_base_of<B, B>();
44
45 test_is_not_base_of<D, B>();
46 test_is_not_base_of<B&, D&>();
47 test_is_not_base_of<B[3], D[3]>();
48 test_is_not_base_of<int, int>();
Howard Hinnantc52f43e2010-08-22 00:59:46 +000049}