Author: sebor
Date: Mon Oct 15 16:40:04 2007
New Revision: 584973
URL: http://svn.apache.org/viewvc?rev=584973&view=rev
Log:
2007-10-15 Martin Sebor <[EMAIL PROTECTED]>
* valarray.cpp: Merged from trunk at rev 584618.
Modified:
incubator/stdcxx/branches/4.2.0/examples/manual/valarray.cpp
Modified: incubator/stdcxx/branches/4.2.0/examples/manual/valarray.cpp
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.0/examples/manual/valarray.cpp?rev=584973&r1=584972&r2=584973&view=diff
==============================================================================
--- incubator/stdcxx/branches/4.2.0/examples/manual/valarray.cpp (original)
+++ incubator/stdcxx/branches/4.2.0/examples/manual/valarray.cpp Mon Oct 15
16:40:04 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;
}