|
9 | 9 | #ifndef TEST_STD_INPUTOUTPUT_SPANSTREAMS_TYPES_H
|
10 | 10 | #define TEST_STD_INPUTOUTPUT_SPANSTREAMS_TYPES_H
|
11 | 11 |
|
12 |
| -#include <string_view> |
13 | 12 | #include <concepts>
|
| 13 | +#include <cstddef> |
| 14 | +#include <span> |
| 15 | +#include <ranges> |
14 | 16 |
|
15 | 17 | #include "test_macros.h"
|
16 | 18 |
|
17 |
| -// template <typename CharT, class Traits = std::char_traits<CharT>> |
18 |
| -// class ConstConvertibleStringView { |
19 |
| -// public: |
20 |
| -// explicit ConstConvertibleStringView(const CharT* cs) : cs_{cs} {} |
| 19 | +template <typename CharT, std::size_t N = 0> |
| 20 | +class ReadOnlySpan { |
| 21 | + explicit ReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {} |
21 | 22 |
|
22 |
| -// operator std::basic_string_view<CharT, Traits>() = delete; |
23 |
| -// operator std::basic_string_view<CharT, Traits>() const { return std::basic_string_view<CharT, Traits>(cs_); } |
| 23 | +public: |
| 24 | + operator std::span<CharT>() = delete; |
24 | 25 |
|
25 |
| -// private: |
26 |
| -// const CharT* cs_; |
27 |
| -// }; |
| 26 | + operator std::span<const CharT>() { return std::span<const CharT, N>{arr_}; } |
28 | 27 |
|
29 |
| -// static_assert(!std::constructible_from<std::basic_string_view<char>, ConstConvertibleStringView<char>>); |
30 |
| -// static_assert(!std::convertible_to<ConstConvertibleStringView<char>, std::basic_string_view<char>>); |
| 28 | + const CharT* begin() { return arr_; } |
| 29 | + const CharT* end() { return arr_ + N; } |
31 | 30 |
|
32 |
| -// static_assert(std::constructible_from<std::basic_string_view<char>, const ConstConvertibleStringView<char>>); |
33 |
| -// static_assert(std::convertible_to<const ConstConvertibleStringView<char>, std::basic_string_view<char>>); |
| 31 | +private: |
| 32 | + CharT* arr_; |
| 33 | +}; |
34 | 34 |
|
35 |
| -// #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
36 |
| -// static_assert(!std::constructible_from<std::basic_string_view<wchar_t>, ConstConvertibleStringView<wchar_t>>); |
37 |
| -// static_assert(!std::convertible_to<ConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>); |
| 35 | +template <typename CharT, std::size_t N> |
| 36 | +inline constexpr bool std::ranges::enable_borrowed_range<ReadOnlySpan<CharT, N>> = true; |
38 | 37 |
|
39 |
| -// static_assert(std::constructible_from<std::basic_string_view<wchar_t>, const ConstConvertibleStringView<wchar_t>>); |
40 |
| -// static_assert(std::convertible_to<const ConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>); |
41 |
| -// #endif |
| 38 | +static_assert(std::ranges::borrowed_range<ReadOnlySpan<char>>); |
42 | 39 |
|
43 |
| -// template <typename CharT, class Traits = std::char_traits<CharT>> |
44 |
| -// class NonConstConvertibleStringView { |
45 |
| -// public: |
46 |
| -// explicit NonConstConvertibleStringView(const CharT* cs) : cs_{cs} {} |
| 40 | +static_assert(!std::constructible_from<std::span<char>, ReadOnlySpan<char>>); |
| 41 | +static_assert(!std::convertible_to<ReadOnlySpan<char>, std::span<char>>); |
47 | 42 |
|
48 |
| -// operator std::basic_string_view<CharT, Traits>() { return std::basic_string_view<CharT, Traits>(cs_); } |
49 |
| -// operator std::basic_string_view<CharT, Traits>() const = delete; |
| 43 | +static_assert(!std::constructible_from<std::span<char>, const ReadOnlySpan<char>>); |
| 44 | +static_assert(!std::convertible_to<const ReadOnlySpan<char>, std::span<char>>); |
50 | 45 |
|
51 |
| -// private: |
52 |
| -// const CharT* cs_; |
53 |
| -// }; |
| 46 | +static_assert(std::constructible_from<std::span<const char>, ReadOnlySpan<char>>); |
| 47 | +static_assert(std::convertible_to<ReadOnlySpan<char>, std::span<const char>>); |
54 | 48 |
|
55 |
| -// static_assert(std::constructible_from<std::basic_string_view<char>, NonConstConvertibleStringView<char>>); |
56 |
| -// static_assert(std::convertible_to<NonConstConvertibleStringView<char>, std::basic_string_view<char>>); |
| 49 | +static_assert(!std::constructible_from<std::span<const char>, const ReadOnlySpan<char>>); |
| 50 | +static_assert(!std::convertible_to<const ReadOnlySpan<char>, std::span<const char>>); |
57 | 51 |
|
58 |
| -// static_assert(!std::constructible_from<std::basic_string_view<char>, const NonConstConvertibleStringView<char>>); |
59 |
| -// static_assert(!std::convertible_to<const NonConstConvertibleStringView<char>, std::basic_string_view<char>>); |
| 52 | +#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
60 | 53 |
|
61 |
| -// #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
62 |
| -// static_assert(std::constructible_from<std::basic_string_view<wchar_t>, NonConstConvertibleStringView<wchar_t>>); |
63 |
| -// static_assert(std::convertible_to<NonConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>); |
| 54 | +static_assert(std::ranges::borrowed_range<ReadOnlySpan<wchar_t>>); |
64 | 55 |
|
65 |
| -// static_assert(!std::constructible_from<std::basic_string_view<wchar_t>, const NonConstConvertibleStringView<wchar_t>>); |
66 |
| -// static_assert(!std::convertible_to<const NonConstConvertibleStringView<wchar_t>, std::basic_string_view<wchar_t>>); |
67 |
| -// #endif |
| 56 | +static_assert(!std::constructible_from<std::span<wchar_t>, ReadOnlySpan<wchar_t>>); |
| 57 | +static_assert(!std::convertible_to<ReadOnlySpan<wchar_t>, std::span<wchar_t>>); |
| 58 | + |
| 59 | +static_assert(!std::constructible_from<std::span<wchar_t>, const ReadOnlySpan<wchar_t>>); |
| 60 | +static_assert(!std::convertible_to<const ReadOnlySpan<wchar_t>, std::span<wchar_t>>); |
| 61 | + |
| 62 | +static_assert(std::constructible_from<std::span<const wchar_t>, ReadOnlySpan<wchar_t>>); |
| 63 | +static_assert(std::convertible_to<ReadOnlySpan<wchar_t>, std::span<const wchar_t>>); |
| 64 | + |
| 65 | +static_assert(!std::constructible_from<std::span<const wchar_t>, const ReadOnlySpan<wchar_t>>); |
| 66 | +static_assert(!std::convertible_to<const ReadOnlySpan<wchar_t>, std::span<const wchar_t>>); |
| 67 | +#endif |
| 68 | + |
| 69 | +template <typename CharT, std::size_t N = 0> |
| 70 | +class NonReadOnlySpan { |
| 71 | + explicit NonReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {} |
| 72 | + |
| 73 | +public: |
| 74 | + operator std::span<CharT>() { return std::span<CharT, N>{arr_}; } |
| 75 | + |
| 76 | + operator std::span<const CharT>() = delete; |
| 77 | + |
| 78 | + CharT* begin() { return arr_; } |
| 79 | + CharT* end() { return arr_ + N; } |
| 80 | + |
| 81 | +private: |
| 82 | + CharT* arr_; |
| 83 | +}; |
| 84 | + |
| 85 | +template <typename CharT, std::size_t N> |
| 86 | +inline constexpr bool std::ranges::enable_borrowed_range<NonReadOnlySpan<CharT, N>> = true; |
| 87 | + |
| 88 | +static_assert(std::ranges::borrowed_range<NonReadOnlySpan<char>>); |
| 89 | + |
| 90 | +static_assert(std::constructible_from<std::span<char>, NonReadOnlySpan<char>>); |
| 91 | +static_assert(std::convertible_to<NonReadOnlySpan<char>, std::span<char>>); |
| 92 | + |
| 93 | +static_assert(!std::constructible_from<std::span<char>, const NonReadOnlySpan<char>>); |
| 94 | +static_assert(!std::convertible_to<const NonReadOnlySpan<char>, std::span<char>>); |
| 95 | + |
| 96 | +static_assert(std::constructible_from<std::span<const char>, NonReadOnlySpan<char>>); |
| 97 | +static_assert(!std::convertible_to<NonReadOnlySpan<char>, std::span<const char>>); |
| 98 | + |
| 99 | +static_assert(!std::constructible_from<std::span<const char>, const NonReadOnlySpan<char>>); |
| 100 | +static_assert(!std::convertible_to<const NonReadOnlySpan<char>, std::span<const char>>); |
| 101 | + |
| 102 | +#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 103 | +static_assert(std::ranges::borrowed_range<NonReadOnlySpan<wchar_t>>); |
| 104 | + |
| 105 | +static_assert(std::constructible_from<std::span<wchar_t>, NonReadOnlySpan<wchar_t>>); |
| 106 | +static_assert(std::convertible_to<NonReadOnlySpan<wchar_t>, std::span<wchar_t>>); |
| 107 | + |
| 108 | +static_assert(!std::constructible_from<std::span<wchar_t>, const NonReadOnlySpan<wchar_t>>); |
| 109 | +static_assert(!std::convertible_to<const NonReadOnlySpan<wchar_t>, std::span<wchar_t>>); |
| 110 | + |
| 111 | +static_assert(std::constructible_from<std::span<const wchar_t>, NonReadOnlySpan<wchar_t>>); |
| 112 | +static_assert(!std::convertible_to<NonReadOnlySpan<wchar_t>, std::span<const wchar_t>>); |
| 113 | + |
| 114 | +static_assert(!std::constructible_from<std::span<const wchar_t>, const NonReadOnlySpan<wchar_t>>); |
| 115 | +static_assert(!std::convertible_to<const NonReadOnlySpan<wchar_t>, std::span<const wchar_t>>); |
| 116 | +#endif |
| 117 | + |
| 118 | +template <typename CharT, std::size_t N = 0> |
| 119 | +class ConstConvertibleReadOnlySpan { |
| 120 | + explicit ConstConvertibleReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {} |
| 121 | + |
| 122 | +public: |
| 123 | + operator std::span<CharT>() = delete; |
| 124 | + operator std::span<CharT>() const = delete; |
| 125 | + |
| 126 | + operator std::span<const CharT>() = delete; |
| 127 | + operator std::span<const CharT>() const { return std::span<const CharT, N>{arr_}; } |
| 128 | + |
| 129 | + const CharT* begin() { return arr_; } |
| 130 | + const CharT* end() { return arr_ + N; } |
| 131 | + |
| 132 | +private: |
| 133 | + CharT* arr_; |
| 134 | +}; |
| 135 | + |
| 136 | +template <typename CharT, std::size_t N> |
| 137 | +inline constexpr bool std::ranges::enable_borrowed_range<ConstConvertibleReadOnlySpan<CharT, N>> = true; |
| 138 | + |
| 139 | +static_assert(std::ranges::borrowed_range<ConstConvertibleReadOnlySpan<char>>); |
| 140 | + |
| 141 | +static_assert(!std::constructible_from<std::span<char>, ConstConvertibleReadOnlySpan<char>>); |
| 142 | +static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<char>, std::span<char>>); |
| 143 | + |
| 144 | +static_assert(!std::constructible_from<std::span<char>, const ConstConvertibleReadOnlySpan<char>>); |
| 145 | +static_assert(!std::convertible_to<const ConstConvertibleReadOnlySpan<char>, std::span<char>>); |
| 146 | + |
| 147 | +static_assert(std::constructible_from<std::span<const char>, ConstConvertibleReadOnlySpan<char>>); |
| 148 | +static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<char>, std::span<const char>>); |
| 149 | + |
| 150 | +static_assert(std::constructible_from<std::span<const char>, const ConstConvertibleReadOnlySpan<char>>); |
| 151 | +static_assert(std::convertible_to<const ConstConvertibleReadOnlySpan<char>, std::span<const char>>); |
| 152 | + |
| 153 | +#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 154 | + |
| 155 | +static_assert(std::ranges::borrowed_range<ConstConvertibleReadOnlySpan<wchar_t>>); |
| 156 | + |
| 157 | +static_assert(!std::constructible_from<std::span<wchar_t>, ConstConvertibleReadOnlySpan<wchar_t>>); |
| 158 | +static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>); |
| 159 | + |
| 160 | +static_assert(!std::constructible_from<std::span<wchar_t>, const ConstConvertibleReadOnlySpan<wchar_t>>); |
| 161 | +static_assert(!std::convertible_to<const ConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>); |
| 162 | + |
| 163 | +static_assert(std::constructible_from<std::span<const wchar_t>, ConstConvertibleReadOnlySpan<wchar_t>>); |
| 164 | +static_assert(!std::convertible_to<ConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>); |
| 165 | + |
| 166 | +static_assert(std::constructible_from<std::span<const wchar_t>, const ConstConvertibleReadOnlySpan<wchar_t>>); |
| 167 | +static_assert(std::convertible_to<const ConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>); |
| 168 | +#endif |
| 169 | + |
| 170 | +template <typename CharT, std::size_t N = 0> |
| 171 | +class NonConstConvertibleReadOnlySpan { |
| 172 | + explicit NonConstConvertibleReadOnlySpan(CharT (&arr)[N]) : arr_{arr} {} |
| 173 | + |
| 174 | +public: |
| 175 | + operator std::span<CharT>() = delete; |
| 176 | + operator std::span<CharT>() const = delete; |
| 177 | + |
| 178 | + operator std::span<const CharT>() { return std::span<const CharT, N>{arr_}; } |
| 179 | + operator std::span<const CharT>() const = delete; |
| 180 | + |
| 181 | + const CharT* begin() { return arr_; } |
| 182 | + const CharT* end() { return arr_ + N; } |
| 183 | + |
| 184 | +private: |
| 185 | + CharT* arr_; |
| 186 | +}; |
| 187 | + |
| 188 | +template <typename CharT, std::size_t N> |
| 189 | +inline constexpr bool std::ranges::enable_borrowed_range<NonConstConvertibleReadOnlySpan<CharT, N>> = true; |
| 190 | + |
| 191 | +static_assert(std::ranges::borrowed_range<NonConstConvertibleReadOnlySpan<char>>); |
| 192 | + |
| 193 | +static_assert(!std::constructible_from<std::span<char>, NonConstConvertibleReadOnlySpan<char>>); |
| 194 | +static_assert(!std::convertible_to<NonConstConvertibleReadOnlySpan<char>, std::span<char>>); |
| 195 | + |
| 196 | +static_assert(!std::constructible_from<std::span<char>, const NonConstConvertibleReadOnlySpan<char>>); |
| 197 | +static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<char>, std::span<char>>); |
| 198 | + |
| 199 | +static_assert(std::constructible_from<std::span<const char>, NonConstConvertibleReadOnlySpan<char>>); |
| 200 | +static_assert(std::convertible_to<NonConstConvertibleReadOnlySpan<char>, std::span<const char>>); |
| 201 | + |
| 202 | +static_assert(!std::constructible_from<std::span<const char>, const NonConstConvertibleReadOnlySpan<char>>); |
| 203 | +static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<char>, std::span<const char>>); |
| 204 | + |
| 205 | +#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 206 | +static_assert(std::ranges::borrowed_range<NonConstConvertibleReadOnlySpan<wchar_t>>); |
| 207 | + |
| 208 | +static_assert(!std::constructible_from<std::span<wchar_t>, NonConstConvertibleReadOnlySpan<wchar_t>>); |
| 209 | +static_assert(!std::convertible_to<NonConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>); |
| 210 | + |
| 211 | +static_assert(!std::constructible_from<std::span<wchar_t>, const NonConstConvertibleReadOnlySpan<wchar_t>>); |
| 212 | +static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<wchar_t>, std::span<wchar_t>>); |
| 213 | + |
| 214 | +static_assert(std::constructible_from<std::span<const wchar_t>, NonConstConvertibleReadOnlySpan<wchar_t>>); |
| 215 | +static_assert(std::convertible_to<NonConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>); |
| 216 | + |
| 217 | +static_assert(!std::constructible_from<std::span<const wchar_t>, const NonConstConvertibleReadOnlySpan<wchar_t>>); |
| 218 | +static_assert(!std::convertible_to<const NonConstConvertibleReadOnlySpan<wchar_t>, std::span<const wchar_t>>); |
| 219 | +#endif |
68 | 220 |
|
69 | 221 | struct SomeObject {};
|
70 | 222 |
|
|
0 commit comments