2022-08-04 17:13:06 +08:00
|
|
|
// tmp_policy
|
|
|
|
// Created by lucas on 22-7-26.
|
|
|
|
// Re-implementation of a typical policy architecture in C++ Template Meta-Programming.
|
|
|
|
|
2022-08-04 13:44:15 +08:00
|
|
|
#include <iostream>
|
2022-08-04 17:13:06 +08:00
|
|
|
#include "accumulator.h"
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2022-08-04 13:44:15 +08:00
|
|
|
|
|
|
|
int main() {
|
2022-08-04 17:13:06 +08:00
|
|
|
// Normal demo
|
|
|
|
std::vector<int> intVec;
|
|
|
|
intVec.reserve(10);
|
|
|
|
for (int i = 1; i <= 10; ++i)
|
|
|
|
intVec.push_back(i);
|
|
|
|
std::cout << Accumulator<PAdd, PAve, PResultTypeIs<int>>::eval(intVec) << std::endl;
|
|
|
|
std::cout << Accumulator<PAve, PAdd, PResultTypeIs<int>>::eval(intVec) << std::endl;
|
|
|
|
std::cout << Accumulator<PAdd, PNoAve, PResultTypeIs<int>>::eval(intVec) << std::endl;
|
|
|
|
std::cout << Accumulator<>::eval(intVec) << std::endl;
|
|
|
|
std::cout << Accumulator<PMul, PNoAve>::eval(intVec) << std::endl;
|
|
|
|
std::cout << Accumulator<PAve>::eval(intVec) << std::endl;
|
|
|
|
// Punchline (gusha)
|
|
|
|
std::vector<std::string> strVec;
|
|
|
|
for (int i = 1; i <= 10; ++i)
|
|
|
|
strVec.emplace_back("Today is KFC crazy Thursday V me ¥50\n");
|
|
|
|
std::cout << Accumulator<PAdd, PNoAve, PResultTypeIs<std::string>>::eval(strVec) << std::endl;
|
2022-08-04 13:44:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|