From a93270968f9aab5d8c1c528daf02c8b27d09eed7 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 4 Apr 2022 11:04:41 +0200 Subject: refactor: fix compiler errors with libc++ --- src/bootstrap.cpp | 8 +------- src/engine/user/cursor.hpp | 2 +- src/engine/user/input.hpp | 1 + src/game_of_life.cpp | 4 ++-- src/interfaces/randomization.hpp | 4 +--- src/randomization/seed_generator.cpp | 10 ++-------- src/randomization/seed_generator.hpp | 12 ++++++------ 7 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index f22c689..276b73a 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -56,6 +56,7 @@ auto bootstrap() noexcept -> Container container.bind().to(); container.bind().to(); container.bind().to(); + container.bind().to(); container.bind().to_factory(normalize_lambda( [&container](const std::shared_ptr &window, @@ -82,13 +83,6 @@ auto bootstrap() noexcept -> Container seed); }); - container.bind().to_factory( - []() - { - return construct_as_interface( - std::make_shared()); - }); - container.bind>().to_factory( [](const Bounds &bounds) { diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp index ccdf71a..fcdfd3b 100644 --- a/src/engine/user/cursor.hpp +++ b/src/engine/user/cursor.hpp @@ -5,11 +5,11 @@ #include "engine/data/vector2.hpp" -#include #include #include #include #include +#include constexpr std::string_view MOVE_CURSOR_UP = "{esc}[{amount}A"; constexpr std::string_view MOVE_CURSOR_DOWN = "{esc}[{amount}B"; diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp index 66b58c6..410f3a6 100644 --- a/src/engine/user/input.hpp +++ b/src/engine/user/input.hpp @@ -4,6 +4,7 @@ #include "interfaces/input.hpp" #include "interfaces/subscriber.hpp" +#include #include #include #include diff --git a/src/game_of_life.cpp b/src/game_of_life.cpp index 1daf5b8..098ec32 100644 --- a/src/game_of_life.cpp +++ b/src/game_of_life.cpp @@ -20,13 +20,13 @@ auto main(int argc, char *argv[]) noexcept -> int if (parsed_arguments.random_gen == nullptr) { - auto seed_generator_factory = container.get(); + auto seed_generator = container.get(); auto random_number_generator_factory = container.get(); parsed_arguments.random_gen = - random_number_generator_factory(seed_generator_factory()->random_seed()); + random_number_generator_factory(seed_generator->random_seed()); } auto engine = container.get(); diff --git a/src/interfaces/randomization.hpp b/src/interfaces/randomization.hpp index eb8bd30..8b1631c 100644 --- a/src/interfaces/randomization.hpp +++ b/src/interfaces/randomization.hpp @@ -8,11 +8,9 @@ class ISeedGenerator public: virtual ~ISeedGenerator() noexcept = default; - [[nodiscard]] virtual auto random_seed() const noexcept -> uint32_t = 0; + [[nodiscard]] virtual auto random_seed() noexcept -> uint32_t = 0; }; -using ISeedGeneratorFactory = std::shared_ptr (*)(); - // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class IRandomNumberGenerator { diff --git a/src/randomization/seed_generator.cpp b/src/randomization/seed_generator.cpp index 5aedf17..a0f9303 100644 --- a/src/randomization/seed_generator.cpp +++ b/src/randomization/seed_generator.cpp @@ -1,12 +1,6 @@ #include "seed_generator.hpp" -SeedGenerator::SeedGenerator( - const std::shared_ptr &random_device) noexcept - : _random_device(random_device) +auto SeedGenerator::random_seed() noexcept -> uint32_t { -} - -auto SeedGenerator::random_seed() const noexcept -> uint32_t -{ - return (*_random_device)(); + return _random_device(); } diff --git a/src/randomization/seed_generator.hpp b/src/randomization/seed_generator.hpp index 2439949..71fd089 100644 --- a/src/randomization/seed_generator.hpp +++ b/src/randomization/seed_generator.hpp @@ -1,18 +1,18 @@ #pragma once +#include "DI/auto_wirable.hpp" #include "interfaces/randomization.hpp" -#include #include -class SeedGenerator : public ISeedGenerator +class SeedGenerator : public ISeedGenerator, + public AutoWirable { public: - explicit SeedGenerator( - const std::shared_ptr &random_device) noexcept; + SeedGenerator() noexcept = default; - [[nodiscard]] auto random_seed() const noexcept -> uint32_t override; + [[nodiscard]] auto random_seed() noexcept -> uint32_t override; private: - const std::shared_ptr &_random_device; + std::random_device _random_device; }; -- cgit v1.2.3-18-g5258