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// <memory>
10
11// template<class T> class shared_ptr
12// {
13// public:
14// typedef T element_type; // until C++17
15// typedef remove_extent_t<T> element_type; // since C++17
16// typedef weak_ptr<T> weak_type; // C++17
17// ...
18// };
19
20#include <memory>
21#include <type_traits>
22#include <utility>
23
24#include "test_macros.h"
25
26#if TEST_STD_VER > 14
27template <typename T, typename = std::void_t<> >
28struct has_less : std::false_type {};
29
30template <typename T>
31struct has_less<T,
32 std::void_t<decltype(std::declval<T>() < std::declval<T>())> >
33 : std::true_type {};
34#endif
35
36struct A; // purposefully incomplete
37struct B {
38 int x;
39 B() = default;
40};
41
42template <class T>
43void test() {
44 ASSERT_SAME_TYPE(typename std::shared_ptr<T>::element_type, T);
45#if TEST_STD_VER > 14
46 ASSERT_SAME_TYPE(typename std::shared_ptr<T>::weak_type, std::weak_ptr<T>);
47 static_assert(std::is_copy_constructible<std::shared_ptr<T> >::value, "");
48 static_assert(std::is_copy_assignable<std::shared_ptr<T> >::value, "");
49 static_assert(has_less<std::shared_ptr<T> >::value);
50 ASSERT_SAME_TYPE(typename std::shared_ptr<T[]>::element_type, T);
51 ASSERT_SAME_TYPE(typename std::shared_ptr<T[8]>::element_type, T);
52#endif
53}
54
55int main(int, char**) {
56 test<A>();
57 test<B>();
58 test<int>();
59 test<char*>();
60
61#if TEST_STD_VER > 14
62 ASSERT_SAME_TYPE(typename std::shared_ptr<int[][2]>::element_type, int[2]);
63#endif
64
65 return 0;
66}
67

source code of libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp