Author: sebor
Date: Sun Oct 14 14:46:25 2007
New Revision: 584622
URL: http://svn.apache.org/viewvc?rev=584622&view=rev
Log:
2007-10-14 Martin Sebor <[EMAIL PROTECTED]>
STDCXX-278
* valarray.html: Updated example source code to reflect rev 584618.
Modified:
incubator/stdcxx/trunk/doc/stdlibref/valarray.html
Modified: incubator/stdcxx/trunk/doc/stdlibref/valarray.html
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/doc/stdlibref/valarray.html?rev=584622&r1=584621&r2=584622&view=diff
==============================================================================
--- incubator/stdcxx/trunk/doc/stdlibref/valarray.html (original)
+++ incubator/stdcxx/trunk/doc/stdlibref/valarray.html Sun Oct 14 14:46:25 2007
@@ -857,34 +857,50 @@
// valarray.cpp
//
-#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 ()
{
- const int ibuf[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- const int ibuf2[] = { 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19 };
+ const int ibuf[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ const int ibuf2[] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
- // create 2 valarrays of ints
- std::valarray<int> vi (ibuf, sizeof ibuf / sizeof *ibuf);
- std::valarray<int> vi2 (ibuf2, sizeof ibuf2 / sizeof *ibuf2);
+ // create 2 valarrays of ints
+ std::valarray<int> vi (ibuf, sizeof ibuf / sizeof *ibuf);
+ std::valarray<int> vi2 (ibuf2, sizeof ibuf2 / sizeof *ibuf2);
- // print them out
- std::cout << vi << std::endl
- << vi2 << std::endl;
+ // print them out
+ std::cout << vi << '\n' << vi2 << '\n';
- vi += vi2;
- vi2 *= 2;
+ vi += vi2;
+ vi2 *= 2;
- std::valarray<int> vi3 = vi2 % vi;
+ std::valarray<int> vi3 = vi2 % vi;
- // print them out again
- std::cout << vi << std::endl
- << vi2 << std::endl
- << vi3 << std::endl;
+ // print them out again
+ std::cout << vi << '\n' << vi2 << '\n' <<
vi3 << '\n';
- return 0;
+ return 0;
}