1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// <span>
// template<class OtherElementType, size_t OtherExtent>
// constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;
//
// Remarks: This constructor shall not participate in overload resolution unless:
// Extent == dynamic_extent || Extent == OtherExtent is true, and
// OtherElementType(*)[] is convertible to ElementType(*)[].
#include <span>
#include <cassert>
#include <string>
#include "test_macros.h"
template <class T, class From>
TEST_CONSTEXPR_CXX20 void check() {
// dynamic -> dynamic
{
{
std::span<From> from;
std::span<T> span{from};
ASSERT_NOEXCEPT(std::span<T>(from));
assert(span.data() == nullptr);
assert(span.size() == 0);
}
{
From array[3] = {};
std::span<From> from(array);
std::span<T> span{from};
ASSERT_NOEXCEPT(std::span<T>(from));
assert(span.data() == array);
assert(span.size() == 3);
}
}
// static -> static
{
{
std::span<From, 0> from;
std::span<T, 0> span{from};
ASSERT_NOEXCEPT(std::span<T, 0>(from));
assert(span.data() == nullptr);
assert(span.size() == 0);
}
{
From array[3] = {};
std::span<From, 3> from(array);
std::span<T, 3> span{from};
ASSERT_NOEXCEPT(std::span<T, 3>(from));
assert(span.data() == array);
assert(span.size() == 3);
}
}
// static -> dynamic
{
{
std::span<From, 0> from;
std::span<T> span{from};
ASSERT_NOEXCEPT(std::span<T>(from));
assert(span.data() == nullptr);
assert(span.size() == 0);
}
{
From array[3] = {};
std::span<From, 3> from(array);
std::span<T> span{from};
ASSERT_NOEXCEPT(std::span<T>(from));
assert(span.data() == array);
assert(span.size() == 3);
}
}
// dynamic -> static (not allowed)
}
template <class T>
TEST_CONSTEXPR_CXX20 void check_cvs() {
check<T, T>();
check<T const, T>();
check<T const, T const>();
check<T volatile, T>();
check<T volatile, T volatile>();
check<T const volatile, T>();
check<T const volatile, T const>();
check<T const volatile, T volatile>();
check<T const volatile, T const volatile>();
}
struct A {};
TEST_CONSTEXPR_CXX20 bool test() {
check_cvs<int>();
check_cvs<long>();
check_cvs<double>();
check_cvs<std::string>();
check_cvs<A>();
return true;
}
int main(int, char**) {
static_assert(test());
test();
return 0;
}
|