41#ifndef _RWSTD_NO_EXPLICIT_INSTANTIATION
71 static const char*
name () {
return "unary_function"; }
99 static const char*
name () {
return "binary_function"; }
112 x.data_.val_ =
a.data_.val_ +
b.data_.val_;
135template <
class InputIterator,
class Unused,
class OutputIterator>
141 return std::transform (first,
last, dest,
fun);
144template <
class InputIterator1,
class InputIterator2,
class OutputIterator>
147 InputIterator2 first2,
150 return std::transform (first1, last1, first2, dest,
fun);
154template <
class T,
class InputIterator1,
class InputIterator2,
157 const InputIterator1 &it1,
158 const InputIterator2 &it2,
163 static const char*
const it1name =
type_name (it1,
ptr);
164 static const char*
const it2name =
type_name (it2,
ptr);
166 static const char*
const algname =
"transform";
167 static const char*
const funname = Function::name ();
168 static const bool binary = Function::binary;
173 "std::%s (%s, %2$s%{?}, %s%{;}, %s, %s)%{?}, %s%d == %s%{;}",
174 algname, it1name, binary, it2name, outname, funname,
175 same_seq,
"first", same_seq,
"dest");
181 T*
const buf1 =
new T [nloops + 1];
182 T*
const buf2 =
new T [nloops + 1];
183 T*
const buf3 = same_seq ? (same_seq == 1 ? buf1 : buf2) :
new T [nloops];
185 const int start1_val =
186 same_seq == 2 ? buf2 [0].data_.val_ : buf1 [0].data_.val_;
187 const int start2_val =
188 same_seq == 2 ? buf1 [0].data_.val_ : buf2 [0].data_.val_;
190 for (std::size_t
i = 0;
i < nloops; ++
i) {
192 T*
const buf1_end = buf1 +
i;
193 const T*
const buf2_end = buf2 +
i;
194 const T*
const buf3_end = buf3 +
i;
196 const InputIterator1 first1 =
make_iter (buf1, buf1, buf1_end, it1);
197 const InputIterator1 last1 =
make_iter (buf1_end, buf1, buf1_end, it1);
198 const InputIterator2 first2 =
make_iter (buf2, buf2, buf2_end, it2);
209 bool success =
result.cur_ == buf3_end;
211 "%zu. %s (%s, %2$s%{?}, %s%{;}, %s, %s)%{?}, "
212 "%s%d == %s%{;} : return val: "
213 "dest + %td, expected dest + %zu",
214 i, algname, it1name, binary, it2name, outname, funname,
215 same_seq,
"first", same_seq,
"dest",
224 for ( ;
j <
i;
j++) {
227 start1_val + int (
j) + start2_val + int (
j)
228 : start1_val + int (
j) + 1;
233 + (start2_val + int (
j)) *
int (
i -
j)
234 : start1_val + int (
i);
237 success = buf3 [
j].data_.val_ == exp_val;
243 "%zu. %s (%s, %2$s%{?}, %s%{;}, %s, %s)%{?}, "
244 "%s%d == %s%{;} : error: incorrect value %d, "
245 "expected %d, position %zu",
246 i, algname, it1name, binary, it2name, outname, funname,
247 same_seq,
"first", same_seq,
"dest",
248 buf3 [
j].data_.val_, exp_val,
j + 1);
254 rw_assert (Function::funcalls_ ==
i, 0, __LINE__,
255 "%zu. %s (%s, %2$s%{?}, %s%{;}, %s, %s)%{?}, "
256 "%s%d == %s%{;} : complexity : %zu "
257 "applications of %5$s, expected %zu",
258 i, algname, it1name, binary, it2name, outname, funname,
259 same_seq,
"first", same_seq,
"dest",
260 Function::funcalls_,
i);
272template <
class T,
class InputIterator1,
class InputIterator2,
275 const InputIterator1 &it1,
276 const InputIterator2 &it2,
303 if (1 == tag1 || (0 == tag1 && 1 == tag2))
304 rw_note (0, __FILE__, __LINE__,
"InputIterator test disabled");
309 pfun, 0, tag2, tag3, same_seq);
311 else if (0 == tag1 && 1 == tag2) {
313 pfun, tag1, 0, tag3, same_seq);
319 if (tag1 || (!tag1 && tag2) || (!tag1 && !tag2 && tag3))
320 rw_note (0, __FILE__, __LINE__,
"ForwardIterator test disabled");
325 pfun, 0, tag2, tag3, same_seq);
327 else if (2 == tag1) {
329 pfun, 0, tag2, 0, same_seq);
331 else if (0 == tag1 && 1 == tag2) {
333 pfun, tag1, 0, tag3, same_seq);
335 else if (0 == tag1 && 2 == tag2) {
337 pfun, tag1, 0, 0, same_seq);
339 else if (0 == tag1 && 0 == tag2 && 1 == tag3) {
341 pfun, tag1, tag2, 0, same_seq);
347 if (tag1 || (!tag1 && tag2) || (!tag1 && !tag2 && tag3))
348 rw_note (0, __FILE__, __LINE__,
349 "BidirectionalIterator test disabled");
354 pfun, 0, tag2, tag3, same_seq);
356 else if (2 == tag1) {
358 pfun, 0, tag2, 0, same_seq);
360 else if (0 == tag1 && 1 == tag2) {
362 pfun, tag1, 0, tag3, same_seq);
364 else if (0 == tag1 && 2 == tag2) {
366 pfun, tag1, 0, 0, same_seq);
368 else if (0 == tag1 && 0 == tag2 && 1 == tag3) {
370 pfun, tag1, tag2, 0, same_seq);
376 if (tag1 || (!tag1 && tag2) || (!tag1 && !tag2 && tag3))
377 rw_note (0, __FILE__, __LINE__,
378 "RandomAccessIterator test disabled");
383 pfun, 0, tag2, tag3, same_seq);
385 else if (2 == tag1) {
387 pfun, 0, tag2, 0, same_seq);
389 else if (0 == tag1 && 1 == tag2) {
391 pfun, tag1, 0, tag3, same_seq);
393 else if (0 == tag1 && 2 == tag2) {
395 pfun, tag1, 0, 0, same_seq);
397 else if (0 == tag1 && 0 == tag2 && 1 == tag3) {
399 pfun, tag1, tag2, 0, same_seq);
405 if (0 == tag1 && 0 == tag2 && 1 == tag3)
406 rw_note (0, __FILE__, __LINE__,
"OutputIterator test disabled");
409 if (0 == tag1 && 0 == tag2 && 1 == tag3) {
411 pfun, tag1, tag2, 0, same_seq);
415 if (0 == tag1 && 0 == tag2 && 0 == tag3) {
433 rw_note (0, __FILE__, __LINE__,
434 "std::transform unary function test disabled");
453 rw_note (0, __FILE__, __LINE__,
454 "std::transform binary function test disabled");
483int main (
int argc,
char *argv[])
485 return rw_test (argc, argv, __FILE__,
489 "|-no-unary_function# "
490 "|-no-binary_function# "
491 "|-no-InputIterator# "
492 "|-no-OutputIterator# "
493 "|-no-ForwardIterator# "
494 "|-no-BidirectionalIterator# "
495 "|-no-RandomAccessIterator",
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define _RWSTD_NAMESPACE(name)
_TEST_EXPORT int gen_seq()
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 *,...)
static std::size_t funcalls_
static const char * name()
static std::size_t funcalls_
static const char * name()
T operator()(const T &a, const T &b)