1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // type_traits 11 12 // is_base_of 13 14 #include <type_traits> 15 16 template <class T, class U> 17 void 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 25 template <class T, class U> 26 void test_is_not_base_of() 27 { 28 static_assert((!std::is_base_of<T, U>::value), ""); 29 } 30 31 struct B {}; 32 struct B1 : B {}; 33 struct B2 : B {}; 34 struct D : private B1, private B2 {}; 35 36 int 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>(); 49 } 50