blob: a1d5d6baee19c39497484c2335928045b53c046b (
plain)
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
|
// { dg-do compile { target c++26 } }
// { dg-add-options no_pch }
#include <text_encoding>
#ifndef __cpp_lib_text_encoding
# error "Feature-test macro for text_encoding missing in <text_encoding>"
#elif __cpp_lib_text_encoding != 202306L
# error "Feature-test macro for text_encoding has wrong value in <text_encoding>"
#endif
#undef __cpp_lib_expected
#include <version>
#ifndef __cpp_lib_text_encoding
# error "Feature-test macro for text_encoding missing in <version>"
#elif __cpp_lib_text_encoding != 202306L
# error "Feature-test macro for text_encoding has wrong value in <version>"
#endif
#include <concepts>
#include <ranges>
static_assert( std::is_trivially_copyable_v<std::text_encoding> );
using aliases_view = std::text_encoding::aliases_view;
static_assert( std::copyable<aliases_view> );
static_assert( std::ranges::view<aliases_view> );
static_assert( std::ranges::random_access_range<aliases_view> );
static_assert( std::ranges::borrowed_range<aliases_view> );
static_assert( std::same_as<std::ranges::range_value_t<aliases_view>,
const char*> );
static_assert( std::same_as<std::ranges::range_reference_t<aliases_view>,
const char*> );
#include <testsuite_hooks.h>
constexpr bool
test_constexpr_iterator()
{
// This encoding has two aliases, "UTF-8" and "csUTF8".
const auto a = std::text_encoding(std::text_encoding::UTF8).aliases();
const auto begin = a.begin();
const auto end = a.end();
auto iter = begin;
VERIFY( *iter == *begin );
VERIFY( *iter == iter[0] );
VERIFY( iter[1] == begin[1] );
--++iter;
VERIFY( iter == begin );
auto iter2 = iter++;
VERIFY( iter2 == begin );
VERIFY( iter != begin );
iter2 = iter--;
VERIFY( iter2 != begin );
VERIFY( iter == begin );
iter++++; // Increments prvalue returned by operator++(int) instead of iter.
VERIFY( iter == iter2 );
iter----; // Decrements prvalue returned by operator++(int) instead of iter.
VERIFY( iter == begin );
const auto d = std::ranges::distance(a);
iter += d;
VERIFY( iter == end );
VERIFY( (iter - begin) == d );
VERIFY( (begin + 2) == iter );
VERIFY( (2 + begin) == iter );
VERIFY( iter[-1] == begin[1] );
iter -= d;
VERIFY( iter == begin );
VERIFY( *(iter + 1) == iter[1] );
VERIFY( (1 + iter - 1) == begin );
VERIFY( (-1 + (iter - -2) + -1) == begin );
std::ranges::iterator_t<std::text_encoding::aliases_view> singular{};
VERIFY( (singular + 0) == singular );
VERIFY( (singular - 0) == singular );
return true;
}
static_assert( test_constexpr_iterator() );
|