我有几种使用策略创建的类型,即
template <typename PolicyA, typename PolicyB>
class BaseType : PolicyA, PolicyB
{};
struct MyPolicyA {};
struct MyPolicyB {};
struct OtherPolicyB {};
using SpecializedTypeX = BaseType<MyPolicyA, MyPolicyB>;
using SpecializedTypeY = BaseType<MyPolicyA, OtherPolicyB>;
现在我想介绍一些机制,它允许我根据来自例如命令行的输入优雅地选择应该使用哪个 SpecializedType。理想情况下,这将是一个创建适当类型对象的工厂方法,例如:
auto CreateSelectedSpecializedType(const std::string &key);
// selected has type SpecializedTypeX
auto selected = CreateSelectedSpecializedType("SpecializedTypeX");
我会很感激任何建议。谢谢!