is_base_of.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===// 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// 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>(); 49 test_is_not_base_of<int, int>(); 50} 51