Skip to content
Snippets Groups Projects
mean_template_op_derived.cpp 1.14 KiB
Newer Older
#include <iostream>
#include <vector>
#include "functors.h"
#include "mean_template.h"

int main(){
  // Since C++11
	using data_type=int;
	using result_type=double;
	using sum_type=sum<data_type>;
	using multiply_type=multiply<data_type>;
	using divide_type=divide<result_type>;
	using nroot_type=nroot<result_type>;
	using arithmetic_type=mean_impl<data_type,result_type,sum_type,divide_type>;
	using geometrical_type=mean_impl<data_type,result_type,multiply_type,nroot_type,1>;
    using mean_type=mean<data_type,result_type>;
    using mean_container_type=std::vector<mean_type *>;

	arithmetic_type a;
	geometrical_type b;
    mean_container_type c;
    // Add mean into the container
    c.push_back(new arithmetic_type{});
    c.push_back(new geometrical_type{});

	data_type indata{};
	std::cout <<"Enter values [Ctrl-D to finish]: " <<std::endl;
	while(std::cin>>indata){
		a.add_data(indata);
		b.add_data(indata);
        for(auto & i: c) i->add_data(indata);
	}
	std::cout << " Arithmetic mean: " << a.get_mean() << "\n Geometrical mean: " << b.get_mean() << std::endl;
    for(const auto & i: c) i->print();
	return 0;
}