Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 49555 invoked from network); 29 Nov 2005 16:23:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 29 Nov 2005 16:23:38 -0000 Received: (qmail 85882 invoked by uid 500); 29 Nov 2005 16:23:38 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 85864 invoked by uid 500); 29 Nov 2005 16:23:37 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 85853 invoked by uid 99); 29 Nov 2005 16:23:37 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Nov 2005 08:23:37 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of AntonP@moscow.vdiweb.com designates 195.210.189.132 as permitted sender) Received: from [195.210.189.132] (HELO exmsk.moscow.vdiweb.com) (195.210.189.132) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Nov 2005 08:25:07 -0800 Received: from [10.11.0.166] ([10.11.0.166]) by exmsk.moscow.vdiweb.com with Microsoft SMTPSVC(6.0.3790.211); Tue, 29 Nov 2005 19:23:06 +0300 Message-ID: <438C8082.1010300@moscow.vdiweb.com> Date: Tue, 29 Nov 2005 19:23:30 +0300 From: Anton Pevtsov User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040514 X-Accept-Language: en-us, en MIME-Version: 1.0 To: stdcxx-dev@incubator.apache.org Subject: test for lib.alg.fill Content-Type: multipart/mixed; boundary="------------070204030401020303000700" X-OriginalArrivalTime: 29 Nov 2005 16:23:06.0165 (UTC) FILETIME=[2DC5FE50:01C5F501] X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------070204030401020303000700 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit The attached file contains my attempt to update the lib.alg.fill test. I have a question about fill_n test: is it necessary to implement a separate test for the fill_n algorithm with our custom Size class? If so, this test may be updated - currently it just uses size_t. With best wishes, Anton Pevtsov --------------070204030401020303000700 Content-Type: text/plain; name="25.fill.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="25.fill.cpp" /*************************************************************************** * * fill.cpp - test exercising 25.2.5 [lib.alg.fill] * * $Id: //stdlib/dev/tests/stdlib/algorithm/fill.cpp#14 $ * *************************************************************************** * * 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 // for fill #include // for size_t #include #include // for rw_test() /**************************************************************************/ // exercises std::fill() template void test_fill (std::size_t N, const FillIterator& fill_iter, const T* ) { static const char* const itname = type_name (fill_iter, (T*) 0); rw_info (0, 0, 0, "void std::fill (%s, %s, %s)", itname, itname, "const X& "); // generate sequential values for each default constructed T T::gen_ = gen_seq; // use ::operator new() to prevent default initialization T *buf = _RWSTD_STATIC_CAST (T*, ::operator new (N * sizeof (T))); // default-construct the first T at buf[0] new (buf) T (); for (std::size_t i = 0; i < N; ++i) { // default-construct a new X at the end of buf T* const new_t = new (buf + i) T (); // exercise 25.2.5 - std::fill<> () std::size_t last_n_op_assign = T::n_total_op_assign_; T* const buf_end = buf + i + 1; const FillIterator begin = make_iter (buf, buf, buf_end, fill_iter); const FillIterator end = make_iter (buf_end, buf_end, buf_end, fill_iter); std::fill (begin, end, *new_t); // verify 25.2.5, p2 bool success; std::size_t j = 0; for ( ; j != i + 1; ++j) { success = buf[j].val_ == new_t->val_; if (!success) break; } rw_assert (success, 0, __LINE__, "%zu. std::fill<> (): buf[%zu]: %d != %d", i + 1, j, buf[j].val_, new_t->val_); if (!success) break; // verify 25.2.5, p3 success = T::n_total_op_assign_ - last_n_op_assign == i + 1; rw_assert (success, 0, __LINE__, "%zu. std::fill<> (): complexity: %zu != %zu", i + 1, T::n_total_op_assign_ - last_n_op_assign, i + 1); if (!success) break; } ::operator delete (buf); } // exercises std::fill_n() template void test_fill_n (std::size_t N, const FillIterator& fill_iter, const T* ) { static const char* const itname = type_name (fill_iter, (T*) 0); rw_info (0, 0, 0, "void std::fill_n (%s, %s, %s)", itname, "std::size_t", "const X& "); // generate sequential values for each default constructed T T::gen_ = gen_seq; // use ::operator new() to prevent default initialization T *buf = _RWSTD_STATIC_CAST (T*, ::operator new (N * sizeof (T))); // default-construct the first T at buf[0] new (buf) T (); for (std::size_t i = 0; i < N; ++i) { // default-construct a new X at the end of buf T* const new_t = new (buf + i) T (); // exercise 25.2.5 - std::fill<> () std::size_t last_n_op_assign = T::n_total_op_assign_; T* const buf_end = buf + i + 1; const FillIterator begin = make_iter (buf, buf, buf_end, fill_iter); std::fill_n (begin, i, *new_t); bool success = true; // verify 25.2.5, p2 std::size_t j = 0; for ( ; j != i; ++j) { success = buf[j].val_ == new_t->val_; if (!success) break; } rw_assert (success, 0, __LINE__, "%zu. std::fill_n<> (): buf[%zu]: %d != %d", i + 1, j, buf[j].val_, new_t->val_); if (!success) break; success = T::n_total_op_assign_ - last_n_op_assign == i; rw_assert (success, 0, __LINE__, "%zu. std::fill_n<> (): complexity: %zu != %zu", i + 1, T::n_total_op_assign_ - last_n_op_assign, i); if (!success) break; } ::operator delete (buf); } /**************************************************************************/ /* extern */ int rw_opt_nloops = 32; // --nloops /* extern */ int rw_opt_no_output_iter; // --no-OutputIterator /* 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 static void test_fill (const std::size_t N) { rw_info (0, 0, 0, "template " "void std::fill (%1$s, %1$s, const %2$s& )", "FillIterator", "T"); if (rw_opt_no_fwd_iter) { rw_note (0, __FILE__, __LINE__, "ForwardIterator test disabled"); } else { test_fill (N, FwdIter(), (X*)0); } if (rw_opt_no_bidir_iter) { rw_note (0, __FILE__, __LINE__, "BidirectionalIterator test disabled"); } else { test_fill (N, BidirIter(), (X*)0); } if (rw_opt_no_rnd_iter) { rw_note (0, __FILE__, __LINE__, "RandomAccessIterator test disabled"); } else { test_fill (N, RandomAccessIter(), (X*)0); } } static void test_fill_n (const std::size_t N) { rw_info (0, 0, 0, "template " "void std::fill_n (%1$s, %2$s, const %3$s& )", "FillIterator", "Size", "T"); if (rw_opt_no_output_iter) { rw_note (0, __FILE__, __LINE__, "OutputIterator test disabled"); } else { test_fill_n (N, OutputIter((X*)0, (X*)0, (X*)0), (X*)0); } if (rw_opt_no_fwd_iter) { rw_note (0, __FILE__, __LINE__, "ForwardIterator test disabled"); } else { test_fill_n (N, FwdIter(), (X*)0); } if (rw_opt_no_bidir_iter) { rw_note (0, __FILE__, __LINE__, "BidirectionalIterator test disabled"); } else { test_fill_n (N, BidirIter(), (X*)0); } if (rw_opt_no_rnd_iter) { rw_note (0, __FILE__, __LINE__, "RandomAccessIterator test disabled"); } else { test_fill_n (N, RandomAccessIter(), (X*)0); } } static int run_test (int, char*[]) { // check that the number of loops is non-negative rw_fatal (-1 < rw_opt_nloops, 0, 0, "number of loops must be non-negative, got %d", rw_opt_nloops); const std::size_t N = std::size_t (rw_opt_nloops); test_fill(N); test_fill_n(N); return 0; } int main (int argc, char *argv[]) { return rw_test (argc, argv, __FILE__, "lib.alg.fill", 0 /* no comment */, run_test, "|-nloops#" "|-no-OutputIterator#" "|-no-ForwardIterator#" "|-no-BidirectionalIterator#" "|-no-RandomAccessIterator#", &rw_opt_nloops, &rw_opt_no_output_iter, &rw_opt_no_fwd_iter, &rw_opt_no_bidir_iter, &rw_opt_no_rnd_iter); } --------------070204030401020303000700--