@@ -81,6 +81,44 @@ constexpr bool test() {
81
81
82
82
static_assert (!BeginInvocable<const ForwardView>);
83
83
84
+ {
85
+ // non-common non-simple view,
86
+ // The wording of the standard is:
87
+ // Returns: ranges::next(ranges::begin(base_), count_, ranges::end(base_))
88
+ // Note that "Returns" is used here, meaning that we don't have to do it this way.
89
+ // In fact, this will use ranges::advance that has O(n) on non-common range.
90
+ // but [range.range] requires "amortized constant time" for ranges::begin and ranges::end
91
+ // Here, we test that begin() is indeed constant time, by creating a customized
92
+ // sentinel and counting how many times the sentinel eq function is called.
93
+ // It should be 0 times, but since this test (or any test under libcxx/test/std) is
94
+ // also used by other implementations, we relax the condition to that
95
+ // sentinel_cmp_calls is a constant number.
96
+ int sentinel_cmp_calls_1 = 0 ;
97
+ int sentinel_cmp_calls_2 = 0 ;
98
+ using NonCommonView = MaybeSimpleNonCommonView<false >;
99
+ static_assert (std::ranges::random_access_range<NonCommonView>);
100
+ static_assert (std::ranges::sized_range<NonCommonView>);
101
+ std::ranges::drop_view dropView9_1 (NonCommonView{{}, 0 , &sentinel_cmp_calls_1}, 4 );
102
+ std::ranges::drop_view dropView9_2 (NonCommonView{{}, 0 , &sentinel_cmp_calls_2}, 6 );
103
+ assert (dropView9_1.begin () == globalBuff + 4 );
104
+ assert (dropView9_2.begin () == globalBuff + 6 );
105
+ assert (sentinel_cmp_calls_1 == sentinel_cmp_calls_2);
106
+ }
107
+
108
+ {
109
+ // non-common simple view, same as above.
110
+ int sentinel_cmp_calls_1 = 0 ;
111
+ int sentinel_cmp_calls_2 = 0 ;
112
+ using NonCommonView = MaybeSimpleNonCommonView<true >;
113
+ static_assert (std::ranges::random_access_range<NonCommonView>);
114
+ static_assert (std::ranges::sized_range<NonCommonView>);
115
+ std::ranges::drop_view dropView10_1 (NonCommonView{{}, 0 , &sentinel_cmp_calls_1}, 4 );
116
+ std::ranges::drop_view dropView10_2 (NonCommonView{{}, 0 , &sentinel_cmp_calls_2}, 6 );
117
+ assert (dropView10_1.begin () == globalBuff + 4 );
118
+ assert (dropView10_2.begin () == globalBuff + 6 );
119
+ assert (sentinel_cmp_calls_1 == sentinel_cmp_calls_2);
120
+ }
121
+
84
122
{
85
123
static_assert (std::ranges::random_access_range<const SimpleView>);
86
124
static_assert (std::ranges::sized_range<const SimpleView>);
0 commit comments