1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // REQUIRES: objective-c++
11 // Simple test to check that type traits support Objective-C types.
13 #include <type_traits>
14 #include "test_macros.h"
20 static_assert(std::is_same<std::add_pointer<id>::type, id*>::value, "");
21 static_assert(std::is_same<std::add_pointer<I>::type, I*>::value, "");
23 // add_lvalue_reference
24 static_assert(std::is_same<std::add_lvalue_reference<id>::type, id&>::value, "");
25 static_assert(std::is_same<std::add_lvalue_reference<I>::type, I&>::value, "");
27 // add_rvalue_reference
28 static_assert(std::is_same<std::add_rvalue_reference<id>::type, id&&>::value, "");
29 static_assert(std::is_same<std::add_rvalue_reference<I>::type, I&&>::value, "");
32 static_assert(std::is_same<std::decay<id>::type, id>::value, "");
33 static_assert(std::is_same<std::decay<I>::type, I>::value, "");
34 static_assert(std::is_same<std::decay<id(&)[5]>::type, id*>::value, "");
36 // __libcpp_is_referenceable
37 LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<id>::value, "");
38 LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<id*>::value, "");
39 LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<id&>::value, "");
40 LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<id&&>::value, "");
41 LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<I>::value, "");
42 LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<I*>::value, "");
43 LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<I&>::value, "");
44 LIBCPP_STATIC_ASSERT(std::__libcpp_is_referenceable<I&&>::value, "");
47 static_assert(std::is_same<std::remove_all_extents<id>::type, id>::value, "");
48 static_assert(std::is_same<std::remove_all_extents<id[5]>::type, id>::value, "");
49 static_assert(std::is_same<std::remove_all_extents<id[5][10]>::type, id>::value, "");
50 static_assert(std::is_same<std::remove_all_extents<I>::type, I>::value, "");
53 static_assert(std::is_same<std::remove_const<id>::type, id>::value, "");
54 static_assert(std::is_same<std::remove_const<const id>::type, id>::value, "");
55 static_assert(std::is_same<std::remove_const<I>::type, I>::value, "");
56 static_assert(std::is_same<std::remove_const<const I>::type, I>::value, "");
59 static_assert(std::is_same<std::remove_cv<id>::type, id>::value, "");
60 static_assert(std::is_same<std::remove_cv<const volatile id>::type, id>::value, "");
61 static_assert(std::is_same<std::remove_cv<I>::type, I>::value, "");
62 static_assert(std::is_same<std::remove_cv<const volatile I>::type, I>::value, "");
64 #if TEST_STD_VER >= 20
66 static_assert(std::is_same<std::remove_cvref<id>::type, id>::value, "");
67 static_assert(std::is_same<std::remove_cvref<const volatile id&>::type, id>::value, "");
68 static_assert(std::is_same<std::remove_cvref<const volatile id&&>::type, id>::value, "");
69 static_assert(std::is_same<std::remove_cvref<I>::type, I>::value, "");
70 static_assert(std::is_same<std::remove_cvref<const volatile I&>::type, I>::value, "");
71 static_assert(std::is_same<std::remove_cvref<const volatile I&&>::type, I>::value, "");
75 static_assert(std::is_same<std::remove_all_extents<id>::type, id>::value, "");
76 static_assert(std::is_same<std::remove_all_extents<id[5]>::type, id>::value, "");
77 static_assert(std::is_same<std::remove_all_extents<I>::type, I>::value, "");
80 static_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`.
82 static_assert(std::is_same<std::remove_pointer<id>::type*, id>::value, "");
83 static_assert(std::is_same<std::add_pointer<std::remove_pointer<id>::type>::type, id>::value, "");
84 static_assert(std::is_same<std::remove_pointer<std::add_pointer<id>::type>::type, id>::value, "");
87 static_assert(std::is_same<std::remove_reference<id>::type, id>::value, "");
88 static_assert(std::is_same<std::remove_reference<id&>::type, id>::value, "");
89 static_assert(std::is_same<std::remove_reference<const id&>::type, const id>::value, "");
90 static_assert(std::is_same<std::remove_reference<id&&>::type, id>::value, "");
91 static_assert(std::is_same<std::remove_reference<const id&&>::type, const id>::value, "");
92 static_assert(std::is_same<std::remove_reference<I>::type, I>::value, "");
93 static_assert(std::is_same<std::remove_reference<I&>::type, I>::value, "");
94 static_assert(std::is_same<std::remove_reference<const I&>::type, const I>::value, "");
95 static_assert(std::is_same<std::remove_reference<I&&>::type, I>::value, "");
96 static_assert(std::is_same<std::remove_reference<const I&&>::type, const I>::value, "");
99 static_assert(std::is_same<std::remove_volatile<id>::type, id>::value, "");
100 static_assert(std::is_same<std::remove_volatile<volatile id>::type, id>::value, "");
101 static_assert(std::is_same<std::remove_volatile<I>::type, I>::value, "");
102 static_assert(std::is_same<std::remove_volatile<volatile I>::type, I>::value, "");
104 int main(int, char**) {