1//===----------------------------------------------------------------------===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9// REQUIRES: objective-c++ 10 11// Simple test to check that type traits support Objective-C types. 12 13#include <type_traits> 14#include "test_macros.h" 15 16@interface I; 17@end 18 19// add_pointer 20static_assert(std::is_same<std::add_pointer<id>::type, id*>::value, ""); 21static_assert(std::is_same<std::add_pointer<I>::type, I*>::value, ""); 22 23// add_lvalue_reference 24static_assert(std::is_same<std::add_lvalue_reference<id>::type, id&>::value, ""); 25static_assert(std::is_same<std::add_lvalue_reference<I>::type, I&>::value, ""); 26 27// add_rvalue_reference 28static_assert(std::is_same<std::add_rvalue_reference<id>::type, id&&>::value, ""); 29static_assert(std::is_same<std::add_rvalue_reference<I>::type, I&&>::value, ""); 30 31// decay 32static_assert(std::is_same<std::decay<id>::type, id>::value, ""); 33static_assert(std::is_same<std::decay<I>::type, I>::value, ""); 34static_assert(std::is_same<std::decay<id(&)[5]>::type, id*>::value, ""); 35 36// __libcpp_is_referenceable 37LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<id>::value, ""); 38LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<id*>::value, ""); 39LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<id&>::value, ""); 40LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<id&&>::value, ""); 41LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<I>::value, ""); 42LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<I*>::value, ""); 43LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<I&>::value, ""); 44LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<I&&>::value, ""); 45 46// remove_all_extents 47static_assert(std::is_same<std::remove_all_extents<id>::type, id>::value, ""); 48static_assert(std::is_same<std::remove_all_extents<id[5]>::type, id>::value, ""); 49static_assert(std::is_same<std::remove_all_extents<id[5][10]>::type, id>::value, ""); 50static_assert(std::is_same<std::remove_all_extents<I>::type, I>::value, ""); 51 52// remove_const 53static_assert(std::is_same<std::remove_const<id>::type, id>::value, ""); 54static_assert(std::is_same<std::remove_const<const id>::type, id>::value, ""); 55static_assert(std::is_same<std::remove_const<I>::type, I>::value, ""); 56static_assert(std::is_same<std::remove_const<const I>::type, I>::value, ""); 57 58// remove_cv 59static_assert(std::is_same<std::remove_cv<id>::type, id>::value, ""); 60static_assert(std::is_same<std::remove_cv<const volatile id>::type, id>::value, ""); 61static_assert(std::is_same<std::remove_cv<I>::type, I>::value, ""); 62static_assert(std::is_same<std::remove_cv<const volatile I>::type, I>::value, ""); 63 64#if TEST_STD_VER >= 20 65// remove_cvref 66static_assert(std::is_same<std::remove_cvref<id>::type, id>::value, ""); 67static_assert(std::is_same<std::remove_cvref<const volatile id&>::type, id>::value, ""); 68static_assert(std::is_same<std::remove_cvref<const volatile id&&>::type, id>::value, ""); 69static_assert(std::is_same<std::remove_cvref<I>::type, I>::value, ""); 70static_assert(std::is_same<std::remove_cvref<const volatile I&>::type, I>::value, ""); 71static_assert(std::is_same<std::remove_cvref<const volatile I&&>::type, I>::value, ""); 72#endif 73 74// remove_extent 75static_assert(std::is_same<std::remove_all_extents<id>::type, id>::value, ""); 76static_assert(std::is_same<std::remove_all_extents<id[5]>::type, id>::value, ""); 77static_assert(std::is_same<std::remove_all_extents<I>::type, I>::value, ""); 78 79// remove_pointer 80static_assert(!std::is_same<std::remove_pointer<id>::type, id>::value, ""); 81// The result of removing and re-adding pointer to `id` should be still `id`. 82static_assert(std::is_same<std::remove_pointer<id>::type*, id>::value, ""); 83static_assert(std::is_same<std::add_pointer<std::remove_pointer<id>::type>::type, id>::value, ""); 84static_assert(std::is_same<std::remove_pointer<std::add_pointer<id>::type>::type, id>::value, ""); 85 86// remove_reference 87static_assert(std::is_same<std::remove_reference<id>::type, id>::value, ""); 88static_assert(std::is_same<std::remove_reference<id&>::type, id>::value, ""); 89static_assert(std::is_same<std::remove_reference<const id&>::type, const id>::value, ""); 90static_assert(std::is_same<std::remove_reference<id&&>::type, id>::value, ""); 91static_assert(std::is_same<std::remove_reference<const id&&>::type, const id>::value, ""); 92static_assert(std::is_same<std::remove_reference<I>::type, I>::value, ""); 93static_assert(std::is_same<std::remove_reference<I&>::type, I>::value, ""); 94static_assert(std::is_same<std::remove_reference<const I&>::type, const I>::value, ""); 95static_assert(std::is_same<std::remove_reference<I&&>::type, I>::value, ""); 96static_assert(std::is_same<std::remove_reference<const I&&>::type, const I>::value, ""); 97 98// remove_volatile 99static_assert(std::is_same<std::remove_volatile<id>::type, id>::value, ""); 100static_assert(std::is_same<std::remove_volatile<volatile id>::type, id>::value, ""); 101static_assert(std::is_same<std::remove_volatile<I>::type, I>::value, ""); 102static_assert(std::is_same<std::remove_volatile<volatile I>::type, I>::value, ""); 103 104int main(int, char**) { 105 return 0; 106} 107