{"id":20564783,"url":"https://github.com/dinhtap/exception-safe-stack","last_synced_at":"2025-09-21T23:09:24.729Z","repository":{"id":225906283,"uuid":"767177250","full_name":"dinhtap/exception-safe-stack","owner":"dinhtap","description":"A stack with exception safety and memory management with smart pointers","archived":false,"fork":false,"pushed_at":"2024-03-04T22:10:09.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T08:35:08.260Z","etag":null,"topics":["exception-handling","smart-pointers"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dinhtap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-04T20:50:38.000Z","updated_at":"2024-03-05T23:37:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"e34502ea-5003-4ea3-ae14-ad98dcd3f6bc","html_url":"https://github.com/dinhtap/exception-safe-stack","commit_stats":null,"previous_names":["dinhtap/exception-safe-stack"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dinhtap/exception-safe-stack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinhtap%2Fexception-safe-stack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinhtap%2Fexception-safe-stack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinhtap%2Fexception-safe-stack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinhtap%2Fexception-safe-stack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dinhtap","download_url":"https://codeload.github.com/dinhtap/exception-safe-stack/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dinhtap%2Fexception-safe-stack/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276318992,"owners_count":25621652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-21T02:00:07.055Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["exception-handling","smart-pointers"],"created_at":"2024-11-16T04:28:58.186Z","updated_at":"2025-09-21T23:09:24.721Z","avatar_url":"https://github.com/dinhtap.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enhanced exception-safe stack\nA C++ programming course project regarding exception safety and memory management with smart pointers.\n\n## Problem statement\nThe goal of this project is to implement a container template behaving like a stack where each element consists of a (key, value) pair. The container must provide a strong exception guarantee and realize the copy-on-write semantics.\n\nThe template is to be parametrized by the key and value types, named `K` and `V` accordingly. The key type `K` has value semantics (provides a default constructor, copy constructor, move constructor, and assignment operators). A linear order is defined on `K` and objects of that type can be freely compared. Type `V` only guarantees a copy constructor.\n\nThe class `stack` must be visible in a `cxx` namespace and have the following declaration:\n```c++\nnamespace cxx {\n  template \u003ctypename K, typename V\u003e class stack;\n}\n```\n\nThe class has to offer all of the operations described below. Time complexities apply only to cases when no copy is created. Time complexity of copying is `O(n log n)`, where `n` is the number of elements on the stack. All operations must provide a strong exception guarantee, the move constructor and the desctructor must not throw.\n\n- Constructors. Time complexity `O(1)`.\n```c++\n  stack();\n  stack(stack const \u0026);\n  stack(stack \u0026\u0026);\n```\n- Assignment operator, Time complexity `O(1)` plus the time of destroying the overriden object.\n```c++\n  stack \u0026 operator=(stack);\n```\n- Push method. Time complexity `O(log n)`.\n```c++\n  void push(K const \u0026, V const \u0026);\n```\n- Pop method. If the stack is empty, `std::invalid_argument` should be thrown. Time complexity `O(log n)`.\n```c++\n  void pop();\n```\n- Pop method with a key parameter. Pops the closest element with the given key. If the stack is empty, `std::invalid_argument` should be thrown. Time complexity `O(log n)`.\n```c++\n  void pop(K const \u0026);\n```\n- Front methods returning a pair of references to the key and value on the top of the stack. In the non-const version the pair should allow for modifying the value, but not the key. A modifying operation on the stack might invalidate the returned references. If the stack is empty, `std::invalid_argument` should be thrown. Time complexity `O(1)`.\n```c++\n  std::pair\u003cK const \u0026, V \u0026\u003e front();\n  std::pair\u003cK const \u0026, V const \u0026\u003e front() const;\n```\n- Front methods with a key parameter. Returns the closest value with the given key. Details as above. Time complexity `O(log n)`.\n```c++\n  V \u0026 front(K const \u0026);\n  V const \u0026 front(K const \u0026) const;\n```\n- Size method. Time complexity `O(1)`.\n```c++\n  size_t size() const;\n```\n- Count method returning the number of elements with the given key. Time complexity `O(log n)`.\n```c++\n  size_t count(K const \u0026) const;\n```\n- Clear method removing all elements from the stack. Time complexity `O(n)`.\n```c++\n  void clear();\n```\n- Iterator `const_iterator`, `cbegin`, `cend` methods on the stack, and assignment operators, comparisons (`==`, `!=`), incrementation (both prefix and postfix), dereferencing (`*`, `-\u003e`) allowing for looping through the key set in their increasing order. The iterator must satisfy the `std::forward_iterator` concept. All operations in `O(log n)`. Looping through all the keys in `O(n)`. The iterator should behave like a `const_iterator` from the standard library.\n\nThe methods should be declared `const` and `noexcept` wherever possible and reasonable.\n\nAn object of type `stack` should only keep one copy of the inserted keys and values. Storing copies of equal keys is forbidden.\n\nAn example use can be viewed in `stack_example.cc`.\n\n## Formal requirements\nThe solution will be compiled on the `students` machine with the following command:\n```bash\ng++ -Wall -Wextra -O2 -std=c++20 *.cc\n```\nCredit to my friend at college for translating this readme to English [Nikodem Gapski](https://github.com/NikodemGapski)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdinhtap%2Fexception-safe-stack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdinhtap%2Fexception-safe-stack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdinhtap%2Fexception-safe-stack/lists"}