#include <string>
#include <iostream>
struct StratA {
enum gender { male, female, unknown };
double price(std::string name, int age, gender g) const
{ return 42; }
};
struct StratB {
double price(int age, int volume, double historic_rate) const
{ return (age*age*historic_rate)/volume; }
};
template <typename PricingStrategy=StratA>
struct SomeEngine
{
template <typename... Args>
void doSomethingInvolvingPricing(std::string logmessage,
Args... args) // involving pricing
{
std::cout << logmessage << ": " << PricingStrategy().price(std::forward<Args>(args)...) << '\n';
}
};
int main()
{
SomeEngine<>().doSomethingInvolvingPricing("default", "name", 18, StratA::female);
SomeEngine<StratB>().doSomethingInvolvingPricing("overridden", 18, 3000, 4.5);
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IFN0cmF0QSB7CiAgICBlbnVtIGdlbmRlciB7IG1hbGUsIGZlbWFsZSwgdW5rbm93biB9OwogICAgZG91YmxlIHByaWNlKHN0ZDo6c3RyaW5nIG5hbWUsIGludCBhZ2UsIGdlbmRlciBnKSBjb25zdAogICAgeyByZXR1cm4gNDI7IH0KfTsKCnN0cnVjdCBTdHJhdEIgewogICAgZG91YmxlIHByaWNlKGludCBhZ2UsIGludCB2b2x1bWUsIGRvdWJsZSBoaXN0b3JpY19yYXRlKSBjb25zdAogICAgeyByZXR1cm4gKGFnZSphZ2UqaGlzdG9yaWNfcmF0ZSkvdm9sdW1lOyB9Cn07Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgUHJpY2luZ1N0cmF0ZWd5PVN0cmF0QT4Kc3RydWN0IFNvbWVFbmdpbmUKewogICAgdGVtcGxhdGUgPHR5cGVuYW1lLi4uIEFyZ3M+CiAgICB2b2lkIGRvU29tZXRoaW5nSW52b2x2aW5nUHJpY2luZyhzdGQ6OnN0cmluZyBsb2dtZXNzYWdlLAogICAgICAgICAgICBBcmdzLi4uIGFyZ3MpIC8vIGludm9sdmluZyBwcmljaW5nCiAgICB7CiAgICAgICAgc3RkOjpjb3V0IDw8IGxvZ21lc3NhZ2UgPD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