#include <iostream>
#include <functional>

struct interface {
	virtual int hello() = 0;
};

struct implementation : public interface {
	virtual int hello() {
		std::cout << "hello()\n";
		return 42;
	}
	~implementation() {
		std::cout << "~implementation()\n";
	}
};

struct adapter {
	interface* obj;
	
	adapter(std::function<int()>&& func) {
		struct lambda : public interface {
			std::function<int()> func;
			lambda(std::function<int()> func_): func(func_) { }
			virtual int hello() {
				return this->func();
			}
		};
		this->obj = new lambda{func};
	}
	
	adapter(interface&& impl) {
		this->obj = &impl;
	}
};

int main() {
	adapter a([]() { std::cout << "hello from lambda\n"; return 99; });
	a.obj->hello();
	
	adapter b{implementation()};
	b.obj->hello();

	return 0;
}