I would like to have a class, let's say a queue, that can be specialized to its behavior. For example, let them be a SafeQueue (which disables IRQs before any access) and a FastQueue (which doesn't). As you see, the vast majority of the common code would be just the queue itself.
Please tell me what you think about the below implementation. Is it something you would expect to see in the codebase? Is there a better/standard solution?
struct IrqGuard { IrqGuard(){fmt::print("Disable IRQ\n");} ~IrqGuard(){fmt::print("Enable IRQ\n");} }; struct NoGuard { }; template<typename T, typename GuardT> struct BaseQueue { bool push(T val) { [[maybe_unused]] GuardT guard; fmt::print("Pushing {}\n", val); return true; } }; template<typename T> struct SafeQueue : public BaseQueue<T, IrqGuard>{}; template<typename T> struct FastQueue : public BaseQueue<T, NoGuard>{}; Example usage: https://godbolt.org/z/rjnYr4Weq