我编写了以下定义一些策略类的特征:
namespace memory
{
struct on_RAM
{
template<typename T>
using pop_sizes_type = PopulationSizeOnRAMImplementation<T>;
template<typename T>
using flow_type = FlowOnRAMImplementation<T>;
};
struct on_disk
{
template<typename T>
using pop_sizes_type = PopulationSizeOnDiskImplementation<T>;
template<typename T>
using flow_type = FlowOnDiskImplementation<T>;
};
} // end namespace memory
我使用这些特征来配置模拟类的行为:MyClass<memory::on_RAM>
或MyClass<memory::on_disk>
Eveything 工作正常,但我希望结果程序的用户能够选择或其他替代方案,而无需修改源代码。
我想我可以通过为 CMake 提供一个选项来要求他们覆盖默认实现,这可以将其提供给编译器,这可以做出一些编译时选择。但我不知道如何在技术上实现它。有什么建议吗?