@@ -66,39 +66,77 @@ struct holder {
6666 }
6767};
6868
69- template <class R >
70- void not_ranges_destroy (R&& r) { // TRANSITION, ranges::destroy
71- for (auto & e : r) {
72- destroy_at (&e);
73- }
74- }
75-
7669struct instantiator {
77- static constexpr int expected_output[] = {13 , 55 , 12345 };
78- static constexpr int expected_input[] = {13 , 55 , 12345 };
70+ static constexpr int expected_output[] = {13 , 55 , 12345 };
71+ static constexpr int expected_output_long[] = {13 , 55 , 12345 , -1 };
72+ static constexpr int expected_input[] = {13 , 55 , 12345 };
73+ static constexpr int expected_input_long[] = {13 , 55 , 12345 , 42 };
7974
8075 template <ranges::input_range Read, ranges::forward_range Write>
8176 static void call () {
82- using ranges::uninitialized_copy_n, ranges::uninitialized_copy_n_result, ranges::equal, ranges::equal_to,
83- ranges::iterator_t ;
77+ using ranges::destroy, ranges::uninitialized_copy_n, ranges::uninitialized_copy_n_result, ranges::equal,
78+ ranges::equal_to, ranges::iterator_t ;
79+
80+ { // Validate equal ranges
81+ int_wrapper input[3 ] = {13 , 55 , 12345 };
82+ Read wrapped_input{input};
83+ holder<int_wrapper, 3 > mem;
84+ Write wrapped_output{mem.as_span ()};
85+
86+ int_wrapper::clear_counts ();
87+ const same_as<uninitialized_copy_n_result<iterator_t <Read>, iterator_t <Write>>> auto result =
88+ uninitialized_copy_n (wrapped_input.begin (), 3 , wrapped_output.begin (), wrapped_output.end ());
89+ assert (int_wrapper::constructions == 3 );
90+ assert (int_wrapper::destructions == 0 );
91+ assert (result.in == wrapped_input.end ());
92+ assert (result.out == wrapped_output.end ());
93+ assert (equal (wrapped_output, expected_output, equal_to{}, &int_wrapper::val));
94+ assert (equal (input, expected_input, equal_to{}, &int_wrapper::val));
95+ destroy (wrapped_output);
96+ assert (int_wrapper::constructions == 3 );
97+ assert (int_wrapper::destructions == 3 );
98+ }
8499
85- int_wrapper input[3 ] = {13 , 55 , 12345 };
86- Read wrapped_input{input};
87- holder<int_wrapper, 3 > mem;
88- Write wrapped_output{mem.as_span ()};
100+ { // Validate shorter output
101+ int_wrapper input[4 ] = {13 , 55 , 12345 , 42 };
102+ Read wrapped_input{input};
103+ holder<int_wrapper, 3 > mem;
104+ Write wrapped_output{mem.as_span ()};
105+
106+ int_wrapper::clear_counts ();
107+ same_as<uninitialized_copy_n_result<iterator_t <Read>, iterator_t <Write>>> auto result =
108+ uninitialized_copy_n (wrapped_input.begin (), 3 , wrapped_output.begin (), wrapped_output.end ());
109+ assert (int_wrapper::constructions == 3 );
110+ assert (int_wrapper::destructions == 0 );
111+ assert (++result.in == wrapped_input.end ());
112+ assert (result.out == wrapped_output.end ());
113+ assert (equal (wrapped_output, expected_output, equal_to{}, &int_wrapper::val));
114+ assert (equal (input, expected_input_long, equal_to{}, &int_wrapper::val));
115+ destroy (wrapped_output);
116+ assert (int_wrapper::constructions == 3 );
117+ assert (int_wrapper::destructions == 3 );
118+ }
89119
90- int_wrapper::clear_counts ();
91- const same_as<uninitialized_copy_n_result<iterator_t <Read>, iterator_t <Write>>> auto result =
92- uninitialized_copy_n (wrapped_input.begin (), 3 , wrapped_output.begin (), wrapped_output.end ());
93- assert (int_wrapper::constructions == 3 );
94- assert (int_wrapper::destructions == 0 );
95- assert (result.in == wrapped_input.end ());
96- assert (result.out == wrapped_output.end ());
97- assert (equal (wrapped_output, expected_output, equal_to{}, &int_wrapper::val));
98- assert (equal (input, expected_input, equal_to{}, &int_wrapper::val));
99- not_ranges_destroy (wrapped_output);
100- assert (int_wrapper::constructions == 3 );
101- assert (int_wrapper::destructions == 3 );
120+ { // Validate shorter input
121+ int_wrapper input[3 ] = {13 , 55 , 12345 };
122+ Read wrapped_input{input};
123+ holder<int_wrapper, 4 > mem;
124+ Write wrapped_output{mem.as_span ()};
125+
126+ int_wrapper::clear_counts ();
127+ same_as<uninitialized_copy_n_result<iterator_t <Read>, iterator_t <Write>>> auto result =
128+ uninitialized_copy_n (wrapped_input.begin (), 3 , wrapped_output.begin (), wrapped_output.end ());
129+ assert (int_wrapper::constructions == 3 );
130+ assert (int_wrapper::destructions == 0 );
131+ assert (result.in == wrapped_input.end ());
132+ construct_at (addressof (*result.out ), -1 ); // Need to construct non written element for comparison
133+ assert (++result.out == wrapped_output.end ());
134+ assert (equal (wrapped_output, expected_output_long, equal_to{}, &int_wrapper::val));
135+ assert (equal (input, expected_input, equal_to{}, &int_wrapper::val));
136+ destroy (wrapped_output);
137+ assert (int_wrapper::constructions == 4 );
138+ assert (int_wrapper::destructions == 4 );
139+ }
102140 }
103141};
104142
@@ -127,17 +165,39 @@ struct throwing_test {
127165};
128166
129167struct memcopy_test {
130- static constexpr int expected_output[] = {13 , 55 , 12345 , -1 };
131- static constexpr int expected_input[] = {13 , 55 , 12345 , 42 };
168+ static constexpr int expected_output[] = {13 , 55 , 12345 , -1 };
169+ static constexpr int expected_output_long[] = {13 , 55 , -1 , -1 };
170+ static constexpr int expected_input[] = {13 , 55 , 12345 , 42 };
171+ static constexpr int expected_input_short[] = {13 , 55 };
172+ static constexpr int expected_input_long[] = {13 , 55 , 12345 , 42 };
132173
133174 static void call () {
134- // Validate only range overload (one is plenty since they both use the same backend)
135- int input[] = {13 , 55 , 12345 , 42 };
136- int output[] = {-1 , -1 , -1 , -1 };
175+ { // Validate range overload
176+ int input[] = {13 , 55 , 12345 , 42 };
177+ int output[] = {-1 , -1 , -1 , -1 };
178+
179+ ranges::uninitialized_copy_n (input, 3 , begin (output), end (output));
180+ assert (ranges::equal (input, expected_input));
181+ assert (ranges::equal (output, expected_output));
182+ }
183+
184+ { // Validate shorter input
185+ int input[] = {13 , 55 };
186+ int output[] = {-1 , -1 , -1 , -1 };
137187
138- ranges::uninitialized_copy_n (input, 3 , output, output + 4 );
139- assert (ranges::equal (input, expected_input));
140- assert (ranges::equal (output, expected_output));
188+ ranges::uninitialized_copy_n (input, 2 , begin (output), end (output));
189+ assert (ranges::equal (input, expected_input_short));
190+ assert (ranges::equal (output, expected_output_long));
191+ }
192+
193+ { // Validate shorter output
194+ int input[] = {13 , 55 , 12345 , 42 };
195+ int output[] = {-1 , -1 };
196+
197+ ranges::uninitialized_copy_n (input, 3 , begin (output), end (output));
198+ assert (ranges::equal (input, expected_input));
199+ assert (ranges::equal (output, expected_input_short));
200+ }
141201 }
142202};
143203
0 commit comments