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 #include "test_macros.h" 17 18 template <class T, class U> 19 void test_is_base_of() 20 { 21 static_assert((std::is_base_of<T, U>::value), ""); 22 static_assert((std::is_base_of<const T, U>::value), ""); 23 static_assert((std::is_base_of<T, const U>::value), ""); 24 static_assert((std::is_base_of<const T, const U>::value), ""); 25 #if TEST_STD_VER > 14 26 static_assert((std::is_base_of_v<T, U>), ""); 27 static_assert((std::is_base_of_v<const T, U>), ""); 28 static_assert((std::is_base_of_v<T, const U>), ""); 29 static_assert((std::is_base_of_v<const T, const U>), ""); 30 #endif 31 } 32 33 template <class T, class U> 34 void test_is_not_base_of() 35 { 36 static_assert((!std::is_base_of<T, U>::value), ""); 37 } 38 39 struct B {}; 40 struct B1 : B {}; 41 struct B2 : B {}; 42 struct D : private B1, private B2 {}; 43 44 int main() 45 { 46 test_is_base_of<B, D>(); 47 test_is_base_of<B1, D>(); 48 test_is_base_of<B2, D>(); 49 test_is_base_of<B, B1>(); 50 test_is_base_of<B, B2>(); 51 test_is_base_of<B, B>(); 52 53 test_is_not_base_of<D, B>(); 54 test_is_not_base_of<B&, D&>(); 55 test_is_not_base_of<B[3], D[3]>(); 56 test_is_not_base_of<int, int>(); 57 } 58