add iterable

This commit is contained in:
2025-07-28 17:03:05 +07:00
parent 765bfc3502
commit 40557c03b4
7 changed files with 199 additions and 23 deletions
+38
View File
@@ -0,0 +1,38 @@
#include <iostream>
#include "main.h"
template<typename T>
class Wrapper {
T* impl;
public:
Wrapper(T* obj) : impl(obj) {}
T* operator->() { return impl; }
const T* operator->() const { return impl; }
operator T*() { return impl; }
operator const T*() const { return impl; }
operator T&() { return *impl; }
operator const T&() const { return *impl; }
};
void render_shape_by_ptr(IShape* shape) {
shape->draw();
}
void render_shape_by_ref(IShape& shape) {
shape.draw();
}
int main() {
Circle circle {10};
Wrapper<IShape> wrapped(&circle);
std::cout << wrapped->area() << "\n";
render_shape_by_ptr(wrapped);
render_shape_by_ref(wrapped);
}