/* valarrayIO.h
 * ...
 */
 
#include <iostream>       // istream, ostream
#include <valarray>
using namespace std;

/* read() fills a valarray<T> with input from a stream.
 * Note: Must #include <valarray> to use this function.
 *
 * Receives:     type parameter t
 *               in, an istream
 *               theValArray, a valarray
 * Input:        a sequence of T values
 * Precondition: operator >> is defined for type T.
 * Pass back:    the modified istream and the modified valarray<T>
 ****************************************************************/
template <class T>
void read(istream & in, valarray<T> & theValArray)
{
  for (int i = 0; i < theValArray.size(); i++)
     in >> theValArray[i];
}

/* print() displays the T values stored in a valarray.
 * Note: Must #include <valarray> to use this function.
 *
 *  Receive: type parameter T
 *           out, an ostream
 *           theValArray, a valarray
 *  Output:  each value in theArray to the ostream out
 *  Precondition: operator << is defined for type T.
 *  Passes back:  the modified ostream out
 ************************************************************/

template <class T>
void print(ostream & out, const valarray<T> & theValArray)
{
   for (int i = 0; i < theValArray.size(); i++)
      out << theValArray[i] << " ";
}

