From 0f60b23b33ac1b2428bcc54e89aeeb1e8e67c048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Tue, 21 Jan 2025 14:03:40 +0100 Subject: [PATCH] Change constants methods to static constexpr --- include/aoc/GuardGallivant.hpp | 8 ++++---- include/aoc/HoofIt.hpp | 4 ++-- include/aoc/PrintQueue.hpp | 4 ++-- src/GuardGallivant.cpp | 8 ++++---- src/HoofIt.cpp | 4 ++-- src/PrintQueue.cpp | 14 ++++++++++++-- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/include/aoc/GuardGallivant.hpp b/include/aoc/GuardGallivant.hpp index fdd8110..b0ef5df 100644 --- a/include/aoc/GuardGallivant.hpp +++ b/include/aoc/GuardGallivant.hpp @@ -26,11 +26,11 @@ class GuardGallivant virtual void processDataLine(const std::string& line) override; virtual void finish() override; private: + static constexpr size_t getStartDirectionIndex(); + static constexpr char getStartChar(); + static constexpr char getVisitedChar(); + static constexpr char getObstructionChar(); Point2 start_{}; - const size_t getStartDirectionIndex() const; - const char getStartChar() const; - const char getVisitedChar() const; - const char getObstructionChar() const; void visitPosition(const Point2& current); size_t turnDirection(const size_t current) const; }; diff --git a/include/aoc/HoofIt.hpp b/include/aoc/HoofIt.hpp index 5735c43..218ae9a 100644 --- a/include/aoc/HoofIt.hpp +++ b/include/aoc/HoofIt.hpp @@ -28,7 +28,7 @@ class HoofIt virtual const std::string getInputFileName() const override; virtual void finish() override; private: - const char getTrailheadChar() const; - const char getTrailTopChar() const; + static constexpr char getTrailheadChar(); + static constexpr char getTrailTopChar(); void addUnique(const std::vector& source, std::vector& destination); }; diff --git a/include/aoc/PrintQueue.hpp b/include/aoc/PrintQueue.hpp index 91811a7..bd1af24 100644 --- a/include/aoc/PrintQueue.hpp +++ b/include/aoc/PrintQueue.hpp @@ -30,8 +30,8 @@ class PrintQueue virtual void processDataLine(const std::string& line) override; virtual void finish() override; private: - static const int nPages_{ 49 }; - static const int maxPageNo_{ 99 }; + static constexpr int getNPages(); + static constexpr int getMaxPageNo(); bool isProcessingOrderingRules_; int pageNoMapIndex_; std::vector pageNoMap_; diff --git a/src/GuardGallivant.cpp b/src/GuardGallivant.cpp index d8bbbb9..b7cb5ac 100644 --- a/src/GuardGallivant.cpp +++ b/src/GuardGallivant.cpp @@ -56,22 +56,22 @@ void GuardGallivant::finish() } } -const size_t GuardGallivant::getStartDirectionIndex() const +constexpr size_t GuardGallivant::getStartDirectionIndex() { return 2; } -const char GuardGallivant::getStartChar() const +constexpr char GuardGallivant::getStartChar() { return '^'; } -const char GuardGallivant::getVisitedChar() const +constexpr char GuardGallivant::getVisitedChar() { return 'X'; } -const char GuardGallivant::getObstructionChar() const +constexpr char GuardGallivant::getObstructionChar() { return '#'; } diff --git a/src/HoofIt.cpp b/src/HoofIt.cpp index 634894b..e6f5d1a 100644 --- a/src/HoofIt.cpp +++ b/src/HoofIt.cpp @@ -81,12 +81,12 @@ void HoofIt::finish() } } -const char HoofIt::getTrailheadChar() const +constexpr char HoofIt::getTrailheadChar() { return '0'; } -const char HoofIt::getTrailTopChar() const +constexpr char HoofIt::getTrailTopChar() { return '9'; } diff --git a/src/PrintQueue.cpp b/src/PrintQueue.cpp index 75e4098..e2fdfa8 100644 --- a/src/PrintQueue.cpp +++ b/src/PrintQueue.cpp @@ -20,8 +20,8 @@ #include PrintQueue::PrintQueue() - : Solver{}, isProcessingOrderingRules_{ true }, pageNoMapIndex_{ 0 }, pageNoMap_(maxPageNo_ + 1, -1), - orderingRules_(nPages_, nPages_) + : Solver{}, isProcessingOrderingRules_{ true }, pageNoMapIndex_{ 0 }, pageNoMap_(getMaxPageNo() + 1, -1), + orderingRules_(getNPages(), getNPages()) { orderingRules_.fill(false); } @@ -59,6 +59,16 @@ void PrintQueue::finish() { } +constexpr int PrintQueue::getNPages() +{ + return 49; +} + +constexpr int PrintQueue::getMaxPageNo() +{ + return 99; +} + size_t PrintQueue::getMapped(const int pageNo) { if (pageNoMap_[pageNo] < 0)