Exemplo n.º 1
0
int main()
{
	Sum A(5);
	Sum B(3);
	Sum D(1);	 
	Sum c;
	c = A + B + D;
	c.out();

	return 0;
}
Exemplo n.º 2
0
int main() {

  IOperation * firstArgument = new Numbers(7),
             * secondArgument = new Numbers(3);

    Sum * sum = new Sum(firstArgument, secondArgument);

    sum->toString();
  std::cout << sum->firstArgument() << "\n";

    return 0;
}
Exemplo n.º 3
0
void TestVolumeStoreImpl::testAccept()
{
	Volume::Handle v = VolumeUS::load("structural");
	Volume::Handle c = v;
	Sum sum;
	v->accept(sum);
	
	float total = sum.total();
	int count = sum.count();

	assert(count == v->inqX() * v->inqY() * v->inqZ());

	Volume::Handle d = c;
}
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
    vector<int> v(10,5); // 10 copies of 5

    
    // sum of all elements of v
    Sum<int> s;
    s = for_each(v.begin(), v.end(), s);
    cout << "the sum is " << s.result() << '\n';




    return 0;
}
Exemplo n.º 5
0
void f(list<double>& ls)
{
	Sum<double> sum;
	sum = for_each(ls.begin((), ls.end(), sum);	// 对表中每一个元素调用sum()函数对象
	cout << "the sum is " << sum.result() << endl;
}
Exemplo n.º 6
0
 std::string
 show(const Sum<T> &t) override
 {
     return type_name<Sum<T>>() + ' ' + show(t.value());
 }
Exemplo n.º 7
0
static bool testZeroApply (Field1 &F1, Field2 &F2, VectorStream<Vector> &stream1, VectorStream<Vector> &stream2)
{
	commentator().start ("Testing zero apply", "testZeroApply", stream1.m ());

	bool ret = true;
	bool iter_passed = true;

	Vector d1, d2, v, w, zero;
	VectorDomain<Field1> VD (F1);
	typename Field1::Element neg_one;

	VectorWrapper::ensureDim (zero, stream1.dim ());
	VectorWrapper::ensureDim (d1, stream1.dim ());
	VectorWrapper::ensureDim (d2, stream1.dim ());
	VectorWrapper::ensureDim (v, stream1.dim ());
	VectorWrapper::ensureDim (w, stream2.dim ());
// 	F.init (neg_one, 1);
// 	F.negin (neg_one);
	F1.init (neg_one, -1);

	while (stream1) {
		commentator().startIteration ((unsigned)stream1.j ());
		iter_passed = true;

		stream1.next (d1);
		VD.mul (d2, d1, neg_one);

		Diagonal <Field1> D1 (F1, d1), D2 (F1, d2);

		Sum <Diagonal<Field1>,Diagonal <Field1> > A (&D1, &D2);

		ostream &report = commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_DESCRIPTION);
		report << "Diagonal matrix:  ";
		VD.write (report, d1);
		report << endl;

		report << "Negative diagonal matrix:  ";
		VD.write (report, d2);
		report << endl;

		stream2.reset ();

		while (stream2) {
			stream2.next (w);

			report << "Input vector:  ";
			VD.write (report, w);
			report << endl;

			A.apply (v, w);

			report << "Output vector:  ";
			VD.write (report, v);
			report << endl;

			if (!VD.isZero (v))
				ret = iter_passed = false;
		}

		if (!iter_passed)
			commentator().report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR)
				<< "ERROR: Vector is not zero" << endl;

		commentator().stop ("done");
		commentator().progress ();

                ret = ret && testBBrebind(F2, A);

	}

	commentator().stop (MSG_STATUS (ret), (const char *) 0, "testZeroApply");

	return ret;
}
Exemplo n.º 8
0
int exampleSum(int sum1, int sum2){
    Sum sum;
    return sum.testsum(sum1, sum2);
}