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// XFAIL: FROZEN-CXX03-HEADERS-FIXME
14
15#include <type_traits>
16#include "test_macros.h"
17
18@interface I;
19@end
20
21// add_pointer
22static_assert(std::is_same<std::add_pointer<id>::type, id*>::value, "");
23static_assert(std::is_same<std::add_pointer<I>::type, I*>::value, "");
24
25// add_lvalue_reference
26static_assert(std::is_same<std::add_lvalue_reference<id>::type, id&>::value, "");
27static_assert(std::is_same<std::add_lvalue_reference<I>::type, I&>::value, "");
28
29// add_rvalue_reference
30static_assert(std::is_same<std::add_rvalue_reference<id>::type, id&&>::value, "");
31static_assert(std::is_same<std::add_rvalue_reference<I>::type, I&&>::value, "");
32
33// decay
34static_assert(std::is_same<std::decay<id>::type, id>::value, "");
35static_assert(std::is_same<std::decay<I>::type, I>::value, "");
36static_assert(std::is_same<std::decay<id(&)[5]>::type, id*>::value, "");
37
38// __is_referenceable_v
39LIBCPP_STATIC_ASSERT(std::__is_referenceable_v<id>, "");
40LIBCPP_STATIC_ASSERT(std::__is_referenceable_v<id*>, "");
41LIBCPP_STATIC_ASSERT(std::__is_referenceable_v<id&>, "");
42LIBCPP_STATIC_ASSERT(std::__is_referenceable_v<id&&>, "");
43LIBCPP_STATIC_ASSERT(std::__is_referenceable_v<I>, "");
44LIBCPP_STATIC_ASSERT(std::__is_referenceable_v<I*>, "");
45LIBCPP_STATIC_ASSERT(std::__is_referenceable_v<I&>, "");
46LIBCPP_STATIC_ASSERT(std::__is_referenceable_v<I&&>, "");
47
48// remove_all_extents
49static_assert(std::is_same<std::remove_all_extents<id>::type, id>::value, "");
50static_assert(std::is_same<std::remove_all_extents<id[5]>::type, id>::value, "");
51static_assert(std::is_same<std::remove_all_extents<id[5][10]>::type, id>::value, "");
52static_assert(std::is_same<std::remove_all_extents<I>::type, I>::value, "");
53
54// remove_const
55static_assert(std::is_same<std::remove_const<id>::type, id>::value, "");
56static_assert(std::is_same<std::remove_const<const id>::type, id>::value, "");
57static_assert(std::is_same<std::remove_const<I>::type, I>::value, "");
58static_assert(std::is_same<std::remove_const<const I>::type, I>::value, "");
59
60// remove_cv
61static_assert(std::is_same<std::remove_cv<id>::type, id>::value, "");
62static_assert(std::is_same<std::remove_cv<const volatile id>::type, id>::value, "");
63static_assert(std::is_same<std::remove_cv<I>::type, I>::value, "");
64static_assert(std::is_same<std::remove_cv<const volatile I>::type, I>::value, "");
65
66#if TEST_STD_VER >= 20
67// remove_cvref
68static_assert(std::is_same<std::remove_cvref<id>::type, id>::value, "");
69static_assert(std::is_same<std::remove_cvref<const volatile id&>::type, id>::value, "");
70static_assert(std::is_same<std::remove_cvref<const volatile id&&>::type, id>::value, "");
71static_assert(std::is_same<std::remove_cvref<I>::type, I>::value, "");
72static_assert(std::is_same<std::remove_cvref<const volatile I&>::type, I>::value, "");
73static_assert(std::is_same<std::remove_cvref<const volatile I&&>::type, I>::value, "");
74#endif
75
76// remove_extent
77static_assert(std::is_same<std::remove_all_extents<id>::type, id>::value, "");
78static_assert(std::is_same<std::remove_all_extents<id[5]>::type, id>::value, "");
79static_assert(std::is_same<std::remove_all_extents<I>::type, I>::value, "");
80
81// remove_pointer
82static_assert(!std::is_same<std::remove_pointer<id>::type, id>::value, "");
83// The result of removing and re-adding pointer to `id` should be still `id`.
84static_assert(std::is_same<std::remove_pointer<id>::type*, id>::value, "");
85static_assert(std::is_same<std::add_pointer<std::remove_pointer<id>::type>::type, id>::value, "");
86static_assert(std::is_same<std::remove_pointer<std::add_pointer<id>::type>::type, id>::value, "");
87
88// remove_reference
89static_assert(std::is_same<std::remove_reference<id>::type, 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<id&&>::type, id>::value, "");
93static_assert(std::is_same<std::remove_reference<const id&&>::type, const id>::value, "");
94static_assert(std::is_same<std::remove_reference<I>::type, 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, "");
97static_assert(std::is_same<std::remove_reference<I&&>::type, I>::value, "");
98static_assert(std::is_same<std::remove_reference<const I&&>::type, const I>::value, "");
99
100// remove_volatile
101static_assert(std::is_same<std::remove_volatile<id>::type, id>::value, "");
102static_assert(std::is_same<std::remove_volatile<volatile id>::type, id>::value, "");
103static_assert(std::is_same<std::remove_volatile<I>::type, I>::value, "");
104static_assert(std::is_same<std::remove_volatile<volatile I>::type, I>::value, "");
105
106int main(int, char**) {
107 return 0;
108}
109

source code of libcxx/test/std/utilities/meta/meta.trans/objc_support.compile.pass.mm