42#ifndef _RWSTD_NO_EXPLICIT_INSTANTIATION
79const char*
const fnames[] = {
"replace",
"replace_copy" };
80const char*
const fnames_if[] = {
"replace_if",
"replace_copy_if" };
114 class ConvertibleToBool {
118 operator bool()
const {
return result_; }
139template <
class Iterator,
class T,
class Predicate>
151 static const char*
const fname =
tag.use_predicate ?
155 const std::size_t
nsrc = std::strlen (src);
161 T*
const xsrc = T::from_char (src,
nsrc + 1);
162 T*
const xsrc_end = xsrc +
nsrc;
166 to_replace.data_.val_ =
val;
170 replace_with.data_.val_ = new_val;
181 T::n_total_op_eq_ = 0;
184 if (
tag.use_predicate)
185 std::replace_if (first,
last, pred, replace_with);
187 std::replace (first,
last, to_replace, replace_with);
194 success = to_replace.data_.val_ != xsrc [
i].data_.val_;
199 static const int cwidth =
sizeof (
T);
202 "line %d: %s<%s>(\"%s\", ..., %#c, %#c) ==> "
203 "\"%{X=*.*}\"; unexpected element value %#c",
204 __LINE__, fname, itname, src,
val, new_val,
205 cwidth,
int (
nsrc),
int (
i), xsrc, src [
i]);
213 || (
val == src [
i] && replace_with.origin_ == xsrc [
i].origin_);
220 "line %d: %s<%s>(\"%s\", ..., %#c, %#c) ==> "
221 "\"%{X=#*.*}\"; failed to replace element %zu: "
222 "origin %d (%d, %d), expected %d (%d)",
223 __LINE__, fname, itname, src,
val, new_val,
224 cwidth,
int (
nsrc),
int (
i), xsrc,
225 i, xsrc [
i].origin_, xsrc [
i].id_, xsrc [
i].src_id_,
226 replace_with.origin_, replace_with.id_);
229 if (
tag.use_predicate) {
231 "line %d: %s<%s>(\"%s\", ..., %#c) called "
232 "Predicate::operator() %zu times, %zu expected",
233 __LINE__, fname, itname, src,
val,
238 "line %d: %s<%s>(\"%s\", ..., %#c) called "
239 "T::operator< %zu times, %zu expected",
240 __LINE__, fname, itname, src,
val,
241 T::n_total_op_eq_,
nsrc);
250template <
class Iterator,
class OutputIterator,
class T,
class Predicate>
261 static const char*
const itname =
type_name (it, (
T*)0);
262 static const char*
const fname =
tag.use_predicate ?
265 const std::size_t
nsrc = std::strlen (src);
271 T*
const xsrc = T::from_char (src,
nsrc + 1);
272 T*
const xdst = T::from_char (src,
nsrc + 1);
274 T*
const xsrc_end = xsrc +
nsrc;
275 T*
const xdst_end = xdst +
nsrc;
278 to_replace.data_.val_ =
val;
281 replace_with.data_.val_ = new_val;
291 T::n_total_op_eq_ = 0;
294 ? std::replace_copy_if (first,
last,
result, pred, replace_with)
295 : std::replace_copy (first,
last,
result, to_replace, replace_with);
299 "line %d: %s<%s>(\"%s\", ..., %#c) == result + %zu, got %td",
300 __LINE__, fname, itname, src,
val,
nsrc,
end.cur_ - xdst);
307 typedef unsigned char UChar;
308 success =
UChar (
val) != xdst [
i].data_.val_;
313 static const int cwidth =
sizeof (
T);
316 "line %d: %s<%s>(\"%s\", ..., %#c) ==> "
317 "\"%{X=*.*}\"; unexpected element value %#c",
318 __LINE__, fname, itname, src,
val,
319 cwidth,
int (
nsrc),
int (
i), xdst, src [
i]);
326 || (
val == src [
i] && replace_with.origin_ == xdst [
i].origin_);
333 "line %d: %s<%s>(\"%s\", ..., %#c, %#c) ==> "
334 "\"%{X=*.*}\"; failed to copy and replace element %zu: "
335 "origin %d (%d, %d), expected %d (%d)",
336 __LINE__, fname, itname, src,
val, new_val,
337 cwidth,
int (
nsrc),
int (
i), xdst,
338 i, xdst [
i].origin_, xdst [
i].id_, xdst [
i].src_id_,
339 replace_with.origin_, replace_with.id_);
342 if (
tag.use_predicate) {
344 "line %d: %s<%s>(\"%s\", ..., %#c) called "
345 "Predicate::operator() %zu times, %zu expected",
346 __LINE__, fname, itname, src,
val,
351 "line %d: %s<%s>(\"%s\", ..., %#c) called "
352 "T::operator< %zu times, %zu expected",
353 __LINE__, fname, itname, src,
val,
354 T::n_total_op_eq_,
nsrc);
364template <
class Iterator1,
class Iterator2,
class T,
369 static const char*
const it1name =
type_name (it1, (
T*)0);
370 static const char*
const it2name =
type_name (it2, (
T*)0);
374 "std::%s (%s, %s, %s, %s, const T&)",
375 tag.use_predicate ?
"replace_copy_if" :
"replace_copy",
376 it1name, it1name, it2name,
377 tag.use_predicate ?
"UnaryPredicate" :
"const T&");
381 "std::%s (%s, %s, %s, const T&)",
382 tag.use_predicate ?
"replace_if" :
"replace",
384 tag.use_predicate ?
"UnaryPredicate" :
"const T&");
388#define TEST(src, val, new_val) \
389 test_replace (__LINE__, src, val, new_val, it1, it2, (T*)0, pred, tag)
397 TEST (
"a",
'a',
'b');
398 TEST (
"aa",
'a',
'b');
399 TEST (
"aaa",
'a',
'b');
400 TEST (
"aaaa",
'a',
'b');
401 TEST (
"aaaaa",
'a',
'b');
402 TEST (
"aaaaaa",
'a',
'b');
403 TEST (
"aaaaaaa",
'a',
'b');
404 TEST (
"aaaaaaaa",
'a',
'b');
405 TEST (
"aaaaaaaaa",
'a',
'b');
406 TEST (
"aaaaaaaaaa",
'a',
'b');
408 TEST (
"b",
'a',
'b');
409 TEST (
"bb",
'a',
'b');
410 TEST (
"ba",
'a',
'b');
411 TEST (
"ab",
'a',
'b');
412 TEST (
"abc",
'a',
'b');
413 TEST (
"bac",
'a',
'b');
414 TEST (
"bca",
'a',
'b');
415 TEST (
"aba",
'a',
'b');
416 TEST (
"abab",
'a',
'b');
417 TEST (
"ababa",
'a',
'b');
418 TEST (
"bababa",
'a',
'b');
419 TEST (
"bababab",
'a',
'b');
420 TEST (
"babababa",
'a',
'b');
421 TEST (
"bbbbbbbbb",
'a',
'b');
436template <
class T,
class Predicate,
class Tag>
440 "template <class ForwardIterator, class T> "
441 "std::%s (ForwardIterator, ForwardIterator, "
443 tag.use_predicate ?
"replace_if" :
"replace",
444 tag.use_predicate ?
"Predicate" :
"const T&");
447 rw_note (0, __FILE__, __LINE__,
"ForwardIterator test disabled");
454 rw_note (0, __FILE__, __LINE__,
"BidirectionalIterator test disabled");
461 rw_note (0, __FILE__, __LINE__,
"RandomAccessIterator test disabled");
477 rw_note (0, __FILE__, __LINE__,
"std::replace test disabled");
485 rw_note (0, __FILE__, __LINE__,
"std::replace_if test disabled");
495template <
class InputIterator,
class T,
class Predicate,
class Tag>
500 rw_note (0, __FILE__, __LINE__,
"OutputIterator test disabled");
507 rw_note (0, __FILE__, __LINE__,
"ForwardIterator test disabled");
514 rw_note (0, __FILE__, __LINE__,
"BidirectionalIterator test disabled");
521 rw_note (0, __FILE__, __LINE__,
"RandomAccessIterator test disabled");
530template <
class T,
class Predicate,
class Tag>
535 "<class InputIterator, class OutputIterator, class T> "
536 "std::%s (InputIterator, InputIterator, "
537 "OutputIterator, %s, const T&)",
538 tag.use_predicate ?
"replace_copy_if" :
"replace_copy",
539 tag.use_predicate ?
"Predicate" :
"const T&");
542 rw_note (0, __FILE__, __LINE__,
"InputIterator test disabled");
549 rw_note (0, __FILE__, __LINE__,
"ForwardIterator test disabled");
556 rw_note (0, __FILE__, __LINE__,
"BidirectionalIterator test disabled");
563 rw_note (0, __FILE__, __LINE__,
"RandomAccessIterator test disabled");
579 rw_note (0, __FILE__, __LINE__,
"std::replace_copy test disabled");
587 rw_note (0, __FILE__, __LINE__,
"std::replace_copy_if test disabled");
609int main (
int argc,
char *argv[])
611 return rw_test (argc, argv, __FILE__,
617 "|-no-replace_copy# "
618 "|-no-replace_copy_if# "
619 "|-no-InputIterator# "
620 "|-no-OutputIterator# "
621 "|-no-ForwardIterator# "
622 "|-no-BidirectionalIterator# "
623 "|-no-RandomAccessIterator#",
const MyBuffer< char > nsrc[]
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
void test_replace(int line, const char *src, char val, char new_val, Iterator dummy, NoIterator, const T *, const Predicate *, ReplaceTag tag)
const char *const fnames[]
const char *const fnames_if[]
int rw_opt_no_replace_copy_if
void test_replace_copy(const InputIterator &iter, const T *, const Predicate *pred, Tag tag)
int rw_opt_no_output_iter
int rw_opt_no_replace_copy
#define TEST(src, val, new_val)
#define _RWSTD_NAMESPACE(name)
ConvertibleToBool(bool res)
T * make_iter(T *cur, const T *, const T *, T *)
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
ConvertibleToBool operator()(const T &x, const U &y)
EqualityPredicate(const T &val, int)
static std::size_t funcalls_
static std::size_t funcalls_