| 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 |
// unique_ptr |
| 12 |
|
| 13 |
// test get |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
#include <cassert> |
| 17 |
|
| 18 |
#include "test_macros.h" |
| 19 |
#include "unique_ptr_test_helper.h" |
| 20 |
|
| 21 |
template <bool IsArray> |
| 22 |
TEST_CONSTEXPR_CXX23 void test_basic() { |
| 23 |
typedef typename std::conditional<IsArray, int[], int>::type VT; |
| 24 |
typedef const VT CVT; |
| 25 |
{ |
| 26 |
typedef std::unique_ptr<VT> U; |
| 27 |
int* p = newValue<VT>(1); |
| 28 |
U s(p); |
| 29 |
U const& sc = s; |
| 30 |
ASSERT_SAME_TYPE(decltype(s.get()), int*); |
| 31 |
ASSERT_SAME_TYPE(decltype(sc.get()), int*); |
| 32 |
assert(s.get() == p); |
| 33 |
assert(sc.get() == s.get()); |
| 34 |
} |
| 35 |
{ |
| 36 |
typedef std::unique_ptr<CVT> U; |
| 37 |
const int* p = newValue<VT>(1); |
| 38 |
U s(p); |
| 39 |
U const& sc = s; |
| 40 |
ASSERT_SAME_TYPE(decltype(s.get()), const int*); |
| 41 |
ASSERT_SAME_TYPE(decltype(sc.get()), const int*); |
| 42 |
assert(s.get() == p); |
| 43 |
assert(sc.get() == s.get()); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
TEST_CONSTEXPR_CXX23 bool test() { |
| 48 |
test_basic</*IsArray*/ false>(); |
| 49 |
test_basic<true>(); |
| 50 |
|
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
int main(int, char**) { |
| 55 |
test(); |
| 56 |
#if TEST_STD_VER >= 23 |
| 57 |
static_assert(test()); |
| 58 |
#endif |
| 59 |
|
| 60 |
return 0; |
| 61 |
} |