Category : C++ Source Code
Archive   : BLFMATH.ZIP
Filename : TSTVEC.CPP
// tstvec.cpp: Vector test program using integer vector math.
// Copyright(c) 1993 Azarona Software. All rights reserved.
///////////////////////////////////////////////////////////////
#include
#include "vector.h"
//
// Some sample vector math routines
//
template
void operator+=(Vector
// Adds x to every element of v.
// ASSUMES TYPE has '+=' defined.
{
VecPtr
for (unsigned i = 0; i
elemptr++;
}
}
template
void Add(Vector
// Adds vectors a and b together, storing result in r.
// The number of elements added is determined by the
// shortest length of all three vectors.
// ASSUMES that TYPE has '+' defined.
{
unsigned rlen = r.Length();
unsigned slen = a.Length();
if (rlen > slen) rlen = slen;
slen = b.Length();
if (rlen > slen) rlen = slen;
VecPtr
VecPtr
VecPtr
for (unsigned i = 0; i
rptr++;
aptr++;
bptr++;
}
}
template
Vector
// Adds vectors a and b together, returning the result (which
// has its data allocated on the heap.) The number of elements
// created is determined by the shortest length a and b.
{
unsigned rlen = a.Length();
unsigned slen = b.Length();
if (rlen > slen) rlen = slen;
Vector
Add(result, a, b);
return result;
}
template
void PrtVec(const Vector
// Print out the elements of a vector
{
VecPtr
unsigned i, len = v.Length();
for (i = 0; i
cursor++;
}
cout << '\n';
}
// BC++ needs the next statements, which generate functions
// for doing operations on vectors
void Add(Vector
void operator+=(Vector
void PrtVec(const Vector
// You need one of these statements for each type of vector:
INITNULLVEC(int);
// A low-level C array we'll copy
const int arr_size = 7;
int arr[arr_size] = {0, 1, 2, 3, 4, 5, 6};
void test()
{
cout << "Creating a vector\n";
Vector
cout << "myvec: "; PrtVec(myvec);
cout << "Creating a shared slice of every other element\n";
Vector
cout << "everyother: "; PrtVec(everyother);
cout << "Creating a copied slice of every other element\n";
Vector
cout << "cpslice: "; PrtVec(cpslice);
cout << "Adding 10 to every other element\n";
everyother += 10;
cout << "myvec: "; PrtVec(myvec);
cout << "everyother: "; PrtVec(everyother);
cout << "cpslice: "; PrtVec(cpslice);
cout << "Adding all odd elements to even elements\n";
Vector
Vector
cout << "Result: "; PrtVec(odd + even);
cout << "myvec: "; PrtVec(myvec);
cout << "Testing consistency checks for stride, length, and offset\n";
Vector
cout << "everyother: "; PrtVec(everyother);
cout << "tstslice: "; PrtVec(tstslice);
}
main()
{
test();
return 0;
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/