Umístění: ./labs/10-aggregator/
Čas: 20 minut
Navrhněte a implementujte šablonu třídy která bude sčítat všechny předané hodnoty. Následuje příklad použití třídy.
Aggregator<int> numbers;
numbers += 1;
numbers += 2;
std::cout << numbers.value() << std::endl; // 3
Aggregator<std::string> strings;
strings += "a";
strings += "b";
std::cout << strings.value() << std::endl; // ab
Umístění: ./labs/10-vector/
Čas: N/A
Vytvořte generické gumové pole jako kontejner, který zachovává pořadí vložených prvků. Pro vnitřní organizaci prvků využijte vektor unikátních ukazatelů (std::unique_ptr) na pole prvků. Jednotlivá pole prvků mají fixní velikost danou jako kompilační argument.
Zadání úlohy pokračuje na dalším slajdu.
Řešení musí implementovat následující funkce:
Volitelně funkce pop_back - odebere poslední prvek pokud existuje. Toto vyžaduje volání "destruktoru", což není úplně běžné, ale možné. Pro třídu Observer a proměnou instance je syntaxe: instance.~Observer();
Pár dalších věcí:
struct Observer {
int index;
Observer() : index(-1) { std::cout << "ctor -1" << std::endl; }
Observer(int index_) : index(index_) { std::cout << "ctor " << index << std::endl; }
// Rule of five.
Observer(const Observer& other) : index(other.index) { std::cout << "copy " << index << std::endl; }
Observer(Observer&& other) noexcept : index(other.index) { other.index = -1; std::cout << "move " << index << std::endl; }
void operator=(const Observer& other) { index = other.index; std::cout << "= copy " << index << std::endl; }
void operator=(Observer&& other) noexcept { index = other.index; other.index = -1; std::cout << "= move " << index << std::endl; }
~Observer() { std::cout << "dtor " << index << std::endl; }
};