#include <iostream>
#include <vector>
#include <memory>
#include <string>
#include <algorithm>
template<typename T>
class Container {
private:
std::vector<T> data;
public:
void add(const T& item) {
data.push_back(item);
}
T get(size_t index) const {
return data.at(index);
}
size_t size() const {
return data.size();
}
};
class Shape {
public:
virtual ~Shape() = default;
virtual double area() const = 0;
virtual std::string name() const = 0;
};
class Rectangle : public Shape {
private:
double width, height;
public:
Rectangle(double w, double h) : width(w), height(h) {}
double area() const override {
return width * height;
}
std::string name() const override {
return "Rectangle";
}
};
void modern_cpp_features() {
auto rectangle = std::make_unique<Rectangle>(10.0, 5.0);
std::vector<int> numbers = {1, 2, 3, 4, 5};
for (const auto& num : numbers) {
std::cout << num << " ";
}
std::cout << std::endl;
auto lambda = [](int x) { return x * x; };
std::cout << "Square of 5: " << lambda(5) << std::endl;
std::string str1 = "Hello";
std::string str2 = std::move(str1);
}
namespace Math {
constexpr double PI = 3.14159265359;
template<typename T>
T max(T a, T b) {
return (a > b) ? a : b;
}
}
enum class Color {
Red,
Green,
Blue
};
int main() {
Container<int> intContainer;
intContainer.add(42);
intContainer.add(17);
std::cout << "Container size: " << intContainer.size() << std::endl;
modern_cpp_features();
return 0;
}