Возможные реализации для решения конкретных задач
Adapter
Шаблонный адаптер
# include <iostream>
# include <memory>
# include <vector>
using namespace std;class Interface
{
public:
virtual ~Interface() = default;
virtual void request() = 0;
};template <typename Type>
class Adapter : public Interface
{
public:
using MethodPtr = void (Type::*)();
Adapter(shared_ptr<Type> o, MethodPtr m) : object(o), method(m) {}
void request() override
{
((*object).*method)();
}
private:
shared_ptr<Type> object;
MethodPtr method;
};int main()
{
auto v = initialize();
for (const auto& elem : v)
elem->request();
}Last updated