| 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 |
// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 |
|
| 11 |
// constexpr T* data() noexcept; |
| 12 |
// constexpr const T* data() const noexcept; |
| 13 |
|
| 14 |
#include <ranges> |
| 15 |
#include <cassert> |
| 16 |
|
| 17 |
#include "test_macros.h" |
| 18 |
|
| 19 |
struct Empty {}; |
| 20 |
struct BigType { char buffer[64] = {10}; }; |
| 21 |
|
| 22 |
constexpr bool test() { |
| 23 |
{ |
| 24 |
auto sv = std::ranges::single_view<int>(42); |
| 25 |
assert(*sv.data() == 42); |
| 26 |
|
| 27 |
ASSERT_SAME_TYPE(decltype(sv.data()), int*); |
| 28 |
static_assert(noexcept(sv.data())); |
| 29 |
} |
| 30 |
{ |
| 31 |
const auto sv = std::ranges::single_view<int>(42); |
| 32 |
assert(*sv.data() == 42); |
| 33 |
|
| 34 |
ASSERT_SAME_TYPE(decltype(sv.data()), const int*); |
| 35 |
static_assert(noexcept(sv.data())); |
| 36 |
} |
| 37 |
|
| 38 |
{ |
| 39 |
auto sv = std::ranges::single_view<Empty>(Empty()); |
| 40 |
assert(sv.data() != nullptr); |
| 41 |
|
| 42 |
ASSERT_SAME_TYPE(decltype(sv.data()), Empty*); |
| 43 |
} |
| 44 |
{ |
| 45 |
const auto sv = std::ranges::single_view<Empty>(Empty()); |
| 46 |
assert(sv.data() != nullptr); |
| 47 |
|
| 48 |
ASSERT_SAME_TYPE(decltype(sv.data()), const Empty*); |
| 49 |
} |
| 50 |
|
| 51 |
{ |
| 52 |
auto sv = std::ranges::single_view<BigType>(BigType()); |
| 53 |
assert(sv.data()->buffer[0] == 10); |
| 54 |
|
| 55 |
ASSERT_SAME_TYPE(decltype(sv.data()), BigType*); |
| 56 |
} |
| 57 |
{ |
| 58 |
const auto sv = std::ranges::single_view<BigType>(BigType()); |
| 59 |
assert(sv.data()->buffer[0] == 10); |
| 60 |
|
| 61 |
ASSERT_SAME_TYPE(decltype(sv.data()), const BigType*); |
| 62 |
} |
| 63 |
|
| 64 |
return true; |
| 65 |
} |
| 66 |
|
| 67 |
int main(int, char**) { |
| 68 |
test(); |
| 69 |
static_assert(test()); |
| 70 |
|
| 71 |
return 0; |
| 72 |
} |