From f4f91c53868ada9fa17aa9626da52968d5d6579c Mon Sep 17 00:00:00 2001 From: Alex Hirsch Date: Fri, 6 Nov 2020 01:32:43 +0100 Subject: [PATCH] Exercises: Add container operator task --- exercises/README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/exercises/README.md b/exercises/README.md index 1417101..af02941 100644 --- a/exercises/README.md +++ b/exercises/README.md @@ -103,3 +103,38 @@ Read [this blog post](https://www.gamedev.net/blogs/entry/2265481-oop-is-dead-lo - Pay attention to *implementation vs. interface inheritance* - Pay attention to the use of templates (assuming you've already covered them) - Think about the benefits and drawbacks of the used patterns + +## Task 08 + +You are given the following definition of a person: + +```cpp +struct Person { + std::string firstName; + std::string lastName; + int age; +}; +``` + +- Implement relational operators (`<`, `<=`, `>`, `>=`) +- Implement comparison operators (`==`, `!=`) + +Next, create 5 different instances and put all of them +- in an `std::vector`; +- in an `std::set`; and +- in an `std::map` as key (we don't care about the value type of the map). + +Use algorithms from the standard library, like `std::find` and `std::partition` on these containers and examine which operators are used. + +*Hint:* You may want to have a look at `std::tie`. + +## Task 09 + +Reuse `Person` from Task 08 and implement the necessary parts for inserting it into an `std::unordered_set`. + +Compare the performance of: + +- `std::vector` +- `std::list` +- `std::set` +- `std::unordered_set`