Second attempt - I switched to Mozilla mailer.
The attached file contains the test for the lib.alg.mismatch algorithm.
With best wishes,
Anton Pevtsov
-----Original Message-----
From: Martin Sebor [mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 23, 2005 23:16
To: [email protected]
Subject: Re: test for lib.alg.mismatch
Anton Pevtsov wrote:
The attached file contains my attempt to update the lib.alg.mismatch
test.
The attachment is missing (it probably got stripped due to the mailer
issue I mentioned previously). Here are some ways in which we can try to
deal with it, listed in the order of my preference :)
1. use a different mailer, one that doesn't cause attachments to
be stripped (Netscape, Mozilla, or Thunderbird are known to work)
2. paste the contents of the file directly into the body of the email
(make sure your mailer doesn't mangle the text or break up long
lines)
3. make the file available on the Internet and post a link to it
4. uuencode the file and insert the output directly into the text
of your email (the advantage of this over (3) is that there
will be permanent record of the first version of the test).
[...]
The question is: what mechanism should I use to check that the
iterator reachs the end of the sequence? Will it be correct to compare
the iterator cur_ field value with the pointer to the corresponding
test array element? If so, the attached test may be updated.
I think so. Every test iterator template should have this member.
Martin
/***************************************************************************
*
* mismatch.cpp - test exercising 25.1.7 [lib.mismatch]
*
* $Id: //stdlib/dev/tests/stdlib/algorithm/mismatch.cpp#19 $
*
***************************************************************************
*
* Copyright (c) 1994-2005 Quovadx, Inc. All Rights Reserved.
*
* This computer software is owned by Quovadx, Inc. and is protected by
* U.S. copyright laws and other laws and by international treaties.
* This computer software is furnished by Quovadx, Inc., pursuant to a
* written license agreement and may be used, copied, transmitted, and
* stored only in accordance with the terms of such license agreement and
* with the inclusion of the above copyright notice. This computer
* software or any other copies thereof may not be provided or otherwise
* made available to any other person.
*
*
* U.S. Government Restricted Rights.
*
* This computer software: (a) was developed at private expense and is in
* all respects the proprietary information of Quovadx, Inc.; (b) was not
* developed with government funds; (c) is a trade secret of Quovadx,
* Inc. for all purposes of the Freedom of Information Act; and (d) is a
* commercial item and thus, pursuant to Section 12.212 of the Federal
* Acquisition Regulations (FAR) and DFAR Supplement Section 227.7202,
* Government's use, duplication or disclosure of the computer software
* is subject to the restrictions set forth by Quovadx, Inc.
*
**************************************************************************/
#include <algorithm> // for mismatch
#include <functional> // for equal_to
#include <cstddef> // for size_t
#include <alg_test.h>
#include <driver.h> // for rw_test()...
/**************************************************************************/
_RWSTD_NAMESPACE (std) {
// disable explicit instantiation for compilers (like MSVC)
// that can't handle it
#ifndef _RWSTD_NO_EXPLICIT_INSTANTIATION
template
pair<InputIter<eq_comp<base<> > >,
InputIter<eq_comp<base<> > > >
mismatch (InputIter<eq_comp<base<> > >,
InputIter<eq_comp<base<> > >,
InputIter<eq_comp<base<> > >);
template
pair<InputIter<eq_comp<base<> > >,
InputIter<eq_comp<base<> > > >
mismatch (InputIter<eq_comp<base<> > >,
InputIter<eq_comp<base<> > >,
InputIter<eq_comp<base<> > >,
binary_predicate<eq_comp<base<> > >);
#endif // _RWSTD_NO_EXPLICIT_INSTANTIATION
} // namespace std
// exercises std::mismatch()
template <class InputIterator1, class InputIterator2, class T>
void test_mismatch (std::size_t N,
const InputIterator1 &it1_dummy,
const InputIterator2 &it2_dummy,
T*,
const char *predicate)
{
static const char* const it1name = type_name (it1_dummy, (T*)0);
static const char* const it2name = type_name (it2_dummy, (T*)0);
rw_info (0, 0, 0, "std::mismatch (%s, %1$s, %s%{?}, %s%{;})",
it1name, it2name, 0 != predicate, predicate);
// generate sequential values for each default constructed X
// for both lists
X::gen_ = gen_seq_2lists;
// use ::operator new() to prevent default initialization
X *buf1 = _RWSTD_STATIC_CAST (X*, ::operator new (N * sizeof (X)));
X *buf2 = _RWSTD_STATIC_CAST (X*, ::operator new (N * sizeof (X)));
const std::size_t mid_inx = N / 2;
for (std::size_t i = 0; i != N; ++i) {
// default-construct a new X at the end of the array
new (buf1 + i) X ();
// build a nearly identical list only missing N/2 (the N/2th
// element) from it's list
if (i != mid_inx)
new (buf2 + i) X ();
}
new (buf2 + mid_inx) X ();
for (std::size_t i = 0; i != N; ++i) {
// exercise 25.1.7 - std::mismatch<>()
std::size_t last_n_op_eq = X::n_total_op_eq_;
X* const buf1_end = buf1 + i + 1;
X* const buf2_end = buf2 + i + 1;
const InputIterator1 first1 =
make_iter (buf1, buf1, buf1_end, it1_dummy);
const InputIterator1 last1 =
make_iter (buf1_end, buf1_end, buf1_end, it1_dummy);
const InputIterator2 first2 =
make_iter (buf2, buf2, buf2_end, it2_dummy);
// use dummies to prevent default iterator constructor call
std::pair<InputIterator1, InputIterator2> mismatch_result_ (
it1_dummy, it2_dummy);
if (predicate) {
mismatch_result_ =
std::mismatch (first1, last1, first2, std::equal_to<X>());
}
else {
mismatch_result_ =
std::mismatch (first1, last1, first2);
}
// verify 25.1.7, p2
X* const expected_buf1_end_ =
(i < mid_inx) ? buf1_end : buf1 + mid_inx;
X* const expected_buf2_end_ =
(i < mid_inx) ? buf2_end : buf2 + mid_inx;
X* const res_buf1_end_ =
buf1 + (mismatch_result_.first.cur_ - first1.cur_);
X* const res_buf2_end_ =
buf2 + (mismatch_result_.second.cur_ - first2.cur_);
// check that the returned iterators are valid
bool success =
buf1 <= res_buf1_end_ && res_buf1_end_ <= buf1_end &&
buf2 <= res_buf2_end_ && res_buf2_end_ <= buf2_end;
if (! success)
{
rw_assert (success, 0, __LINE__,
"%zu. std::mismatch<> () iterator out of range "
"offset is %d, expected must be less than %d, "
"offset is %d, expected must be less than %d", i + 1,
res_buf1_end_ - buf1, buf1_end - buf1,
res_buf2_end_ - buf2, buf2_end - buf2);
}
else
{
// iterators are valid check that the algorithm works correctly
success =
res_buf1_end_->val_ == expected_buf1_end_->val_ &&
res_buf2_end_->val_ == expected_buf2_end_->val_;
rw_assert (success, 0, __LINE__,
"%zu. std::mismatch<> () correctness: got: %d "
"expected: %d, got: %d expected: %d", i + 1,
res_buf1_end_->val_, expected_buf1_end_->val_,
res_buf2_end_->val_, expected_buf2_end_->val_);
}
// verify 25.1.7, p3
success = X::n_total_op_eq_ - last_n_op_eq <= (N + 1);
rw_assert (success, 0, __LINE__,
"%zu. std::mismatch<> () complexity: %zu <= %zu",
i + 1, X::n_total_op_eq_, i + 1);
if (!success)
break;
}
::operator delete (buf1);
::operator delete (buf2);
}
/**************************************************************************/
/* extern */ int rw_opt_no_input_iter; // --no-InputIterator
/* extern */ int rw_opt_no_fwd_iter; // --no-ForwardIterator
/* extern */ int rw_opt_no_bidir_iter; // --no-BidirectionalIterator
/* extern */ int rw_opt_no_rnd_iter; // --no-RandomAccessIterator
/* extern */ int rw_opt_no_predicate; // --no-Predicate
template <class InputIterator, class T>
void test_mismatch (const InputIterator &dummy, T*, const char *predicate)
{
static const std::size_t N = 1024;
if (rw_opt_no_input_iter) {
rw_note (0, __FILE__, __LINE__, "InputIterator test disabled");
}
else {
test_mismatch (N, dummy, InputIter<X>((X*)0, (X*)0, (X*)0), (X*)0,
predicate);
}
if (rw_opt_no_fwd_iter) {
rw_note (0, __FILE__, __LINE__, "ForwardIterator test disabled");
}
else {
test_mismatch (N, dummy, FwdIter<X>(), (X*)0, predicate);
}
if (rw_opt_no_bidir_iter) {
rw_note (0, __FILE__, __LINE__,
"BidirectionalIterator test disabled");
}
else {
test_mismatch (N, dummy, BidirIter<X>(), (X*)0, predicate);
}
if (rw_opt_no_rnd_iter) {
rw_note (0, __FILE__, __LINE__,
"RandomAccessIterator test disabled");
}
else {
test_mismatch (N, dummy, RandomAccessIter<X>(), (X*)0, predicate);
}
}
/**************************************************************************/
static void
test_mismatch (const char *predicate)
{
rw_info (0, 0, 0,
"template <class %s, class %s> "
"pair <%s, %s> "
"std::mismatch (%1$s, %1$s, %2$s%{?}, %s%{;})",
"InputIterator1", "InputIterator2",
"InputIterator1", "InputIterator2",
0 != predicate, predicate);
if (rw_opt_no_input_iter) {
rw_note (0, __FILE__, __LINE__, "InputIterator test disabled");
}
else {
test_mismatch (InputIter<X>((X*)0, (X*)0, (X*)0), (X*)0, predicate);
}
if (rw_opt_no_fwd_iter) {
rw_note (0, __FILE__, __LINE__, "ForwardIterator test disabled");
}
else {
test_mismatch (FwdIter<X>(), (X*)0, predicate);
}
if (rw_opt_no_bidir_iter) {
rw_note (0, __FILE__, __LINE__,
"BidirectionalIterator test disabled");
}
else {
test_mismatch (BidirIter<X>(), (X*)0, predicate);
}
if (rw_opt_no_rnd_iter) {
rw_note (0, __FILE__, __LINE__,
"RandomAccessIterator test disabled");
}
else {
test_mismatch (RandomAccessIter<X>(), (X*)0, predicate);
}
}
static int
run_test (int, char*[])
{
test_mismatch (0);
if (rw_opt_no_predicate) {
rw_note (0, __FILE__, __LINE__, "Predicate test disabled");
}
else {
test_mismatch ("std::equal_to<X>");
}
return 0;
}
/**************************************************************************/
int main (int argc, char *argv[])
{
return rw_test (argc, argv, __FILE__,
"lib.alg.mismatch",
0 /* no comment */, run_test,
"|-no-InputIterator#"
"|-no-ForwardIterator#"
"|-no-BidirectionalIterator#"
"|-no-RandomAccessIterator#"
"|-no-Predicate",
&rw_opt_no_input_iter,
&rw_opt_no_fwd_iter,
&rw_opt_no_bidir_iter,
&rw_opt_no_rnd_iter,
&rw_opt_no_predicate);
}