stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r381513 - in /incubator/stdcxx/trunk/tests/numerics: 26.adjacent.diff.cpp 26.inner.product.cpp 26.partial.sum.cpp
Date Tue, 28 Feb 2006 00:49:52 GMT
Author: sebor
Date: Mon Feb 27 16:49:51 2006
New Revision: 381513

URL: http://svn.apache.org/viewcvs?rev=381513&view=rev
Log:
2006-02-27  Martin Sebor  <sebor@roguewave.com>

	* 26.adjacent.diff.cpp: Replaced class Y with class X and enhanced
	diagnostic output to take advantage of the %{X=+*} directive to
	format sequences of objects of type X as strictly numeric arrays.
	* 26.inner.product.cpp: Same.
	* 26.partial.sum.cpp: Same.

Modified:
    incubator/stdcxx/trunk/tests/numerics/26.adjacent.diff.cpp
    incubator/stdcxx/trunk/tests/numerics/26.inner.product.cpp
    incubator/stdcxx/trunk/tests/numerics/26.partial.sum.cpp

Modified: incubator/stdcxx/trunk/tests/numerics/26.adjacent.diff.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/numerics/26.adjacent.diff.cpp?rev=381513&r1=381512&r2=381513&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/numerics/26.adjacent.diff.cpp (original)
+++ incubator/stdcxx/trunk/tests/numerics/26.adjacent.diff.cpp Mon Feb 27 16:49:51 2006
@@ -74,68 +74,11 @@
 
 /**************************************************************************/
 
-struct Y: public X
+X operator- (const X &lhs, const X &rhs)
 {
-    // number of times the object's + operator has been invoked,
-    // regardless of whether the operation threw an exception or not
-    std::size_t n_op_minus_;
-
-    static std::size_t n_total_op_minus_;       // ... - operators ...
-
-    // class thrown from the respective functions
-    struct OpMinus: Exception { };
-
-    // throw object's `id' wrapped in the appropriate struct when the
-    // corresponding n_total_xxx_ counter reaches the value pointed to
-    // by the respective pointer below
-    static std::size_t* op_minus_throw_ptr_;
-
-    // objects to which the pointers above initally point
-    static std::size_t op_minus_throw_count_;
-};
-
-/* static */ std::size_t  Y::n_total_op_minus_;
-/* static */ std::size_t* Y::op_minus_throw_ptr_ =
-    &Y::op_minus_throw_count_;
-/* static */ std::size_t  Y::op_minus_throw_count_ =
-    std::size_t (-1);
-
-/**************************************************************************/
-
-Y operator- (const Y& lhs, const Y& rhs) {
-
-    // increment the number of times each distinct object
-    // has been used as the argument to operator-
-    // (do so even if the function throws an exception below)
-    ++_RWSTD_CONST_CAST (Y*, &lhs)->n_op_minus_;
-
-    if (&lhs != &rhs)
-        ++_RWSTD_CONST_CAST (Y*, &rhs)->n_op_minus_;
-
-    // increment the total number of invocations of the operator
-    // (do so even if the function throws an exception below)
-    ++Y::n_total_op_minus_;
-
-#ifndef _RWSTD_NO_EXCEPTIONS
-
-    // throw an exception if the number of calls
-    // to operator- reaches the given value
-
-    if ( lhs.op_minus_throw_ptr_
-            && Y::n_total_op_minus_ == *lhs.op_minus_throw_ptr_) {
-            Y::OpMinus ex;
-            ex.id_ = lhs.id_;
-            throw ex;
-    }
-
-#endif   // _RWSTD_NO_EXCEPTIONS
-
-    Y res(lhs);
-    res.val_ -= rhs.val_;
-    return res;
+    return X (lhs)-= rhs;
 }
 
-
 /**************************************************************************/
 
 template <class T>
@@ -172,12 +115,12 @@
         funcalls_ = 0;
     }
 
-    // return a type convertible to Y
-    conv_to_T<Y> operator() (const Y &x, const Y &y) /* non-const */ {
+    // return a type convertible to X
+    conv_to_T<X> operator() (const X &x, const X &y) /* non-const */ {
         ++funcalls_;
-        Y res (x);
+        X res (x);
         res.val_ -= y.val_;
-        return conv_to_T<Y>::make (res);
+        return conv_to_T<X>::make (res);
     }
 
 private:
@@ -195,9 +138,9 @@
     const char* iter_names [2];
 
     // pure virtual
-    virtual Y*
-    adjacent_difference (const Y    *xsrc, const Y     *xsrc_end,
-                         Y          *xdst, const Y     *xdst_end,
+    virtual X*
+    adjacent_difference (const X    *xsrc, const X     *xsrc_end,
+                         X          *xdst, const X     *xdst_end,
                          const Accumulator *op) const = 0;
 };
 
@@ -205,13 +148,13 @@
 struct AdjacentDiff : AdjacentDiffBase
 {
     AdjacentDiff () {
-        iter_names [0] = type_name (InputIterator (0, 0, 0), (Y*)0);
-        iter_names [1] = type_name (OutputIterator (0, 0, 0), (Y*)0);
+        iter_names [0] = type_name (InputIterator (0, 0, 0), (X*)0);
+        iter_names [1] = type_name (OutputIterator (0, 0, 0), (X*)0);
     }
 
-    virtual Y*
-    adjacent_difference (const Y    *xsrc, const Y     *xsrc_end,
-                         Y          *xdst, const Y     *xdst_end,
+    virtual X*
+    adjacent_difference (const X    *xsrc, const X     *xsrc_end,
+                         X          *xdst, const X     *xdst_end,
                          const Accumulator *op) const {
 
         const InputIterator  first (xsrc,     xsrc, xsrc_end);
@@ -238,66 +181,68 @@
                                bool                      binop,
                                bool                      same_seq)
 {
-    const char* const itname =  alg.iter_names [0];
+    const char* const itname  =  alg.iter_names [0];
     const char* const outname = alg.iter_names [1];
-    const char* const opname = "Minus";
+    const char* const opname  = "Minus";
 
     rw_info (0, 0, 0, 
              "std::adjacent_difference(%s, %1$s, %s%{?}, %s%{;})%{?}, %s%{;}",
              itname, outname, binop, opname, same_seq, "first == result");
 
-    Y::gen_ = gen_seq;
+    X::gen_ = gen_seq;
 
-    Y* const src = new Y [N];
-    Y* dst = same_seq ? src : new Y [N];
+    X* const src = new X [N + 1];
+    X* dst = same_seq ? src : new X [N + 1];
 
     for (std::size_t i = 0; i != N; ++i) {
 
-        Y* const src_end = src + i;
-        Y* const dst_end = dst + i;
+        X* const src_end = src + i;
+        X* const dst_end = dst + i;
 
-        std::size_t last_n_op_minus  = Y::n_total_op_minus_;
+        std::size_t last_n_op_minus_assign  = X::n_total_op_minus_assign_;
 
         const Accumulator   acc  (0, 0);
         const Accumulator* const pbinop = binop ? &acc : 0;
 
-        std::size_t k = i > 0 ? i - 1 : 0;
-        int* const tmp_val = new int [i]; 
-        for (; k > 0; k--)
-            tmp_val[k] = src[k].val_ - src[k - 1].val_;
-        if (i > 0)
-            tmp_val[0] = src[0].val_;
+        std::size_t k = 0 < i ? i - 1 : 0;
+        int* const tmp_val = new int [i + 1];
+
+        for (; 0 < k; --k)
+            tmp_val [k] = src [k].val_ - src [k - 1].val_;
+
+        tmp_val [0] = src [0].val_;
 
-        const Y* res = 
+        const X* const res =
             alg.adjacent_difference (src, src_end, dst, dst_end, pbinop);
 
-        const std::size_t minus_ops = binop ? Accumulator::funcalls_ : 
-            Y::n_total_op_minus_ - last_n_op_minus;
+        const std::size_t minus_ops = binop ?
+              Accumulator::funcalls_
+            : X::n_total_op_minus_assign_ - last_n_op_minus_assign;
 
         // verify the returned iterator 26.4.4, p2
         bool success = res == dst_end;
         rw_assert (success, 0, __LINE__,
-                   "step %zu: adjacent_difference <%s, %s%{?}, %s%{;}> = %p"
-                   " expected %p, difference %td",
-                   i + 1, itname, outname, binop, opname, res, dst_end,
-                   res - dst_end);
+                   "adjacent_difference <%s, %s%{?}, %s%{;}>"
+                   "({%{X=+*}}, ...) == result + %td, got result + %td",
+                   itname, outname, binop, opname,
+                   int (i), src, dst_end - dst, res - dst);
 
         for (k = 0; k < i; k++) {
-            success = dst[k].val_ == tmp_val[k];
+            success = dst [k].val_ == tmp_val [k];
             if (!success)
                 break;
         }
 
         // verify the result 26.4.4, p1
-        if (i > 0) {
+        if (0 < i) {
             // to avoid errors in --trace mode
             k = k < i ? k : i - 1;
 
             rw_assert (success, 0, __LINE__,
-                       "step %zu: adjacent_difference <%s, %s%{?}, %s%{;}>: "
-                       "got %d at %zu, expected %d here",
-                       i + 1, itname, outname, binop, opname, dst[k].val_, 
-                       k + 1, tmp_val[k]);
+                       "adjacent_difference <%s, %s%{?}, %s%{;}>"
+                       "({%{X=+*}}, ...) ==> {%{X=+*.*}}, expected %d",
+                       itname, outname, binop, opname,
+                       int (i), src, int (i), int (k), dst, tmp_val [k]);
         }
 
         delete[] tmp_val;
@@ -306,12 +251,14 @@
             break;
 
         // verify the complexity, 26.4.4, p3
-        const std::size_t exp_minus_ops = i > 0 ? i - 1 : 0;
+        const std::size_t exp_minus_ops = 0 < i ? i - 1 : 0;
         success = minus_ops == exp_minus_ops;
         rw_assert (success, 0, __LINE__,
-                   "step %zu: adjacent_difference <%s, %s%{?}, %s%{;}> "
-                   "complexity: got %zu invocations of %s, expected %zu",
-                   i + 1, itname, outname, binop, opname, minus_ops, 
+                   "adjacent_difference <%s, %s%{?}, %s%{;}>"
+                   "({%{X=+*}}, ...) complexity: got %zu invocations "
+                   "of %s, expected %zu",
+                   itname, outname, binop, opname,
+                   int (i), src, minus_ops,
                    binop ? "BinaryMinus" : "operator-", exp_minus_ops);
 
         if (!success)
@@ -359,16 +306,16 @@
 {
     if (0 == rw_opt_no_output_iter)
         gen_adjacent_difference_test (
-            N, it, OutputIter<Y>(0, 0, 0), binop);
+            N, it, OutputIter<X>(0, 0, 0), binop);
     if (0 == rw_opt_no_fwd_iter)
         gen_adjacent_difference_test (
-            N, it, FwdIter<Y>(0, 0, 0), binop);
+            N, it, FwdIter<X>(0, 0, 0), binop);
     if (0 == rw_opt_no_bidir_iter)
         gen_adjacent_difference_test (
-            N, it, BidirIter<Y>(0, 0, 0), binop);
+            N, it, BidirIter<X>(0, 0, 0), binop);
     if (0 == rw_opt_no_rnd_iter)
         gen_adjacent_difference_test (
-            N, it, RandomAccessIter<Y>(0, 0, 0), binop);
+            N, it, RandomAccessIter<X>(0, 0, 0), binop);
 }
 
 // generates a specialization of the partial_sum test for each of the required
@@ -388,23 +335,23 @@
     if (rw_opt_no_input_iter)
         rw_note (0, 0, 0, "InputIterator test disabled");
     else
-        gen_adjacent_difference_test (N, InputIter<Y>(0, 0, 0), binop);
+        gen_adjacent_difference_test (N, InputIter<X>(0, 0, 0), binop);
 
     if (rw_opt_no_fwd_iter)
         rw_note (0, 0, 0, "ForwardIterator test disabled");
     else
-        gen_adjacent_difference_test (N, ConstFwdIter<Y>(0, 0, 0), binop);
+        gen_adjacent_difference_test (N, ConstFwdIter<X>(0, 0, 0), binop);
 
     if (rw_opt_no_bidir_iter)
         rw_note (0, 0, 0, "BidirectionalIterator test disabled");
     else
-        gen_adjacent_difference_test (N, ConstBidirIter<Y>(0, 0, 0), binop);
+        gen_adjacent_difference_test (N, ConstBidirIter<X>(0, 0, 0), binop);
 
     if (rw_opt_no_rnd_iter)
         rw_note (0, 0, 0, "RandomAccessIterator test disabled");
     else
         gen_adjacent_difference_test (N, 
-            ConstRandomAccessIter<Y>(0, 0, 0), binop);
+            ConstRandomAccessIter<X>(0, 0, 0), binop);
 }
 
 /**************************************************************************/

Modified: incubator/stdcxx/trunk/tests/numerics/26.inner.product.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/numerics/26.inner.product.cpp?rev=381513&r1=381512&r2=381513&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/numerics/26.inner.product.cpp (original)
+++ incubator/stdcxx/trunk/tests/numerics/26.inner.product.cpp Mon Feb 27 16:49:51 2006
@@ -84,113 +84,9 @@
 
 /**************************************************************************/
 
-struct Y: public X
+X operator* (const X& lhs, const X& rhs)
 {
-    // number of times the object's += and * operators has been invoked,
-    // regardless of whether the operation threw an exception or not
-    std::size_t n_op_plus_assign_;
-    std::size_t n_op_multiple_;
-
-    static std::size_t n_total_op_plus_assign_;   // ... += operators ...
-    static std::size_t n_total_op_multiple_;       // ... * operators ...
-
-    // class thrown from the respective functions
-    struct OpPlusAssign: Exception { };
-    struct OpMultiple: Exception { };
-
-    // throw object's `id' wrapped in the appropriate struct when the
-    // corresponding n_total_xxx_ counter reaches the value pointed to
-    // by the respective pointer below
-    static std::size_t* op_plus_assign_throw_ptr_;
-    static std::size_t* op_multiple_throw_ptr_;
-
-    // objects to which the pointers above initally point
-    static std::size_t op_plus_assign_throw_count_;
-    static std::size_t op_multiple_throw_count_;
-
-    Y& operator+= (const Y& rhs) {
-
-        // verify id validity and uniqueness
-        RW_ASSERT (id_ && id_ <= id_gen_);
-        RW_ASSERT (rhs.id_ && rhs.id_ <= id_gen_);
-        RW_ASSERT (this == &rhs || id_ != rhs.id_);
-
-        // increment the number of times each distinct object
-        // has been used as the argument to operator+=
-        // (do so even if the function throws an exception below)
-        ++n_op_plus_assign_;
-
-        if (this != &rhs)
-            ++_RWSTD_CONST_CAST (Y*, &rhs)->n_op_plus_assign_;
-
-        // increment the total number of invocations of the operator
-        // (do so even if the function throws an exception below)
-        ++n_total_op_plus_assign_;
-
-#ifndef _RWSTD_NO_EXCEPTIONS
-
-        // throw an exception if the number of calls
-        // to operator== reaches the given value
-
-        if (   op_plus_assign_throw_ptr_
-            && n_total_op_plus_assign_ == *op_plus_assign_throw_ptr_) {
-            OpPlusAssign ex;
-            ex.id_ = id_;
-            throw ex;
-        }
-
-#endif   // _RWSTD_NO_EXCEPTIONS
-
-        val_ += rhs.val_;
-        return *this;
-    }
-};
-
-/* static */ std::size_t  Y::n_total_op_plus_assign_;
-/* static */ std::size_t* Y::op_plus_assign_throw_ptr_ =
-    &Y::op_plus_assign_throw_count_;
-/* static */ std::size_t  Y::op_plus_assign_throw_count_ =
-    std::size_t (-1);
-
-/* static */ std::size_t  Y::n_total_op_multiple_;
-/* static */ std::size_t* Y::op_multiple_throw_ptr_ =
-    &Y::op_multiple_throw_count_;
-/* static */ std::size_t  Y::op_multiple_throw_count_ =
-    std::size_t (-1);
-
-/**************************************************************************/
-
-Y operator* (const Y& lhs, const Y& rhs) {
-
-    // increment the number of times each distinct object
-    // has been used as the argument to operator*
-    // (do so even if the function throws an exception below)
-    ++_RWSTD_CONST_CAST (Y*, &lhs)->n_op_multiple_;
-
-    if (&lhs != &rhs)
-        ++_RWSTD_CONST_CAST (Y*, &rhs)->n_op_multiple_;
-
-    // increment the total number of invocations of the operator
-    // (do so even if the function throws an exception below)
-    ++Y::n_total_op_multiple_;
-
-#ifndef _RWSTD_NO_EXCEPTIONS
-
-    // throw an exception if the number of calls
-    // to operator== reaches the given value
-
-    if (   lhs.op_multiple_throw_ptr_
-        && Y::n_total_op_multiple_ == *lhs.op_multiple_throw_ptr_) {
-        Y::OpMultiple ex;
-        ex.id_ = lhs.id_;
-        throw ex;
-    }
-
-#endif   // _RWSTD_NO_EXCEPTIONS
-
-    Y res (lhs);
-    res.val_ *= rhs.val_;
-    return res;
+    return X (lhs) *= rhs;
 }
 
 /**************************************************************************/
@@ -229,12 +125,12 @@
         funcalls_ = 0;
     }
 
-    // return a type convertible to Y
-    conv_to_T<Y> operator() (const Y &x, const Y &y) /* non-const */ {
+    // return a type convertible to X
+    conv_to_T<X> operator() (const X &x, const X &y) /* non-const */ {
         ++funcalls_;
-        Y res (x);
+        X res (x);
         res.val_ += y.val_;
-        return conv_to_T<Y>::make (res);
+        return conv_to_T<X>::make (res);
     }
 
 private:
@@ -254,12 +150,12 @@
         funcalls_ = 0;
     }
 
-    // return a type convertible to Y
-    conv_to_T<Y> operator() (const Y &x, const Y &y) /* non-const */ {
+    // return a type convertible to X
+    conv_to_T<X> operator() (const X &x, const X &y) /* non-const */ {
         ++funcalls_;
-        Y res (x);
+        X res (x);
         res.val_ *= y.val_;
-        return conv_to_T<Y>::make (res);
+        return conv_to_T<X>::make (res);
     }
 
 private:
@@ -277,10 +173,10 @@
     const char* iter_names [2];
 
     // pure virtual
-    virtual Y
-    inner_product (const Y    *xsrc1, const Y           *xsrc1_end,
-                   const Y    *xsrc2, const Y           *xsrc2_end,
-                   const Y&    init,  const Accumulator *op1, 
+    virtual X
+    inner_product (const X    *xsrc1, const X           *xsrc1_end,
+                   const X    *xsrc2, const X           *xsrc2_end,
+                   const X&    init,  const Accumulator *op1, 
                    const Multiplicator *op2) const = 0;
 };
 
@@ -288,21 +184,21 @@
 struct InnerProduct : InnerProductBase
 {
     InnerProduct () {
-        iter_names [0] = type_name (InputIterator1 (0, 0, 0), (Y*)0);
-        iter_names [1] = type_name (InputIterator2 (0, 0, 0), (Y*)0);
+        iter_names [0] = type_name (InputIterator1 (0, 0, 0), (X*)0);
+        iter_names [1] = type_name (InputIterator2 (0, 0, 0), (X*)0);
     }
 
-    virtual Y
-    inner_product (const Y    *xsrc1, const Y           *xsrc1_end,
-                   const Y    *xsrc2, const Y           *xsrc2_end,
-                   const Y&    init,  const Accumulator *op1, 
+    virtual X
+    inner_product (const X    *xsrc1, const X           *xsrc1_end,
+                   const X    *xsrc2, const X           *xsrc2_end,
+                   const X&    init,  const Accumulator *op1, 
                    const Multiplicator *op2) const {
 
         const InputIterator1 first1 (xsrc1,     xsrc1, xsrc1_end);
         const InputIterator1 last1  (xsrc1_end, xsrc1, xsrc1_end);
         const InputIterator2 first2 (xsrc2,     xsrc2, xsrc2_end);
 
-        const Y res = op1 ?
+        const X res = op1 ?
               std::inner_product (first1, last1, first2, init, *op1, *op2)
             : std::inner_product (first1, last1, first2, init);
 
@@ -323,7 +219,7 @@
 {
     const char* const it1name = alg.iter_names [0];
     const char* const it2name = alg.iter_names [1];
-    const char* const tname   = "Y";
+    const char* const tname   = "X";
     const char* const op1name = "Plus";
     const char* const op2name = "Multiple";
 
@@ -331,19 +227,19 @@
              "std::inner_product (%s, %1$s, %s, %s%{?}, %s, %s%{;})",
              it1name, it2name, tname, binop, op1name, op2name);
 
-    // construct initial Y
-    const Y init = Y ();
+    // construct initial X
+    const X init = X ();
     int sum = init.val_;
 
-    Y::gen_ = gen_seq;
+    X::gen_ = gen_seq;
 
-    Y* const buf1 = new Y [N];
-    Y* const buf2 = new Y [N];
+    X* const buf1 = new X [N];
+    X* const buf2 = new X [N];
     
     for (std::size_t i = 0; i != N; ++i) {
 
-        Y* const buf1_end = buf1 + i;
-        Y* const buf2_end = buf2 + i;
+        X* const buf1_end = buf1 + i;
+        X* const buf2_end = buf2 + i;
 
         const Accumulator   acc  (0, 0);
         const Multiplicator mult (0, 0);
@@ -351,17 +247,16 @@
         const Accumulator* const   pbinop1 = binop ? &acc : 0;
         const Multiplicator* const pbinop2 = binop ? &mult : 0;
 
-        const Y res = alg.inner_product (buf1, buf1_end, buf2, buf2_end, 
+        const X res = alg.inner_product (buf1, buf1_end, buf2, buf2_end, 
                                          init, pbinop1, pbinop2);
 
         // verify the result 26.4.1, p1
         bool success = sum == res.val_;
         rw_assert (success, 0, __LINE__,
-                   "step %zu: inner_product <%s, %s, %s%{?}, %s, %s%{;}>= %u "
-                   "expected %u%{?} (%d * %d + %d * %d + ... + %d * %d)%{;}",
-                   i + 1, it1name, it2name, tname, binop, op1name, op2name, 
-                   res.val_, sum, i >= 2, buf1[0].val_, buf2[0].val_, 
-                   buf1[1].val_, buf2[1].val_, buf1[i].val_, buf2[i].val_);
+                   "inner_product <%s, %s, %s%{?}, %s, %s%{;}>"
+                   "({%{X=+*}}, {%{X=+*}}) == %d, got %d",
+                   it1name, it2name, tname, binop, op1name, op2name,
+                   int (i), buf1, int (i), buf2, sum, res.val_);
 
         sum += (buf1 [i].val_ * buf2 [i].val_);
 
@@ -403,16 +298,16 @@
 {
     if (0 == rw_opt_no_input_iter)
         gen_inner_product_test (
-            N, it1, InputIter<Y>(0, 0, 0), binop);
+            N, it1, InputIter<X>(0, 0, 0), binop);
     if (0 == rw_opt_no_fwd_iter)
         gen_inner_product_test (
-            N, it1, ConstFwdIter<Y>(0, 0, 0), binop);
+            N, it1, ConstFwdIter<X>(0, 0, 0), binop);
     if (0 == rw_opt_no_bidir_iter)
         gen_inner_product_test (
-            N, it1, ConstBidirIter<Y>(0, 0, 0), binop);
+            N, it1, ConstBidirIter<X>(0, 0, 0), binop);
     if (0 == rw_opt_no_rnd_iter)
         gen_inner_product_test (
-            N, it1, ConstRandomAccessIter<Y>(0, 0, 0), binop);
+            N, it1, ConstRandomAccessIter<X>(0, 0, 0), binop);
 }
 
 // generates a specialization of the inner_product test for each of the required
@@ -424,29 +319,29 @@
              "template <class %s, class %s, class %s%{?}, class %s, "
              "class %s%{;}> %3$s inner_product (%1$s, %1$s, %2$s, "
              "%3$s%{?}, %s, %s%{;})", 
-             "InputIterator1", "InputIterator2", "Y",
+             "InputIterator1", "InputIterator2", "X",
              binop, "BinaryOperation1", "BinaryOperation2", binop, 
              "BinaryOperation1", "BinaryOperation2");
 
     if (rw_opt_no_input_iter)
         rw_note (0, 0, 0, "InputIterator test disabled");
     else
-        gen_inner_product_test (N, InputIter<Y>(0, 0, 0), binop);
+        gen_inner_product_test (N, InputIter<X>(0, 0, 0), binop);
 
     if (rw_opt_no_fwd_iter)
         rw_note (0, 0, 0, "ForwardIterator test disabled");
     else
-        gen_inner_product_test (N, ConstFwdIter<Y>(0, 0, 0), binop);
+        gen_inner_product_test (N, ConstFwdIter<X>(0, 0, 0), binop);
 
     if (rw_opt_no_bidir_iter)
         rw_note (0, 0, 0, "BidirectionalIterator test disabled");
     else
-        gen_inner_product_test (N, ConstBidirIter<Y>(0, 0, 0), binop);
+        gen_inner_product_test (N, ConstBidirIter<X>(0, 0, 0), binop);
 
     if (rw_opt_no_rnd_iter)
         rw_note (0, 0, 0, "RandomAccessIterator test disabled");
     else
-        gen_inner_product_test (N, ConstRandomAccessIter<Y>(0, 0, 0), binop);
+        gen_inner_product_test (N, ConstRandomAccessIter<X>(0, 0, 0), binop);
 }
 
 /**************************************************************************/

Modified: incubator/stdcxx/trunk/tests/numerics/26.partial.sum.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/numerics/26.partial.sum.cpp?rev=381513&r1=381512&r2=381513&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/numerics/26.partial.sum.cpp (original)
+++ incubator/stdcxx/trunk/tests/numerics/26.partial.sum.cpp Mon Feb 27 16:49:51 2006
@@ -73,68 +73,11 @@
 
 /**************************************************************************/
 
-struct Y: public X
+X operator+ (const X &lhs, const X &rhs)
 {
-    // number of times the object's + operator has been invoked,
-    // regardless of whether the operation threw an exception or not
-    std::size_t n_op_plus_;
-
-    static std::size_t n_total_op_plus_;       // ... + operators ...
-
-    // class thrown from the respective functions
-    struct OpPlus: Exception { };
-
-    // throw object's `id' wrapped in the appropriate struct when the
-    // corresponding n_total_xxx_ counter reaches the value pointed to
-    // by the respective pointer below
-    static std::size_t* op_plus_throw_ptr_;
-
-    // objects to which the pointers above initally point
-    static std::size_t op_plus_throw_count_;
-};
-
-/* static */ std::size_t  Y::n_total_op_plus_;
-/* static */ std::size_t* Y::op_plus_throw_ptr_ =
-    &Y::op_plus_throw_count_;
-/* static */ std::size_t  Y::op_plus_throw_count_ =
-    std::size_t (-1);
-
-/**************************************************************************/
-
-Y operator+ (const Y& lhs, const Y& rhs) {
-
-    // increment the number of times each distinct object
-    // has been used as the argument to operator+
-    // (do so even if the function throws an exception below)
-    ++_RWSTD_CONST_CAST (Y*, &lhs)->n_op_plus_;
-
-    if (&lhs != &rhs)
-        ++_RWSTD_CONST_CAST (Y*, &rhs)->n_op_plus_;
-
-    // increment the total number of invocations of the operator
-    // (do so even if the function throws an exception below)
-    ++Y::n_total_op_plus_;
-
-#ifndef _RWSTD_NO_EXCEPTIONS
-
-    // throw an exception if the number of calls
-    // to operator== reaches the given value
-
-    if (   lhs.op_plus_throw_ptr_
-        && Y::n_total_op_plus_ == *lhs.op_plus_throw_ptr_) {
-        Y::OpPlus ex;
-        ex.id_ = lhs.id_;
-        throw ex;
-    }
-
-#endif   // _RWSTD_NO_EXCEPTIONS
-
-    Y res (lhs);
-    res.val_ += rhs.val_;
-    return res;
+    return X (lhs)+= rhs;
 }
 
-
 /**************************************************************************/
 
 template <class T>
@@ -171,12 +114,12 @@
         funcalls_ = 0;
     }
 
-    // return a type convertible to Y
-    conv_to_T<Y> operator() (const Y &x, const Y &y) /* non-const */ {
+    // return a type convertible to X
+    conv_to_T<X> operator() (const X &x, const X &y) /* non-const */ {
         ++funcalls_;
-        Y res (x);
+        X res (x);
         res.val_ += y.val_;
-        return conv_to_T<Y>::make (res);
+        return conv_to_T<X>::make (res);
     }
 
 private:
@@ -194,9 +137,9 @@
     const char* iter_names [2];
 
     // pure virtual
-    virtual Y*
-    partial_sum (const Y *xsrc, const Y *xsrc_end,
-                 Y *xdst, const Y *xdst_end,
+    virtual X*
+    partial_sum (const X *xsrc, const X *xsrc_end,
+                 X *xdst, const X *xdst_end,
                  const Accumulator *op) const = 0;
 };
 
@@ -205,13 +148,13 @@
 struct PartialSum: PartialSumBase
 {
     PartialSum () {
-        iter_names [0] = type_name (InputIterator (0, 0, 0), (Y*)0);
-        iter_names [1] = type_name (OutputIterator (0, 0, 0), (Y*)0);
+        iter_names [0] = type_name (InputIterator (0, 0, 0), (X*)0);
+        iter_names [1] = type_name (OutputIterator (0, 0, 0), (X*)0);
     }
 
-    virtual Y*
-    partial_sum (const Y *xsrc, const Y *xsrc_end,
-                 Y *xdst, const Y *xdst_end,
+    virtual X*
+    partial_sum (const X *xsrc, const X *xsrc_end,
+                 X *xdst, const X *xdst_end,
                  const Accumulator *op) const {
 
         const InputIterator  first (xsrc,     xsrc, xsrc_end);
@@ -233,10 +176,10 @@
 /**************************************************************************/
 
 // exercises partial_sum (26.4.3)
-void test_partial_sum (const std::size_t       N,
-                       const PartialSumBase   &alg,
-                       bool                    binop,
-                       bool                    same_seq)
+void test_partial_sum (const std::size_t     N,
+                       const PartialSumBase &alg,
+                       bool                  binop,
+                       bool                  same_seq)
 {
     const char* const itname =  alg.iter_names [0];
     const char* const outname = alg.iter_names [1];
@@ -246,17 +189,17 @@
              "std::partial_sum (%s, %1$s, %s%{?}, %s%{;})%{?}, %s%{;}",
              itname, outname, binop, opname, same_seq, "first == result");
 
-    Y::gen_ = gen_seq;
+    X::gen_ = gen_seq;
 
-    Y* const src = new Y [N];
-    Y* dst = same_seq ? src : new Y [N];
+    X* const src = new X [N];
+    X* dst = same_seq ? src : new X [N];
 
     for (std::size_t i = 0; i != N; ++i) {
 
-        Y* const src_end = src + i;
-        Y* const dst_end = dst + i;
+        X* const src_end = src + i;
+        X* const dst_end = dst + i;
 
-        std::size_t last_n_op_plus  = Y::n_total_op_plus_;
+        std::size_t last_n_op_plus  = X::n_total_op_plus_assign_;
 
         const Accumulator acc  (0, 0);
         const Accumulator* const pbinop = binop ? &acc : 0;
@@ -266,19 +209,19 @@
         for (; k < i; ++k)
             tmp_val [k] = src [k].val_;
 
-        const Y* const res =
+        const X* const res =
             alg.partial_sum (src, src_end, dst, dst_end, pbinop);
 
         const std::size_t plus_ops = binop ? Accumulator::funcalls_ : 
-            Y::n_total_op_plus_ - last_n_op_plus;
+            X::n_total_op_plus_assign_ - last_n_op_plus;
 
         // verify the returned iterator 26.4.3, p2
         bool success = res == dst_end;
         rw_assert (success, 0, __LINE__,
-                   "step %zu: partial_sum<%s, %s%{?}, %s%{;}> = %p"
-                   " expected %p, difference %td",
-                   i + 1, itname, outname, binop, opname, res, dst_end,
-                   res - dst_end);
+                   "partial_sum<%s, %s%{?}, %s%{;}>"
+                   "({%{X=+*}}, ...) == result + %d, got result %td",
+                   itname, outname, binop, opname,
+                   int (i), src, dst_end - dst, res - dst_end);
 
         int sum = 0;
         for (k = 0; k < i; ++k) {
@@ -294,10 +237,10 @@
             k = k < i ? k : i - 1;
 
             rw_assert (success, 0, __LINE__,
-                       "step %zu: partial_sum<%s, %s%{?}, %s%{;}>: "
-                       "got %u at %zu, expected %u here",
-                       i + 1, itname, outname, binop, opname, dst[k].val_, 
-                       k + 1, sum);
+                       "partial_sum<%s, %s%{?}, %s%{;}>"
+                       "({%{X=+*}}, ...) ==> {%{X=+*.*}}, expected %d",
+                       itname, outname, binop, opname,
+                       int (i), src, int (i), int (k), dst, sum);
         }
 
         delete[] tmp_val;
@@ -309,9 +252,11 @@
         const std::size_t exp_plus_ops = i > 0 ? i - 1 : 0;
         success = plus_ops == exp_plus_ops;
         rw_assert (success, 0, __LINE__,
-                   "step %zu: partial_sum <%s, %s%{?}, %s%{;}> "
-                   "complexity: got %zu invocations of %s, expected %zu",
-                   i + 1, itname, outname, binop, opname, plus_ops, 
+                   "partial_sum <%s, %s%{?}, %s%{;}>"
+                   "({%{X=+*}}, ...) complexity: got %zu invocations "
+                   "of %s, expected %zu",
+                   itname, outname, binop, opname,
+                   int (i), src, plus_ops,
                    binop ? "BinaryPlus" : "operator+", exp_plus_ops);
 
         if (!success)
@@ -359,16 +304,16 @@
 {
     if (0 == rw_opt_no_output_iter)
         gen_partial_sum_test (
-            N, it, OutputIter<Y>(0, 0, 0), binop);
+            N, it, OutputIter<X>(0, 0, 0), binop);
     if (0 == rw_opt_no_fwd_iter)
         gen_partial_sum_test (
-            N, it, FwdIter<Y>(0, 0, 0), binop);
+            N, it, FwdIter<X>(0, 0, 0), binop);
     if (0 == rw_opt_no_bidir_iter)
         gen_partial_sum_test (
-            N, it, BidirIter<Y>(0, 0, 0), binop);
+            N, it, BidirIter<X>(0, 0, 0), binop);
     if (0 == rw_opt_no_rnd_iter)
         gen_partial_sum_test (
-            N, it, RandomAccessIter<Y>(0, 0, 0), binop);
+            N, it, RandomAccessIter<X>(0, 0, 0), binop);
 }
 
 // generates a specialization of the partial_sum test for each of the required
@@ -388,22 +333,22 @@
     if (rw_opt_no_input_iter)
         rw_note (0, 0, 0, "InputIterator test disabled");
     else
-        gen_partial_sum_test (N, InputIter<Y>(0, 0, 0), binop);
+        gen_partial_sum_test (N, InputIter<X>(0, 0, 0), binop);
 
     if (rw_opt_no_fwd_iter)
         rw_note (0, 0, 0, "ForwardIterator test disabled");
     else
-        gen_partial_sum_test (N, ConstFwdIter<Y>(0, 0, 0), binop);
+        gen_partial_sum_test (N, ConstFwdIter<X>(0, 0, 0), binop);
 
     if (rw_opt_no_bidir_iter)
         rw_note (0, 0, 0, "BidirectionalIterator test disabled");
     else
-        gen_partial_sum_test (N, ConstBidirIter<Y>(0, 0, 0), binop);
+        gen_partial_sum_test (N, ConstBidirIter<X>(0, 0, 0), binop);
 
     if (rw_opt_no_rnd_iter)
         rw_note (0, 0, 0, "RandomAccessIterator test disabled");
     else
-        gen_partial_sum_test (N, ConstRandomAccessIter<Y>(0, 0, 0), binop);
+        gen_partial_sum_test (N, ConstRandomAccessIter<X>(0, 0, 0), binop);
 }
 
 /**************************************************************************/



Mime
View raw message