From a164593cd85e7159929a4a530df1634b6eadc3ff Mon Sep 17 00:00:00 2001 From: Pcornat Date: Thu, 29 Feb 2024 12:23:30 +0100 Subject: [PATCH] Using svector --- include/billy_objects.hpp | 8 +++----- src/billy_objects.cpp | 11 +++++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/billy_objects.hpp b/include/billy_objects.hpp index fddfa07..5b9b9c7 100644 --- a/include/billy_objects.hpp +++ b/include/billy_objects.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "characteristic/characteristic.hpp" // helper type for the visitor @@ -45,7 +46,7 @@ namespace character { class BillyObjects final { public: using billyObject = std::variant; - using container = std::array; + using container = ankerl::svector; static constexpr std::string_view sword{ "Sword" }; static constexpr std::string_view lance{ "Lance" }; @@ -68,9 +69,7 @@ namespace character { void pop_object(CharacterSheet &sheet) noexcept; - [[nodiscard]] std::pair get_objects() const noexcept { - return { objects, end_object }; - } + [[nodiscard]] const container &get_objects() const noexcept { return objects; } // void insert_weapon(weapons weapon, CharacterSheet &sheet) noexcept; @@ -78,7 +77,6 @@ namespace character { container objects; std::plus plus; std::minus minus; - std::uint8_t end_object{ 0 }; static void change_carac_weapon(const weapons &arg, CharacterSheet &sheet, diff --git a/src/billy_objects.cpp b/src/billy_objects.cpp index 36c2bb7..ad4146e 100644 --- a/src/billy_objects.cpp +++ b/src/billy_objects.cpp @@ -9,9 +9,8 @@ namespace character { using characteristic::Characteristic; void BillyObjects::push_object(const billyObject &object, CharacterSheet &sheet) noexcept { - if (end_object < 3) { - objects.at(end_object) = object; - ++end_object; + if (objects.size() < 3) { + objects.emplace_back(object); auto &local_habilete = static_cast(sheet.habilete); auto &local_adresse = static_cast(sheet.adresse); @@ -49,9 +48,9 @@ namespace character { } void BillyObjects::pop_object(CharacterSheet &sheet) noexcept { - if (end_object > 0) { - const auto &obj = objects.at(end_object - 1); - --end_object; + if (!objects.empty()) { + const billyObject obj = objects.back(); + objects.pop_back(); auto &local_habilete = static_cast(sheet.habilete); auto &local_adresse = static_cast(sheet.adresse);