tmp-policy/main.cpp

29 lines
1.1 KiB
C++

// tmp_policy
// Created by lucas on 22-7-26.
// Re-implementation of a typical policy architecture in C++ Template Meta-Programming.
#include <iostream>
#include "accumulator.h"
#include <vector>
#include <string>
int main() {
// 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;
return 0;
}