stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r584618 - /incubator/stdcxx/trunk/examples/manual/valarray.cpp
Date Sun, 14 Oct 2007 21:42:13 GMT
Author: sebor
Date: Sun Oct 14 14:42:12 2007
New Revision: 584618

URL: http://svn.apache.org/viewvc?rev=584618&view=rev
Log:
2007-10-14  Martin Sebor  <sebor@roguewave.com>

	STDCXX-278
	* valarray.cpp (<valarray.h>): Removed a confusing #include directive
	and added the definition of a generic operator<<() for valarray copied
	from the said header.
	(main): Replaced endl with '\n' for efficiency.

Modified:
    incubator/stdcxx/trunk/examples/manual/valarray.cpp

Modified: incubator/stdcxx/trunk/examples/manual/valarray.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/manual/valarray.cpp?rev=584618&r1=584617&r2=584618&view=diff
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/valarray.cpp (original)
+++ incubator/stdcxx/trunk/examples/manual/valarray.cpp Sun Oct 14 14:42:12 2007
@@ -1,6 +1,6 @@
 /**************************************************************************
  *
- * valarray.cpp -- Valarray examples 
+ * valarray.cpp -- valarray example
  *
  * $Id$
  *
@@ -22,12 +22,32 @@
  * implied.   See  the License  for  the  specific language  governing
  * permissions and limitations under the License.
  *
- * Copyright 1994-2006 Rogue Wave Software.
+ * Copyright 1994-2007 Rogue Wave Software, Inc.
  * 
  **************************************************************************/
 
-#include <valarray.h>   // for valarray stream inserter
-#include <iostream>     // for cout, endl
+#include <cstddef>      // for size_t
+#include <iostream>     // for cout
+#include <valarray>     // for valarray
+
+#include <examples.h>
+
+
+template <class T> 
+inline std::ostream&
+operator<< (std::ostream &out, const std::valarray<T> &v)
+{
+    out << '[';
+
+    for (std::size_t i = 0; i < v.size (); ++i) {
+        out << v [i];
+        if (i < v.size () - 1)
+            out << ',';
+    }
+
+    return out << ']';
+}
+
 
 int main ()
 {
@@ -39,7 +59,7 @@
     std::valarray<int> vi2 (ibuf2, sizeof ibuf2 / sizeof *ibuf2);
 
     // print them out
-    std::cout << vi << std::endl << vi2 << std::endl;
+    std::cout << vi << '\n' << vi2 << '\n';
 
     vi += vi2;
     vi2 *= 2;
@@ -47,7 +67,7 @@
     std::valarray<int> vi3 = vi2 % vi;
 
     // print them out again
-    std::cout << vi << std::endl << vi2 << std::endl << vi3
<< std::endl;
+    std::cout << vi << '\n' << vi2 << '\n' << vi3 <<
'\n';
 
     return 0;
 }



Mime
View raw message