Permalink
Browse files

added operator<<(ostream,T) for T= const& (for temporaries)

  • Loading branch information...
lvv committed Aug 26, 2010
1 parent bdc052d commit 0f139a00f3150c10a0484b05c1a3ee16f64c6b52
Showing with 13 additions and 11 deletions.
  1. +9 −9 array.h
  2. +1 −1 t-array-opt.cc
  3. +3 −1 t-array.cc
18 array.h
@@ -352,7 +352,7 @@ int16_t max_impl (sse2, int16_t) const { // DBG cerr << " max<sse2,int16> " <<
// TODO mutiply http://mindstudies.psy.soton.ac.uk/dmitri/blog/index.php/archives/160
template<typename T,int N, int B> T
dot (const array<T,N,B>& LA, const array<T,N,B>& RA) {
dot_prod (const array<T,N,B>& LA, const array<T,N,B>& RA) {
typename array<T,N,B>::const_iterator lit = LA.begin();
typename array<T,N,B>::const_iterator rit = RA.begin();
T sum = 0;
@@ -396,15 +396,15 @@ distance_norm2 (const array<T,N,B>& LA, const array<T,N,B>& RA) {
template <typename T, int N, int B>
std::ostream&
operator<< (ostream& os, const array<T,N,B> A) { // WHY: if we change A to const-ref or rval-ref it will pring garbage? std not updated yet?
//os << format("[%d..%d]=") %A.ibegin() %(A.iend()-1);
//if (N > 10) std::cout << endl;
//std::cout << "[" << A.ibegin() << ".." << A.iend() << "] ";
//if (N > 10) std::cout << endl;
operator<< (ostream& os, array<T,N,B>& A) { // WHY: if we change A to const-ref or rval-ref it will pring garbage? std not updated yet?
copy (A.begin(), A.end(), ostream_iterator<T>(os, " "));
return os;
};
template <typename T, int N, int B> // for const& (for temproraries)
std::ostream&
operator<< (ostream& os, const array<T,N,B>& A) { // WHY: if we change A to const-ref or rval-ref it will pring garbage? std not updated yet?
copy (A.begin(), A.end(), ostream_iterator<T>(os, " "));
//for (long i=A.ibegin(); i< A.iend(); i++)
return os;
};
@@ -422,7 +422,7 @@ operator>> (istream& is, array<T,N,B>& A) {
template <typename T, int N> class vector: public array<T,N,1> {}; // index start from 1
//template <typename T, int N> class vector: public array<T,N,1> {}; // index start from 1
template <typename T, int N1, int N2, int B1=1, int B2=1> struct matrix: public array<array<T,N1,B1>,N2,B2> {
enum { sz1 = N1, sz2=N2, sz0=N1*N2 };
@@ -16,7 +16,7 @@ int main() {
array <int, 5, 1> const b1 = {{10,20,30,40,50}}; // index starts from 1
array <int, 5, -2> an = *new array <int, 5, -2>; // test new
for (int i = a1.ibegin(); i < a1.iend(); ++i) { cout << format("i=%d a1[i]=%d") %i % (a1[i]) << endl; };
for (int i = a1.ibegin(); i < a1.iend(); ++i) { cout << "i=" << i << " a1[i]=" << a1[i] << endl; };
cout << "\n array op= array \n";
@@ -36,7 +36,7 @@ int main() {
cout << "\n array op= array \n";
cout << "a1+=b1 " << (a1 += b1)<< endl;
cout << "-a1 " << -a1 << endl;
//cout << "-a1 " << -a1 << endl;
// vector ops
@@ -66,10 +66,12 @@ int main() {
cout << endl;
*/
/*
{
cout << "\narray input test, type three whole number\n";
array<int, 3> A;
cin >> A;
cout << "got from input: " << A << endl;
}
*/
}

0 comments on commit 0f139a0

Please sign in to comment.