From 22379375169649cce18c3f99a9e09381afb3a62f Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Mon, 15 Jun 2026 15:44:43 +0200 Subject: [PATCH] Replace `boost::optional` by `std::optional` --- extras/ai-battle/main.cpp | 12 ++++++-- libs/common/include/helpers/OptionalEnum.h | 7 ++--- libs/common/include/helpers/optional_io.h | 29 +++++++++++++++++++ libs/s25main/BuildingRegister.cpp | 4 +-- libs/s25main/EconomyModeHandler.cpp | 4 +-- libs/s25main/Game.cpp | 4 +-- libs/s25main/GameManager.h | 4 +-- libs/s25main/Pathfinding.cpp | 8 ++--- libs/s25main/Settings.cpp | 6 ++-- libs/s25main/Settings.h | 4 +-- libs/s25main/Timer.cpp | 2 +- libs/s25main/Timer.h | 4 +-- libs/s25main/Window.h | 14 ++++----- libs/s25main/addons/AddonList.cpp | 2 +- libs/s25main/ai/AIInterface.h | 2 +- libs/s25main/ai/aijh/AIConstruction.cpp | 6 ++-- libs/s25main/ai/aijh/AIPlayerJH.cpp | 6 ++-- libs/s25main/buildings/nobBaseMilitary.cpp | 2 +- libs/s25main/buildings/nobBaseWarehouse.cpp | 4 +-- libs/s25main/controls/ctrlComboBox.cpp | 6 ++-- libs/s25main/controls/ctrlComboBox.h | 4 +-- libs/s25main/controls/ctrlGroup.cpp | 12 ++++---- libs/s25main/controls/ctrlGroup.h | 12 ++++---- libs/s25main/controls/ctrlList.cpp | 12 ++++---- libs/s25main/controls/ctrlList.h | 12 ++++---- libs/s25main/controls/ctrlOptionGroup.cpp | 4 +-- libs/s25main/controls/ctrlOptionGroup.h | 4 +-- libs/s25main/controls/ctrlTab.cpp | 6 ++-- libs/s25main/controls/ctrlTab.h | 6 ++-- libs/s25main/controls/ctrlTable.cpp | 12 ++++---- libs/s25main/controls/ctrlTable.h | 10 +++---- .../s25main/desktops/dskCampaignSelection.cpp | 2 +- libs/s25main/desktops/dskCampaignSelection.h | 2 +- libs/s25main/desktops/dskGameLobby.cpp | 8 ++--- libs/s25main/desktops/dskLobby.cpp | 2 +- libs/s25main/desktops/dskLobby.h | 2 +- libs/s25main/desktops/dskOptions.cpp | 2 +- libs/s25main/desktops/dskSelectMap.cpp | 4 +-- libs/s25main/desktops/dskSelectMap.h | 2 +- libs/s25main/figures/nofAggressiveDefender.h | 1 + libs/s25main/figures/nofBuildingWorker.cpp | 6 ++-- libs/s25main/figures/nofCarrier.cpp | 2 +- libs/s25main/figures/nofDefender.h | 1 + libs/s25main/figures/nofDonkeybreeder.cpp | 2 +- libs/s25main/figures/nofFarmer.cpp | 2 +- libs/s25main/figures/nofFisher.cpp | 2 +- libs/s25main/figures/nofGeologist.cpp | 4 +-- libs/s25main/figures/nofHunter.cpp | 2 +- libs/s25main/figures/nofMetalworker.cpp | 6 ++-- libs/s25main/figures/nofWarehouseWorker.cpp | 2 +- libs/s25main/figures/nofWinegrower.cpp | 2 +- libs/s25main/gameData/BuildingConsts.h | 10 +++---- libs/s25main/gameData/JobConsts.h | 4 +-- libs/s25main/gameTypes/BuildingTypes.h | 4 +-- libs/s25main/gameTypes/MapDescription.cpp | 2 +- libs/s25main/gameTypes/MapDescription.h | 6 ++-- libs/s25main/ingameWindows/iwBuilding.cpp | 2 +- libs/s25main/ingameWindows/iwDiplomacy.cpp | 4 +-- .../ingameWindows/iwDirectIPConnect.cpp | 2 +- .../ingameWindows/iwDirectIPCreate.cpp | 2 +- libs/s25main/ingameWindows/iwMapDebug.cpp | 4 +-- libs/s25main/ingameWindows/iwMapGenerator.cpp | 6 ++-- libs/s25main/ingameWindows/iwSave.cpp | 2 +- libs/s25main/ingameWindows/iwSave.h | 2 +- libs/s25main/ingameWindows/iwSettings.cpp | 7 ++--- libs/s25main/ingameWindows/iwTrade.cpp | 2 +- libs/s25main/network/GameServer.cpp | 2 +- libs/s25main/nodeObjs/noAnimal.cpp | 4 +-- libs/s25main/pathfinding/RoadPathFinder.h | 2 +- libs/s25main/resources/ArchiveLocator.cpp | 6 ++-- libs/s25main/world/GameWorld.cpp | 2 +- libs/s25main/world/GameWorld.h | 2 +- libs/s25main/world/GameWorldBase.h | 4 +-- libs/s25main/world/TradeRoute.cpp | 4 +-- libs/s25main/world/TradeRoute.h | 2 +- tests/common/testOptionalEnum.cpp | 6 ++-- tests/s25Main/UI/testComboBox.cpp | 2 +- tests/s25Main/integration/testSettings.cpp | 4 +-- tests/s25Main/simple/testGameData.cpp | 2 +- 79 files changed, 208 insertions(+), 173 deletions(-) create mode 100644 libs/common/include/helpers/optional_io.h diff --git a/extras/ai-battle/main.cpp b/extras/ai-battle/main.cpp index cab8fd28de..e20a56143b 100644 --- a/extras/ai-battle/main.cpp +++ b/extras/ai-battle/main.cpp @@ -16,8 +16,14 @@ #include #include #include -#include #include +#if BOOST_VERSION >= 109000 +# include +using std::optional; +#else +# include +using boost::optional; +#endif namespace bnw = boost::nowide; namespace bfs = boost::filesystem; @@ -28,8 +34,8 @@ int main(int argc, char** argv) bnw::nowide_filesystem(); bnw::args _(argc, argv); - boost::optional replay_path; - boost::optional savegame_path; + optional replay_path; + optional savegame_path; unsigned random_init = static_cast(std::chrono::high_resolution_clock::now().time_since_epoch().count()); unsigned random_ai_init = random_init; diff --git a/libs/common/include/helpers/OptionalEnum.h b/libs/common/include/helpers/OptionalEnum.h index 4c74d6fc86..a0f3f4df1a 100644 --- a/libs/common/include/helpers/OptionalEnum.h +++ b/libs/common/include/helpers/OptionalEnum.h @@ -5,9 +5,8 @@ #pragma once #include "MaxEnumValue.h" -#include -#include #include +#include #include namespace helpers { @@ -26,7 +25,7 @@ class OptionalEnum using value_type = T; constexpr OptionalEnum() noexcept = default; - OptionalEnum(boost::none_t) noexcept {} + OptionalEnum(std::nullopt_t) noexcept {} constexpr OptionalEnum(const T& value) noexcept : value_(static_cast(value)) {} constexpr OptionalEnum& operator=(const T& value) noexcept { @@ -41,7 +40,7 @@ class OptionalEnum constexpr T value() const { if(!has_value()) - throw boost::bad_optional_access(); + throw std::bad_optional_access(); return **this; } constexpr T value_or(T default_value) const { return bool(*this) ? **this : default_value; } diff --git a/libs/common/include/helpers/optional_io.h b/libs/common/include/helpers/optional_io.h new file mode 100644 index 0000000000..e52c14ebab --- /dev/null +++ b/libs/common/include/helpers/optional_io.h @@ -0,0 +1,29 @@ +// Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org) +// +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include +#include + +template +inline std::basic_ostream& operator<<(std::basic_ostream& out, + std::optional const& v) +{ + return out << (v ? *v : "--"); +} +namespace boost::test_tools::tt_detail { +template +struct print_log_value> +{ + void operator()(std::ostream& os, std::optional const& v) + { + if(v) + os << *v; + else + os << ""; + } +}; +} // namespace boost::test_tools::tt_detail \ No newline at end of file diff --git a/libs/s25main/BuildingRegister.cpp b/libs/s25main/BuildingRegister.cpp index 13a5e8094b..88cb1849f9 100644 --- a/libs/s25main/BuildingRegister.cpp +++ b/libs/s25main/BuildingRegister.cpp @@ -157,7 +157,7 @@ helpers::EnumArray BuildingRegister::CalcProductivities( unsigned BuildingRegister::CalcAverageProductivity(BuildingType bldType) const { - if(holds_alternative(BLD_WORK_DESC[bldType].producedWare)) + if(holds_alternative(BLD_WORK_DESC[bldType].producedWare)) return 0; unsigned productivity = 0; const auto& buildings = GetBuildings(bldType); @@ -177,7 +177,7 @@ unsigned short BuildingRegister::CalcAverageProductivity() const unsigned numBlds = 0; for(const auto bldType : helpers::enumRange()) { - if(holds_alternative(BLD_WORK_DESC[bldType].producedWare)) + if(holds_alternative(BLD_WORK_DESC[bldType].producedWare)) continue; const auto& buildings = GetBuildings(bldType); diff --git a/libs/s25main/EconomyModeHandler.cpp b/libs/s25main/EconomyModeHandler.cpp index 7ce60113ee..1adecf8ea4 100644 --- a/libs/s25main/EconomyModeHandler.cpp +++ b/libs/s25main/EconomyModeHandler.cpp @@ -16,8 +16,8 @@ #include "gameTypes/JobTypes.h" #include "gameData/GoodConsts.h" #include "gameData/JobConsts.h" -#include #include +#include EconomyModeHandler::EconomyModeHandler(unsigned endFrame) : endFrame(endFrame), gfLastUpdated(0) { @@ -151,7 +151,7 @@ unsigned EconomyModeHandler::SumUpGood(GoodType good, const Inventory& Inventory // Add the tools used by workers to the good totals for(const auto j : helpers::enumRange()) { - boost::optional tool = JOB_CONSTS[j].tool; + std::optional tool = JOB_CONSTS[j].tool; if(tool == good) { retVal += Inventory.people[j]; diff --git a/libs/s25main/Game.cpp b/libs/s25main/Game.cpp index f3537d125f..02b3fdea3e 100644 --- a/libs/s25main/Game.cpp +++ b/libs/s25main/Game.cpp @@ -13,7 +13,7 @@ #include "lua/LuaInterfaceGame.h" #include "network/GameClient.h" #include "gameData/GameConsts.h" -#include +#include Game::Game(GlobalGameSettings settings, unsigned startGF, const std::vector& players) : Game(std::move(settings), std::make_unique(startGF), players) @@ -113,7 +113,7 @@ void Game::CheckObjective() return; unsigned maxPoints = 0, maxTeamPoints = 0, totalPoints = 0, bestPlayer = 0; - boost::optional bestTeam; + std::optional bestTeam; const auto getPlayerMask = [](unsigned playerId) { return 1u << playerId; }; diff --git a/libs/s25main/GameManager.h b/libs/s25main/GameManager.h index de13b0f603..6f95db5bb0 100644 --- a/libs/s25main/GameManager.h +++ b/libs/s25main/GameManager.h @@ -5,7 +5,7 @@ #pragma once #include "FrameCounter.h" -#include +#include class Log; class Settings; @@ -46,7 +46,7 @@ class GameManager { unsigned time, gf; }; - boost::optional lastSkipReport; + std::optional lastSkipReport; }; GameManager& getGlobalGameManager(); diff --git a/libs/s25main/Pathfinding.cpp b/libs/s25main/Pathfinding.cpp index 41d1856452..bf4eb96cb2 100644 --- a/libs/s25main/Pathfinding.cpp +++ b/libs/s25main/Pathfinding.cpp @@ -24,7 +24,7 @@ helpers::OptionalEnum GameWorldBase::FindHumanPath(const MapPoint sta PathConditionHuman(*this))) return first_dir; else - return boost::none; + return std::nullopt; } /// Wegfindung für Menschen im Straßennetz @@ -102,19 +102,19 @@ helpers::OptionalEnum GameWorld::FindTradePath(const MapPoint start, { unsigned char owner = GetNode(dest).owner; if(owner != 0 && !GetPlayer(player).IsAlly(owner - 1)) - return boost::none; + return std::nullopt; RTTR_Assert(GetNO(dest)->GetType() == NodalObjectType::Flag); // Goal should be the flag of a wh if(!PathConditionHuman(*this).IsNodeOk(dest)) - return boost::none; + return std::nullopt; Direction first_dir{}; if(GetFreePathFinder().FindPath(start, dest, random_route, max_route, route, length, &first_dir, PathConditionTrade(*this, player))) return first_dir; else - return boost::none; + return std::nullopt; } bool GameWorld::CheckTradeRoute(const MapPoint start, const std::vector& route, unsigned pos, diff --git a/libs/s25main/Settings.cpp b/libs/s25main/Settings.cpp index 6e94e6d869..46ca3b92e4 100644 --- a/libs/s25main/Settings.cpp +++ b/libs/s25main/Settings.cpp @@ -60,13 +60,13 @@ const std::map persistentWindows = {{CGI_CHAT, "wnd_chat"}, {CGI_MERCHANDISE_STATISTICS, "wnd_merchandise_statistics"}}; namespace validate { -boost::optional checkPort(const std::string& port) +std::optional checkPort(const std::string& port) { int32_t iPort; if((helpers::tryFromString(port, iPort) || s25util::tryFromStringClassic(port, iPort)) && checkPort(iPort)) return static_cast(iPort); else - return boost::none; + return std::nullopt; } bool checkPort(int port) { @@ -309,7 +309,7 @@ void Settings::Load() // server // { server.lastIP = iniServer->getValue("last_ip"); - boost::optional port = validate::checkPort(iniServer->getValue("local_port")); + std::optional port = validate::checkPort(iniServer->getValue("local_port")); server.localPort = port.value_or(3665); server.ipv6 = iniServer->getBoolValue("ipv6"); // } diff --git a/libs/s25main/Settings.h b/libs/s25main/Settings.h index 80e5531243..ec41bc33a0 100644 --- a/libs/s25main/Settings.h +++ b/libs/s25main/Settings.h @@ -9,17 +9,17 @@ #include "driver/VideoMode.h" #include "s25util/ProxySettings.h" #include "s25util/Singleton.h" -#include #include #include #include #include +#include #include #undef interface namespace validate { -boost::optional checkPort(const std::string& port); +std::optional checkPort(const std::string& port); bool checkPort(int port); } // namespace validate diff --git a/libs/s25main/Timer.cpp b/libs/s25main/Timer.cpp index 5a1b6133d1..6499c58a60 100644 --- a/libs/s25main/Timer.cpp +++ b/libs/s25main/Timer.cpp @@ -14,7 +14,7 @@ void Timer::start() void Timer::stop() { - startTime = boost::none; + startTime = std::nullopt; } void Timer::restart() diff --git a/libs/s25main/Timer.h b/libs/s25main/Timer.h index 0ed8ea768a..bf7c79b31c 100644 --- a/libs/s25main/Timer.h +++ b/libs/s25main/Timer.h @@ -5,7 +5,7 @@ #pragma once #include "Clock.h" -#include +#include /// Timer class for measuring time periods class Timer @@ -29,5 +29,5 @@ class Timer bool isRunning() const { return !!startTime; } private: - boost::optional startTime; + std::optional startTime; }; diff --git a/libs/s25main/Window.h b/libs/s25main/Window.h index 1f998cb6a2..92aa3910dc 100644 --- a/libs/s25main/Window.h +++ b/libs/s25main/Window.h @@ -14,11 +14,11 @@ #include "gameTypes/Nation.h" #include "gameTypes/TextureColor.h" #include "s25util/colors.h" -#include #include #include #include #include +#include #include class ctrlBuildingIcon; @@ -250,10 +250,10 @@ class Window virtual void Msg_ScrollShow(unsigned /*ctrl_id*/, bool /*visible*/) {} virtual void Msg_OptionGroupChange(unsigned /*ctrl_id*/, unsigned /*selection*/) {} virtual void Msg_Timer(unsigned /*ctrl_id*/) {} - virtual void Msg_TableSelectItem(unsigned /*ctrl_id*/, const boost::optional& /*selection*/) {} + virtual void Msg_TableSelectItem(unsigned /*ctrl_id*/, const std::optional& /*selection*/) {} virtual void Msg_TableChooseItem(unsigned /*ctrl_id*/, unsigned /*selection*/) {} - virtual void Msg_TableRightButton(unsigned /*ctrl_id*/, const boost::optional& /*selection*/) {} - virtual void Msg_TableLeftButton(unsigned /*ctrl_id*/, const boost::optional& /*selection*/) {} + virtual void Msg_TableRightButton(unsigned /*ctrl_id*/, const std::optional& /*selection*/) {} + virtual void Msg_TableLeftButton(unsigned /*ctrl_id*/, const std::optional& /*selection*/) {} /// Callback of a message box when closed virtual void Msg_MsgBoxResult(unsigned /*msgbox_id*/, MsgboxResult /*mbr*/) {} @@ -271,13 +271,13 @@ class Window virtual void Msg_Group_OptionGroupChange(unsigned /*group_id*/, unsigned /*ctrl_id*/, unsigned /*selection*/) {} virtual void Msg_Group_Timer(unsigned /*group_id*/, unsigned /*ctrl_id*/) {} virtual void Msg_Group_TableSelectItem(unsigned /*group_id*/, unsigned /*ctrl_id*/, - const boost::optional& /*selection*/) + const std::optional& /*selection*/) {} virtual void Msg_Group_TableRightButton(unsigned /*group_id*/, unsigned /*ctrl_id*/, - const boost::optional& /*selection*/) + const std::optional& /*selection*/) {} virtual void Msg_Group_TableLeftButton(unsigned /*group_id*/, unsigned /*ctrl_id*/, - const boost::optional& /*selection*/) + const std::optional& /*selection*/) {} protected: diff --git a/libs/s25main/addons/AddonList.cpp b/libs/s25main/addons/AddonList.cpp index cfe0945162..d3b6d4f60f 100644 --- a/libs/s25main/addons/AddonList.cpp +++ b/libs/s25main/addons/AddonList.cpp @@ -48,5 +48,5 @@ unsigned AddonList::Gui::getStatus(const Window& window) { const auto* cb = window.GetCtrl(2); RTTR_Assert(cb); - return cb->GetSelection().get(); + return *cb->GetSelection(); } diff --git a/libs/s25main/ai/AIInterface.h b/libs/s25main/ai/AIInterface.h index 763f4b39f5..1c9019e0bc 100644 --- a/libs/s25main/ai/AIInterface.h +++ b/libs/s25main/ai/AIInterface.h @@ -48,7 +48,7 @@ class AIInterface : public GameCommandFactory AISurfaceResource GetSurfaceResource(MapPoint pt) const; /// Calculate the surface resource value on a given spot (wood/ stones/ farmland) /// when given a direction and lastvalue the calculation will be much faster O(n) vs O(n^2) - int CalcResourceValue(MapPoint pt, AIResource res, helpers::OptionalEnum direction = boost::none, + int CalcResourceValue(MapPoint pt, AIResource res, helpers::OptionalEnum direction = std::nullopt, int lastval = 0xffff) const; /// Calculate the resource value for a given point int GetResourceRating(MapPoint pt, AIResource res) const; diff --git a/libs/s25main/ai/aijh/AIConstruction.cpp b/libs/s25main/ai/aijh/AIConstruction.cpp index f2d131e688..2e42b2d4b3 100644 --- a/libs/s25main/ai/aijh/AIConstruction.cpp +++ b/libs/s25main/ai/aijh/AIConstruction.cpp @@ -436,7 +436,7 @@ helpers::OptionalEnum AIConstruction::GetSmallestAllowedMilBuildin if(aii.CanBuildBuildingtype(bld)) return bld; } - return boost::none; + return std::nullopt; } helpers::OptionalEnum AIConstruction::GetBiggestAllowedMilBuilding() const @@ -446,7 +446,7 @@ helpers::OptionalEnum AIConstruction::GetBiggestAllowedMilBuilding if(aii.CanBuildBuildingtype(bld)) return bld; } - return boost::none; + return std::nullopt; } helpers::OptionalEnum AIConstruction::ChooseMilitaryBuilding(const MapPoint pt) @@ -461,7 +461,7 @@ helpers::OptionalEnum AIConstruction::ChooseMilitaryBuilding(const auto bld = GetSmallestAllowedMilBuilding(); // If we are not allowed to build a military building, return early if(!bld) - return boost::none; + return std::nullopt; const BuildingType biggestBld = GetBiggestAllowedMilBuilding().value(); diff --git a/libs/s25main/ai/aijh/AIPlayerJH.cpp b/libs/s25main/ai/aijh/AIPlayerJH.cpp index 72fbee111f..dae7f5c070 100644 --- a/libs/s25main/ai/aijh/AIPlayerJH.cpp +++ b/libs/s25main/ai/aijh/AIPlayerJH.cpp @@ -1154,7 +1154,7 @@ void AIPlayerJH::HandleRoadConstructionFailed(const MapPoint pt, Direction) if(flag->GetPlayer() != playerId) return; // if it isnt a useless flag AND it has no current road connection then retry to build a road. - if(RemoveUnusedRoad(*flag, boost::none, true, false)) + if(RemoveUnusedRoad(*flag, std::nullopt, true, false)) construction->AddConnectFlagJob(flag); } @@ -1845,7 +1845,7 @@ void AIPlayerJH::RemoveAllUnusedRoads(const MapPoint pt) std::vector reconnectflags; for(const noFlag* flag : flags) { - if(RemoveUnusedRoad(*flag, boost::none, true, false)) + if(RemoveUnusedRoad(*flag, std::nullopt, true, false)) reconnectflags.push_back(flag); } UpdateNodesAround(pt, 25); @@ -1913,7 +1913,7 @@ bool AIPlayerJH::RemoveUnusedRoad(const noFlag& startFlag, helpers::OptionalEnum { if(allowcircle) { - if(!IsFlagPartofCircle(startFlag, 10, startFlag, boost::none, {})) + if(!IsFlagPartofCircle(startFlag, 10, startFlag, std::nullopt, {})) return false; if(!firstflag) return false; diff --git a/libs/s25main/buildings/nobBaseMilitary.cpp b/libs/s25main/buildings/nobBaseMilitary.cpp index 2ee6539d48..815dc4a3e5 100644 --- a/libs/s25main/buildings/nobBaseMilitary.cpp +++ b/libs/s25main/buildings/nobBaseMilitary.cpp @@ -174,7 +174,7 @@ MapPoint nobBaseMilitary::FindAnAttackerPlace(unsigned short& ret_radius, const // Also check if we can reach this. // If not, still consider the other points as the flag could become reachable by then. // TODO(Replay) Limit distance by MAX_ATTACKING_RUN_DISTANCE - if(soldierPos == flagPos || world->FindHumanPath(soldierPos, flagPos) != boost::none) + if(soldierPos == flagPos || world->FindHumanPath(soldierPos, flagPos) != std::nullopt) { ret_radius = 0; return flagPos; diff --git a/libs/s25main/buildings/nobBaseWarehouse.cpp b/libs/s25main/buildings/nobBaseWarehouse.cpp index bb5068110a..dcaf01c9ed 100644 --- a/libs/s25main/buildings/nobBaseWarehouse.cpp +++ b/libs/s25main/buildings/nobBaseWarehouse.cpp @@ -1185,7 +1185,7 @@ void nobBaseWarehouse::AddToInventory(const PeopleCounts& people, bool addToPlay bool nobBaseWarehouse::CanRecruit(const Job job) const { - if(const GoodType* requiredTool = JOB_CONSTS[job].tool.get_ptr()) + if(const auto& requiredTool = JOB_CONSTS[job].tool) { // Do we have a helper and a tool (if required)? return inventory[Job::Helper] > 0 && (*requiredTool == GoodType::Nothing || inventory[*requiredTool] > 0); @@ -1201,7 +1201,7 @@ bool nobBaseWarehouse::TryRecruitJob(const Job job) auto& owner = world->GetPlayer(player); - const GoodType requiredTool = JOB_CONSTS[job].tool.get(); // Validity checked in CanRecruit + const GoodType requiredTool = *JOB_CONSTS[job].tool; // Validity checked in CanRecruit if(requiredTool != GoodType::Nothing) { inventory.Remove(requiredTool); diff --git a/libs/s25main/controls/ctrlComboBox.cpp b/libs/s25main/controls/ctrlComboBox.cpp index 9573dcddb1..acc9fdf4ae 100644 --- a/libs/s25main/controls/ctrlComboBox.cpp +++ b/libs/s25main/controls/ctrlComboBox.cpp @@ -63,13 +63,13 @@ void ctrlComboBox::Resize(const Extent& newSize) list->Resize(listSize); } -boost::optional ctrlComboBox::GetSelectedText() const +std::optional ctrlComboBox::GetSelectedText() const { - const boost::optional& selection = GetSelection(); + const std::optional& selection = GetSelection(); if(selection) return GetText(*selection); else - return boost::none; + return std::nullopt; } bool ctrlComboBox::Msg_MouseMove(const MouseCoords& mc) diff --git a/libs/s25main/controls/ctrlComboBox.h b/libs/s25main/controls/ctrlComboBox.h index 2193e51fe4..658446297e 100644 --- a/libs/s25main/controls/ctrlComboBox.h +++ b/libs/s25main/controls/ctrlComboBox.h @@ -23,11 +23,11 @@ class ctrlComboBox final : public Window void DeleteAllItems(); /// Set selection to an item if within bounds. Does not trigger a notification. void SetSelection(unsigned selection); - const boost::optional& GetSelection() const { return GetCtrl(0)->GetSelection(); }; + const std::optional& GetSelection() const { return GetCtrl(0)->GetSelection(); }; unsigned GetNumItems() const { return GetCtrl(0)->GetNumLines(); } const std::string& GetText(unsigned item) const { return GetCtrl(0)->GetItemText(item); } void SetText(unsigned item, const std::string& text) { GetCtrl(0)->SetItemText(item, text); } - boost::optional GetSelectedText() const; + std::optional GetSelectedText() const; void Msg_PaintAfter() override; bool Msg_MouseMove(const MouseCoords& mc) override; diff --git a/libs/s25main/controls/ctrlGroup.cpp b/libs/s25main/controls/ctrlGroup.cpp index 238a27892e..ce137be4fe 100644 --- a/libs/s25main/controls/ctrlGroup.cpp +++ b/libs/s25main/controls/ctrlGroup.cpp @@ -64,17 +64,17 @@ void ctrlGroup::Msg_Timer(const unsigned ctrl_id) GetParent()->Msg_Group_Timer(this->GetID(), ctrl_id); } -void ctrlGroup::Msg_TableSelectItem(const unsigned ctrl_id, const boost::optional& selection) +void ctrlGroup::Msg_TableSelectItem(const unsigned ctrl_id, const std::optional& selection) { GetParent()->Msg_Group_TableSelectItem(this->GetID(), ctrl_id, selection); } -void ctrlGroup::Msg_TableRightButton(const unsigned ctrl_id, const boost::optional& selection) +void ctrlGroup::Msg_TableRightButton(const unsigned ctrl_id, const std::optional& selection) { GetParent()->Msg_Group_TableRightButton(this->GetID(), ctrl_id, selection); } -void ctrlGroup::Msg_TableLeftButton(const unsigned ctrl_id, const boost::optional& selection) +void ctrlGroup::Msg_TableLeftButton(const unsigned ctrl_id, const std::optional& selection) { GetParent()->Msg_Group_TableLeftButton(this->GetID(), ctrl_id, selection); } @@ -176,19 +176,19 @@ void ctrlGroup::Msg_Group_Timer(const unsigned /*group_id*/, const unsigned ctrl } void ctrlGroup::Msg_Group_TableSelectItem(const unsigned /*group_id*/, const unsigned ctrl_id, - const boost::optional& selection) + const std::optional& selection) { GetParent()->Msg_Group_TableSelectItem(this->GetID(), ctrl_id, selection); } void ctrlGroup::Msg_Group_TableRightButton(const unsigned /*group_id*/, const unsigned ctrl_id, - const boost::optional& selection) + const std::optional& selection) { GetParent()->Msg_Group_TableRightButton(this->GetID(), ctrl_id, selection); } void ctrlGroup::Msg_Group_TableLeftButton(const unsigned /*group_id*/, const unsigned ctrl_id, - const boost::optional& selection) + const std::optional& selection) { GetParent()->Msg_Group_TableLeftButton(this->GetID(), ctrl_id, selection); } diff --git a/libs/s25main/controls/ctrlGroup.h b/libs/s25main/controls/ctrlGroup.h index d364ece543..94b07ab9e0 100644 --- a/libs/s25main/controls/ctrlGroup.h +++ b/libs/s25main/controls/ctrlGroup.h @@ -31,9 +31,9 @@ class ctrlGroup : public Window void Msg_ScrollShow(unsigned ctrl_id, bool visible) override; void Msg_OptionGroupChange(unsigned ctrl_id, unsigned selection) override; void Msg_Timer(unsigned ctrl_id) override; - void Msg_TableSelectItem(unsigned ctrl_id, const boost::optional& selection) override; - void Msg_TableRightButton(unsigned ctrl_id, const boost::optional& selection) override; - void Msg_TableLeftButton(unsigned ctrl_id, const boost::optional& selection) override; + void Msg_TableSelectItem(unsigned ctrl_id, const std::optional& selection) override; + void Msg_TableRightButton(unsigned ctrl_id, const std::optional& selection) override; + void Msg_TableLeftButton(unsigned ctrl_id, const std::optional& selection) override; void Msg_Group_ButtonClick(unsigned group_id, unsigned ctrl_id) override; void Msg_Group_EditEnter(unsigned group_id, unsigned ctrl_id) override; @@ -47,11 +47,11 @@ class ctrlGroup : public Window void Msg_Group_OptionGroupChange(unsigned group_id, unsigned ctrl_id, unsigned selection) override; void Msg_Group_Timer(unsigned group_id, unsigned ctrl_id) override; void Msg_Group_TableSelectItem(unsigned group_id, unsigned ctrl_id, - const boost::optional& selection) override; + const std::optional& selection) override; void Msg_Group_TableRightButton(unsigned group_id, unsigned ctrl_id, - const boost::optional& selection) override; + const std::optional& selection) override; void Msg_Group_TableLeftButton(unsigned group_id, unsigned ctrl_id, - const boost::optional& selection) override; + const std::optional& selection) override; bool Msg_LeftDown(const MouseCoords& mc) override; bool Msg_RightDown(const MouseCoords& mc) override; diff --git a/libs/s25main/controls/ctrlList.cpp b/libs/s25main/controls/ctrlList.cpp index a65db52df9..00e745310a 100644 --- a/libs/s25main/controls/ctrlList.cpp +++ b/libs/s25main/controls/ctrlList.cpp @@ -22,7 +22,7 @@ ctrlList::~ctrlList() DeleteAllItems(); } -void ctrlList::SetSelection(const boost::optional& selection) +void ctrlList::SetSelection(const std::optional& selection) { if(selection != selection_ && (!selection || *selection < lines.size())) { @@ -173,7 +173,7 @@ void ctrlList::SetItemText(const unsigned id, const std::string& text) void ctrlList::DeleteAllItems() { lines.clear(); - selection_ = boost::none; + selection_ = std::nullopt; } const std::string& ctrlList::GetItemText(unsigned line) const @@ -236,7 +236,7 @@ void ctrlList::Remove(const unsigned index) else if(*selection_ == index) { // Current item deleted -> clear selection - selection_ = boost::none; + selection_ = std::nullopt; if(index < GetNumLines()) SetSelection(index); // select item now at deleted position else if(index > 0u) @@ -255,15 +255,15 @@ Rect ctrlList::GetListDrawArea() const return result; } -boost::optional ctrlList::GetItemFromPos(const Position& pos) const +std::optional ctrlList::GetItemFromPos(const Position& pos) const { const Rect listDrawArea = GetListDrawArea(); if(!IsPointInRect(pos, listDrawArea)) - return boost::none; + return std::nullopt; const unsigned itemIdx = (pos.y - listDrawArea.getOrigin().y) / font->getHeight() + GetCtrl(0)->GetScrollPos(); if(itemIdx >= GetNumLines()) - return boost::none; + return std::nullopt; return itemIdx; } diff --git a/libs/s25main/controls/ctrlList.h b/libs/s25main/controls/ctrlList.h index b8f238c7d2..fe1c1139f1 100644 --- a/libs/s25main/controls/ctrlList.h +++ b/libs/s25main/controls/ctrlList.h @@ -6,7 +6,7 @@ #include "Window.h" #include "controls/ctrlBaseTooltip.h" -#include +#include #include #include @@ -37,8 +37,8 @@ class ctrlList : public Window void Remove(unsigned index); unsigned GetNumLines() const { return static_cast(lines.size()); } - const boost::optional& GetSelection() const { return selection_; }; - void SetSelection(const boost::optional& selection); + const std::optional& GetSelection() const { return selection_; }; + void SetSelection(const std::optional& selection); bool Msg_MouseMove(const MouseCoords& mc) override; bool Msg_LeftDown(const MouseCoords& mc) override; @@ -51,7 +51,7 @@ class ctrlList : public Window void Draw_() override; private: - boost::optional GetItemFromPos(const Position& pos) const; + std::optional GetItemFromPos(const Position& pos) const; Rect GetFullDrawArea() const; Rect GetListDrawArea() const; @@ -61,7 +61,7 @@ class ctrlList : public Window std::vector lines; - boost::optional selection_; - boost::optional mouseover_; + std::optional selection_; + std::optional mouseover_; unsigned pagesize; }; diff --git a/libs/s25main/controls/ctrlOptionGroup.cpp b/libs/s25main/controls/ctrlOptionGroup.cpp index 00781f6d07..b2d832e968 100644 --- a/libs/s25main/controls/ctrlOptionGroup.cpp +++ b/libs/s25main/controls/ctrlOptionGroup.cpp @@ -16,7 +16,7 @@ void ctrlOptionGroup::SetSelection(unsigned selection, bool notify) // Aktuellen ausgewählten Button wieder normal machen if(this->selection_) { - auto* button = GetCtrl(this->selection_.get()); + auto* button = GetCtrl(*this->selection_); RTTR_Assert(button); switch(select_type) { @@ -46,7 +46,7 @@ unsigned ctrlOptionGroup::GetSelection() const { if(!selection_) throw std::logic_error("No button selected in option group"); - return selection_.get(); + return *selection_; } void ctrlOptionGroup::Msg_ButtonClick(const unsigned ctrl_id) diff --git a/libs/s25main/controls/ctrlOptionGroup.h b/libs/s25main/controls/ctrlOptionGroup.h index 40d2f9e326..f463eaed8a 100644 --- a/libs/s25main/controls/ctrlOptionGroup.h +++ b/libs/s25main/controls/ctrlOptionGroup.h @@ -6,7 +6,7 @@ #include "ctrlButton.h" #include "ctrlGroup.h" -#include +#include struct MouseCoords; class Window; @@ -31,7 +31,7 @@ class ctrlOptionGroup : public ctrlGroup bool Msg_MouseMove(const MouseCoords& mc) override; private: - boost::optional + std::optional selection_; /// Currently selected button ID, must be set via SetSelection after initialization GroupSelectType select_type; /// Typ der Selektierung }; diff --git a/libs/s25main/controls/ctrlTab.cpp b/libs/s25main/controls/ctrlTab.cpp index 719d5d7eb3..25b6bc9cd4 100644 --- a/libs/s25main/controls/ctrlTab.cpp +++ b/libs/s25main/controls/ctrlTab.cpp @@ -194,19 +194,19 @@ void ctrlTab::Msg_Group_Timer(const unsigned /*group_id*/, const unsigned ctrl_i } void ctrlTab::Msg_Group_TableSelectItem(const unsigned /*group_id*/, const unsigned ctrl_id, - const boost::optional& selection) + const std::optional& selection) { GetParent()->Msg_Group_TableSelectItem(this->GetID(), ctrl_id, selection); } void ctrlTab::Msg_Group_TableRightButton(const unsigned /*group_id*/, const unsigned ctrl_id, - const boost::optional& selection) + const std::optional& selection) { GetParent()->Msg_Group_TableRightButton(this->GetID(), ctrl_id, selection); } void ctrlTab::Msg_Group_TableLeftButton(const unsigned /*group_id*/, const unsigned ctrl_id, - const boost::optional& selection) + const std::optional& selection) { GetParent()->Msg_Group_TableLeftButton(this->GetID(), ctrl_id, selection); } diff --git a/libs/s25main/controls/ctrlTab.h b/libs/s25main/controls/ctrlTab.h index 166cfc6e69..8ad71bd088 100644 --- a/libs/s25main/controls/ctrlTab.h +++ b/libs/s25main/controls/ctrlTab.h @@ -41,11 +41,11 @@ class ctrlTab : public Window void Msg_Group_OptionGroupChange(unsigned group_id, unsigned ctrl_id, unsigned selection) override; void Msg_Group_Timer(unsigned group_id, unsigned ctrl_id) override; void Msg_Group_TableSelectItem(unsigned group_id, unsigned ctrl_id, - const boost::optional& selection) override; + const std::optional& selection) override; void Msg_Group_TableRightButton(unsigned group_id, unsigned ctrl_id, - const boost::optional& selection) override; + const std::optional& selection) override; void Msg_Group_TableLeftButton(unsigned group_id, unsigned ctrl_id, - const boost::optional& selection) override; + const std::optional& selection) override; void Msg_ButtonClick(unsigned ctrl_id) override; bool Msg_LeftDown(const MouseCoords& mc) override; bool Msg_LeftUp(const MouseCoords& mc) override; diff --git a/libs/s25main/controls/ctrlTable.cpp b/libs/s25main/controls/ctrlTable.cpp index 48fb3d314d..885baf4e89 100644 --- a/libs/s25main/controls/ctrlTable.cpp +++ b/libs/s25main/controls/ctrlTable.cpp @@ -190,7 +190,7 @@ void ctrlTable::DeleteAllItems() GetCtrl(0)->SetRange(0); - SetSelection(boost::none); + SetSelection(std::nullopt); sortColumn_ = -1; sortDir_ = TableSortDir::Ascending; } @@ -200,10 +200,10 @@ void ctrlTable::DeleteAllItems() * * @param[in] selection Der Auswahlindex */ -void ctrlTable::SetSelection(const boost::optional& selection) +void ctrlTable::SetSelection(const std::optional& selection) { if(!selection) - selection_ = boost::none; + selection_ = std::nullopt; else if(*selection >= rows_.size()) return; else @@ -391,14 +391,14 @@ bool ctrlTable::Msg_RightDown(const MouseCoords& mc) return RelayMouseMessage(&Window::Msg_RightDown, mc); } -boost::optional ctrlTable::GetSelectionFromMouse(const MouseCoords& mc) const +std::optional ctrlTable::GetSelectionFromMouse(const MouseCoords& mc) const { const int visibleItem = (mc.pos.y - GetContentDrawArea().top) / font->getHeight(); if(visibleItem < 0) - return boost::none; + return std::nullopt; const unsigned itemIdx = static_cast(visibleItem) + GetCtrl(0)->GetScrollPos(); if(itemIdx >= GetNumRows()) - return boost::none; + return std::nullopt; return itemIdx; } diff --git a/libs/s25main/controls/ctrlTable.h b/libs/s25main/controls/ctrlTable.h index 288419b64f..81d2d49319 100644 --- a/libs/s25main/controls/ctrlTable.h +++ b/libs/s25main/controls/ctrlTable.h @@ -6,7 +6,7 @@ #include "Window.h" #include "gameTypes/TextureColor.h" -#include +#include #include #include @@ -60,8 +60,8 @@ class ctrlTable : public Window TableSortDir GetSortDirection() const { return sortDir_; } unsigned short GetNumRows() const { return static_cast(rows_.size()); } unsigned short GetNumColumns() const { return static_cast(columns_.size()); } - const boost::optional& GetSelection() const { return selection_; } - void SetSelection(const boost::optional& selection); + const std::optional& GetSelection() const { return selection_; } + void SetSelection(const std::optional& selection); bool Msg_LeftDown(const MouseCoords& mc) override; bool Msg_RightDown(const MouseCoords& mc) override; @@ -78,7 +78,7 @@ class ctrlTable : public Window /// Setzt die Breite und Position der Buttons ohne Scrolleiste void ResetButtonWidths(); - boost::optional GetSelectionFromMouse(const MouseCoords& mc) const; + std::optional GetSelectionFromMouse(const MouseCoords& mc) const; /// Get the area of the content (table itself w/o header) Rect GetContentDrawArea() const; /// Get the full area (element less spacing) @@ -93,7 +93,7 @@ class ctrlTable : public Window Columns columns_; /// Selected row. - boost::optional selection_; + std::optional selection_; /// Column to sort by. -1 for none int sortColumn_; TableSortDir sortDir_; diff --git a/libs/s25main/desktops/dskCampaignSelection.cpp b/libs/s25main/desktops/dskCampaignSelection.cpp index 88c970485b..701317ad26 100644 --- a/libs/s25main/desktops/dskCampaignSelection.cpp +++ b/libs/s25main/desktops/dskCampaignSelection.cpp @@ -103,7 +103,7 @@ void dskCampaignSelection::Msg_TableChooseItem(const unsigned ctrl_id, const uns showCampaignMissionSelectionScreen(); } -void dskCampaignSelection::Msg_TableSelectItem(const unsigned ctrl_id, const boost::optional& selection) +void dskCampaignSelection::Msg_TableSelectItem(const unsigned ctrl_id, const std::optional& selection) { if(ctrl_id != ID_Table) return; diff --git a/libs/s25main/desktops/dskCampaignSelection.h b/libs/s25main/desktops/dskCampaignSelection.h index fa4c81d356..5c93d70ae1 100644 --- a/libs/s25main/desktops/dskCampaignSelection.h +++ b/libs/s25main/desktops/dskCampaignSelection.h @@ -24,7 +24,7 @@ class dskCampaignSelection : public Desktop class CampaignDataHolder; void Msg_TableChooseItem(unsigned, unsigned) override; - void Msg_TableSelectItem(unsigned ctrl_id, const boost::optional& selection) override; + void Msg_TableSelectItem(unsigned ctrl_id, const std::optional& selection) override; void Msg_ButtonClick(unsigned ctrl_id) override; void Msg_Timer(unsigned ctrl_id) override; void FillCampaignsTable(); diff --git a/libs/s25main/desktops/dskGameLobby.cpp b/libs/s25main/desktops/dskGameLobby.cpp index 8ea7a2086f..f508689511 100644 --- a/libs/s25main/desktops/dskGameLobby.cpp +++ b/libs/s25main/desktops/dskGameLobby.cpp @@ -946,10 +946,10 @@ void dskGameLobby::UpdateGGS() GlobalGameSettings& ggs = gameLobby_->getSettings(); - ggs.speed = static_cast(GetCtrl(ID_cbSpeed)->GetSelection().get()); - ggs.objective = static_cast(GetCtrl(ID_cbGoals)->GetSelection().get()); - ggs.startWares = static_cast(GetCtrl(ID_cbGoods)->GetSelection().get()); - ggs.exploration = static_cast(GetCtrl(ID_cbExploration)->GetSelection().get()); + ggs.speed = static_cast(*GetCtrl(ID_cbSpeed)->GetSelection()); + ggs.objective = static_cast(*GetCtrl(ID_cbGoals)->GetSelection()); + ggs.startWares = static_cast(*GetCtrl(ID_cbGoods)->GetSelection()); + ggs.exploration = static_cast(*GetCtrl(ID_cbExploration)->GetSelection()); ggs.lockedTeams = GetCtrl(ID_chkLockTeams)->isChecked(); ggs.teamView = GetCtrl(ID_chkSharedView)->isChecked(); ggs.randomStartPosition = GetCtrl(ID_chkRandomSpawn)->isChecked(); diff --git a/libs/s25main/desktops/dskLobby.cpp b/libs/s25main/desktops/dskLobby.cpp index 82bc4e13ff..7a2b1fdb49 100644 --- a/libs/s25main/desktops/dskLobby.cpp +++ b/libs/s25main/desktops/dskLobby.cpp @@ -141,7 +141,7 @@ void dskLobby::Msg_EditEnter(const unsigned ctrl_id) } } -void dskLobby::Msg_TableRightButton(const unsigned ctrl_id, const boost::optional& selection) +void dskLobby::Msg_TableRightButton(const unsigned ctrl_id, const std::optional& selection) { if(!selection) return; diff --git a/libs/s25main/desktops/dskLobby.h b/libs/s25main/desktops/dskLobby.h index 7bba01943e..e3b0cd833e 100644 --- a/libs/s25main/desktops/dskLobby.h +++ b/libs/s25main/desktops/dskLobby.h @@ -45,7 +45,7 @@ class dskLobby final : public dskMenuBase, public LobbyInterface void Msg_MsgBoxResult(unsigned msgbox_id, MsgboxResult mbr) override; void Msg_ButtonClick(unsigned ctrl_id) override; void Msg_EditEnter(unsigned ctrl_id) override; - void Msg_TableRightButton(unsigned ctrl_id, const boost::optional& selection) override; + void Msg_TableRightButton(unsigned ctrl_id, const std::optional& selection) override; void Msg_TableChooseItem(unsigned ctrl_id, unsigned selection) override; /** diff --git a/libs/s25main/desktops/dskOptions.cpp b/libs/s25main/desktops/dskOptions.cpp index f7a79fe2b1..8e91dc898b 100644 --- a/libs/s25main/desktops/dskOptions.cpp +++ b/libs/s25main/desktops/dskOptions.cpp @@ -655,7 +655,7 @@ void dskOptions::Msg_OptionGroupChange(const unsigned ctrl_id, const unsigned se /// Check that the port is valid and sets outPort to it. Shows an error otherwise static bool validatePort(const std::string& sPort, uint16_t& outPort) { - boost::optional port = validate::checkPort(sPort); + std::optional port = validate::checkPort(sPort); if(port) outPort = *port; else diff --git a/libs/s25main/desktops/dskSelectMap.cpp b/libs/s25main/desktops/dskSelectMap.cpp index 5720909637..7054e128ef 100644 --- a/libs/s25main/desktops/dskSelectMap.cpp +++ b/libs/s25main/desktops/dskSelectMap.cpp @@ -177,7 +177,7 @@ void dskSelectMap::Msg_OptionGroupChange(const unsigned /*ctrl_id*/, unsigned se table->SortRows(0, TableSortDir::Ascending); // und Auswahl zurücksetzen - table->SetSelection(boost::none); + table->SetSelection(std::nullopt); } /// Load a map, throw on error @@ -199,7 +199,7 @@ static std::unique_ptr loadAndVerifyMap(const std:: /** * Occurs when user changes the selection in the table of maps. */ -void dskSelectMap::Msg_TableSelectItem(const unsigned ctrl_id, const boost::optional& selection) +void dskSelectMap::Msg_TableSelectItem(const unsigned ctrl_id, const std::optional& selection) { if(ctrl_id != 1) return; diff --git a/libs/s25main/desktops/dskSelectMap.h b/libs/s25main/desktops/dskSelectMap.h index e559331965..74f958f756 100644 --- a/libs/s25main/desktops/dskSelectMap.h +++ b/libs/s25main/desktops/dskSelectMap.h @@ -32,7 +32,7 @@ class dskSelectMap final : public Desktop, public LobbyInterface void Msg_OptionGroupChange(unsigned ctrl_id, unsigned selection) override; void Msg_ButtonClick(unsigned ctrl_id) override; void Msg_MsgBoxResult(unsigned msgbox_id, MsgboxResult mbr) override; - void Msg_TableSelectItem(unsigned ctrl_id, const boost::optional& selection) override; + void Msg_TableSelectItem(unsigned ctrl_id, const std::optional& selection) override; void Msg_TableChooseItem(unsigned ctrl_id, unsigned selection) override; void LC_Status_Error(const std::string& error) override; diff --git a/libs/s25main/figures/nofAggressiveDefender.h b/libs/s25main/figures/nofAggressiveDefender.h index 7db9cec9ce..eb9a12b824 100644 --- a/libs/s25main/figures/nofAggressiveDefender.h +++ b/libs/s25main/figures/nofAggressiveDefender.h @@ -5,6 +5,7 @@ #pragma once #include "nofActiveSoldier.h" +#include class nofAttacker; class nofPassiveSoldier; diff --git a/libs/s25main/figures/nofBuildingWorker.cpp b/libs/s25main/figures/nofBuildingWorker.cpp index aba475dd9d..06cd034cc0 100644 --- a/libs/s25main/figures/nofBuildingWorker.cpp +++ b/libs/s25main/figures/nofBuildingWorker.cpp @@ -51,7 +51,7 @@ nofBuildingWorker::nofBuildingWorker(SerializedGameData& sgd, const unsigned obj // GoodType::Nothing is moved because of adding new wares due addons // The old GoodType::Nothing is now GoodType::Grapes if(iWare == rttr::enum_cast(GoodType::Grapes)) - ware = boost::none; + ware = std::nullopt; else ware = GoodType(iWare); } else @@ -60,7 +60,7 @@ nofBuildingWorker::nofBuildingWorker(SerializedGameData& sgd, const unsigned obj } else { workplace = nullptr; - ware = boost::none; + ware = std::nullopt; was_sounding = false; } } @@ -162,7 +162,7 @@ void nofBuildingWorker::WorkingReady() // Warenstatistik erhöhen world->GetPlayer(this->player).IncreaseMerchandiseStatistic(ware_type); // Tragen nun keine Ware mehr - ware = boost::none; + ware = std::nullopt; } } diff --git a/libs/s25main/figures/nofCarrier.cpp b/libs/s25main/figures/nofCarrier.cpp index 1aa89f243c..8c5862afca 100644 --- a/libs/s25main/figures/nofCarrier.cpp +++ b/libs/s25main/figures/nofCarrier.cpp @@ -216,7 +216,7 @@ void nofCarrier::Draw(DrawPoint drawPt) if(carried_ware) DrawWalkingCarrier(drawPt, carried_ware->type, fat); else - DrawWalkingCarrier(drawPt, boost::none, fat); + DrawWalkingCarrier(drawPt, std::nullopt, fat); } } break; diff --git a/libs/s25main/figures/nofDefender.h b/libs/s25main/figures/nofDefender.h index 9ec9fb1c6d..e209a78ea0 100644 --- a/libs/s25main/figures/nofDefender.h +++ b/libs/s25main/figures/nofDefender.h @@ -5,6 +5,7 @@ #pragma once #include "nofActiveSoldier.h" +#include class nofAttacker; class nofPassiveSoldier; diff --git a/libs/s25main/figures/nofDonkeybreeder.cpp b/libs/s25main/figures/nofDonkeybreeder.cpp index 4173cf903e..b2534bb327 100644 --- a/libs/s25main/figures/nofDonkeybreeder.cpp +++ b/libs/s25main/figures/nofDonkeybreeder.cpp @@ -61,7 +61,7 @@ void nofDonkeybreeder::DrawWorking(DrawPoint drawPt) helpers::OptionalEnum nofDonkeybreeder::ProduceWare() { /// @todo Wie kann ich hier eine Person erzeugen? - return boost::none; + return std::nullopt; } void nofDonkeybreeder::WorkFinished() diff --git a/libs/s25main/figures/nofFarmer.cpp b/libs/s25main/figures/nofFarmer.cpp index 7a6401ea9e..613782020d 100644 --- a/libs/s25main/figures/nofFarmer.cpp +++ b/libs/s25main/figures/nofFarmer.cpp @@ -133,7 +133,7 @@ void nofFarmer::WorkFinished() } // Wir haben nur gesäht (gar nichts in die Hand nehmen) - ware = boost::none; + ware = std::nullopt; } // BQ drumrum neu berechnen diff --git a/libs/s25main/figures/nofFisher.cpp b/libs/s25main/figures/nofFisher.cpp index 5a4cf4c46a..528af59df9 100644 --- a/libs/s25main/figures/nofFisher.cpp +++ b/libs/s25main/figures/nofFisher.cpp @@ -117,7 +117,7 @@ void nofFisher::WorkFinished() if(successful) ware = GoodType::Fish; else - ware = boost::none; + ware = std::nullopt; } /// Returns the quality of this working point or determines if the worker can work here at all diff --git a/libs/s25main/figures/nofGeologist.cpp b/libs/s25main/figures/nofGeologist.cpp index f85ccfd3fc..e84a204d6b 100644 --- a/libs/s25main/figures/nofGeologist.cpp +++ b/libs/s25main/figures/nofGeologist.cpp @@ -339,7 +339,7 @@ helpers::OptionalEnum nofGeologist::GetNextNode() if(!signs) { node_goal = MapPoint::Invalid(); - return boost::none; + return std::nullopt; } do @@ -373,7 +373,7 @@ helpers::OptionalEnum nofGeologist::GetNextNode() } while(!available_nodes.empty()); node_goal = MapPoint::Invalid(); - return boost::none; + return std::nullopt; } void nofGeologist::GoToNextNode() diff --git a/libs/s25main/figures/nofHunter.cpp b/libs/s25main/figures/nofHunter.cpp index 80a57c8a79..b276662985 100644 --- a/libs/s25main/figures/nofHunter.cpp +++ b/libs/s25main/figures/nofHunter.cpp @@ -211,7 +211,7 @@ void nofHunter::WalkedDerived() bool nofHunter::IsShootingPointGood(const MapPoint pt) { // Punkt muss betretbar sein und man muss ihn erreichen können - return PathConditionHuman(*world).IsNodeOk(pt) && world->FindHumanPath(this->pos, pt, 6) != boost::none; + return PathConditionHuman(*world).IsNodeOk(pt) && world->FindHumanPath(this->pos, pt, 6) != std::nullopt; } void nofHunter::HandleStateChasing() diff --git a/libs/s25main/figures/nofMetalworker.cpp b/libs/s25main/figures/nofMetalworker.cpp index 3cb0be0c48..b680f5e691 100644 --- a/libs/s25main/figures/nofMetalworker.cpp +++ b/libs/s25main/figures/nofMetalworker.cpp @@ -40,7 +40,7 @@ nofMetalworker::nofMetalworker(SerializedGameData& sgd, const unsigned obj_id) : // GoodType::Nothing is moved because of adding new wares due addons // The old GoodType::Nothing is now GoodType::Grapes if(iWare == rttr::enum_cast(GoodType::Grapes)) - nextProducedTool = boost::none; + nextProducedTool = std::nullopt; else nextProducedTool = GoodType(iWare); } else @@ -164,7 +164,7 @@ helpers::OptionalEnum nofMetalworker::GetOrderedTool() random_array.insert(random_array.end(), toolPriority, tool); } if(random_array.empty()) - return boost::none; + return std::nullopt; const Tool tool = RANDOM_ELEMENT(random_array); @@ -198,7 +198,7 @@ helpers::OptionalEnum nofMetalworker::GetRandomTool() { // do nothing if addon is enabled, otherwise produce random ware (orig S2 behavior) if(world->GetGGS().getSelection(AddonId::METALWORKSBEHAVIORONZERO) == 1) - return boost::none; + return std::nullopt; else return RANDOM_ELEMENT(TOOL_TO_GOOD); } diff --git a/libs/s25main/figures/nofWarehouseWorker.cpp b/libs/s25main/figures/nofWarehouseWorker.cpp index 94380d1fe5..7d96a9a3cd 100644 --- a/libs/s25main/figures/nofWarehouseWorker.cpp +++ b/libs/s25main/figures/nofWarehouseWorker.cpp @@ -54,7 +54,7 @@ void nofWarehouseWorker::Draw(DrawPoint drawPt) if(carried_ware) DrawWalkingCarrier(drawPt, carried_ware->type, fat); else - DrawWalkingCarrier(drawPt, boost::none, fat); + DrawWalkingCarrier(drawPt, std::nullopt, fat); } void nofWarehouseWorker::GoalReached() diff --git a/libs/s25main/figures/nofWinegrower.cpp b/libs/s25main/figures/nofWinegrower.cpp index f8ffe712bb..a2700cc51e 100644 --- a/libs/s25main/figures/nofWinegrower.cpp +++ b/libs/s25main/figures/nofWinegrower.cpp @@ -116,7 +116,7 @@ void nofWinegrower::WorkFinished() } // We have only planted (take nothing into hand) - ware = boost::none; + ware = std::nullopt; } // recompute BQ around diff --git a/libs/s25main/gameData/BuildingConsts.h b/libs/s25main/gameData/BuildingConsts.h index 8b07e0cdcb..006b96b7a9 100644 --- a/libs/s25main/gameData/BuildingConsts.h +++ b/libs/s25main/gameData/BuildingConsts.h @@ -33,22 +33,22 @@ constexpr helpers::EnumArray SUPPRESS_UNUSED BUIL const helpers::EnumArray SUPPRESS_UNUSED BLD_WORK_DESC = {{ {}, // HQ - {Job::Private, boost::none, WaresNeeded(GoodType::Coins), 1}, - {Job::Private, boost::none, WaresNeeded(GoodType::Coins), 2}, + {Job::Private, std::nullopt, WaresNeeded(GoodType::Coins), 1}, + {Job::Private, std::nullopt, WaresNeeded(GoodType::Coins), 2}, {Job::Skinner, GoodType::Skins, WaresNeeded(GoodType::Ham), 3}, - {Job::Private, boost::none, WaresNeeded(GoodType::Coins), 4}, + {Job::Private, std::nullopt, WaresNeeded(GoodType::Coins), 4}, {Job::Winegrower, GoodType::Grapes, WaresNeeded(GoodType::Wood, GoodType::Water)}, {Job::Vintner, GoodType::Wine, WaresNeeded(GoodType::Grapes)}, {Job::TempleServant, GoodType::Gold, WaresNeeded(GoodType::Wine, GoodType::Meat, GoodType::Bread)}, {Job::Tanner, GoodType::Leather, WaresNeeded(GoodType::Skins, GoodType::Boards)}, - {Job::Private, boost::none, WaresNeeded(GoodType::Coins), 6}, + {Job::Private, std::nullopt, WaresNeeded(GoodType::Coins), 6}, {Job::Miner, GoodType::Stones, WaresNeeded(GoodType::Fish, GoodType::Meat, GoodType::Bread), 2, false}, {Job::Miner, GoodType::Coal, WaresNeeded(GoodType::Fish, GoodType::Meat, GoodType::Bread), 2, false}, {Job::Miner, GoodType::IronOre, WaresNeeded(GoodType::Fish, GoodType::Meat, GoodType::Bread), 2, false}, {Job::Miner, GoodType::Gold, WaresNeeded(GoodType::Fish, GoodType::Meat, GoodType::Bread), 2, false}, {Job::Scout}, // No production, just existence {Job::LeatherWorker, GoodType::Armor, WaresNeeded(GoodType::Leather)}, - {Job::Helper, boost::none, WaresNeeded(GoodType::Stones), 4}, + {Job::Helper, std::nullopt, WaresNeeded(GoodType::Stones), 4}, {Job::Woodcutter, GoodType::Wood}, {Job::Fisher, GoodType::Fish}, {Job::Stonemason, GoodType::Stones}, diff --git a/libs/s25main/gameData/JobConsts.h b/libs/s25main/gameData/JobConsts.h index fcbbe740d6..61761d2eaf 100644 --- a/libs/s25main/gameData/JobConsts.h +++ b/libs/s25main/gameData/JobConsts.h @@ -10,8 +10,8 @@ #include "gameTypes/GoodTypes.h" #include "gameTypes/JobTypes.h" #include "gameTypes/Nation.h" -#include #include +#include extern const helpers::EnumArray JOB_NAMES; @@ -19,7 +19,7 @@ extern const helpers::EnumArray JOB_NAMES; struct JobConst { /// Tool required to recruit this job (helper + tool = new worker). Empty if recruiting is not possible - boost::optional tool; + std::optional tool; /// Duration of working and waiting (before and between work steps) in GFs unsigned short work_length, wait1_length, wait2_length; }; diff --git a/libs/s25main/gameTypes/BuildingTypes.h b/libs/s25main/gameTypes/BuildingTypes.h index 06b176ae84..28030e12a7 100644 --- a/libs/s25main/gameTypes/BuildingTypes.h +++ b/libs/s25main/gameTypes/BuildingTypes.h @@ -43,9 +43,9 @@ class WaresNeeded struct BldWorkDescription { /// Worker belonging to the building, if any - helpers::OptionalEnum job = boost::none; + helpers::OptionalEnum job = std::nullopt; /// Ware produced, if any - boost_variant2 producedWare = boost::none; + boost_variant2 producedWare = std::nullopt; // Required for use in aggregate initialization // NOLINTBEGIN(readability-redundant-member-init) /// Wares the building needs, if any diff --git a/libs/s25main/gameTypes/MapDescription.cpp b/libs/s25main/gameTypes/MapDescription.cpp index 6c144ba806..ecbca012dc 100644 --- a/libs/s25main/gameTypes/MapDescription.cpp +++ b/libs/s25main/gameTypes/MapDescription.cpp @@ -5,6 +5,6 @@ #include "MapDescription.h" MapDescription::MapDescription(boost::filesystem::path map_path, MapType map_type, - boost::optional lua_path) + std::optional lua_path) : map_path(std::move(map_path)), map_type(map_type), lua_path(std::move(lua_path)) {} diff --git a/libs/s25main/gameTypes/MapDescription.h b/libs/s25main/gameTypes/MapDescription.h index 3b93fdc7ab..a50b14d5fe 100644 --- a/libs/s25main/gameTypes/MapDescription.h +++ b/libs/s25main/gameTypes/MapDescription.h @@ -6,14 +6,14 @@ #include "gameTypes/MapType.h" #include -#include +#include struct MapDescription { boost::filesystem::path map_path; MapType map_type; - boost::optional lua_path; + std::optional lua_path; MapDescription(boost::filesystem::path map_path, MapType map_type, - boost::optional lua_path = boost::none); + std::optional lua_path = std::nullopt); }; diff --git a/libs/s25main/ingameWindows/iwBuilding.cpp b/libs/s25main/ingameWindows/iwBuilding.cpp index 55f48f66bf..c8ff0c2284 100644 --- a/libs/s25main/ingameWindows/iwBuilding.cpp +++ b/libs/s25main/ingameWindows/iwBuilding.cpp @@ -48,7 +48,7 @@ iwBuilding::iwBuilding(GameWorldView& gwv, GameCommandFactory& gcFactory, nobUsu ITexture* tex = visit( composeVisitor([](GoodType gt) -> ITexture* { return gt != GoodType::Nothing ? LOADER.GetWareTex(gt) : nullptr; }, [](Job job) -> ITexture* { return LOADER.GetJobTex(job); }, - [](boost::none_t) -> ITexture* { return nullptr; }), + [](std::nullopt_t) -> ITexture* { return nullptr; }), producedWare); if(tex) { diff --git a/libs/s25main/ingameWindows/iwDiplomacy.cpp b/libs/s25main/ingameWindows/iwDiplomacy.cpp index 9a685f0799..1ce61c1b0f 100644 --- a/libs/s25main/ingameWindows/iwDiplomacy.cpp +++ b/libs/s25main/ingameWindows/iwDiplomacy.cpp @@ -243,8 +243,8 @@ iwSuggestPact::iwSuggestPact(const PactType pt, const GamePlayer& player, GameCo void iwSuggestPact::Msg_ButtonClick(const unsigned /*ctrl_id*/) { /// Dauer auswählen (wenn id == NUM_DURATIONS, dann "für alle Ewigkeit" ausgewählt) - unsigned selected_id = GetCtrl(6)->GetSelection().get(); - unsigned duration = (selected_id == NUM_DURATIONS) ? DURATION_INFINITE : DURATIONS[selected_id]; + const unsigned selected_id = *GetCtrl(6)->GetSelection(); + const unsigned duration = (selected_id == NUM_DURATIONS) ? DURATION_INFINITE : DURATIONS[selected_id]; if(gcFactory.SuggestPact(player.GetPlayerId(), this->pt, duration)) Close(); } diff --git a/libs/s25main/ingameWindows/iwDirectIPConnect.cpp b/libs/s25main/ingameWindows/iwDirectIPConnect.cpp index 9017c91ba0..2d375095fd 100644 --- a/libs/s25main/ingameWindows/iwDirectIPConnect.cpp +++ b/libs/s25main/ingameWindows/iwDirectIPConnect.cpp @@ -94,7 +94,7 @@ void iwDirectIPConnect::Msg_ButtonClick(const unsigned ctrl_id) auto* edtHost = GetCtrl(ID_edtIp); auto* edtPort = GetCtrl(ID_edtPort); auto* edtPw = GetCtrl(ID_edtPw); - boost::optional port = validate::checkPort(edtPort->GetText()); + std::optional port = validate::checkPort(edtPort->GetText()); if(!port) { SetStatus(_("Invalid port. The valid port-range is 1 to 65535!"), COLOR_RED); diff --git a/libs/s25main/ingameWindows/iwDirectIPCreate.cpp b/libs/s25main/ingameWindows/iwDirectIPCreate.cpp index c18fa9cf24..fca0ab3713 100644 --- a/libs/s25main/ingameWindows/iwDirectIPCreate.cpp +++ b/libs/s25main/ingameWindows/iwDirectIPCreate.cpp @@ -132,7 +132,7 @@ void iwDirectIPCreate::Msg_ButtonClick(const unsigned ctrl_id) edtPw->SetFocus(false); break; } - boost::optional port = validate::checkPort(edtPort->GetText()); + std::optional port = validate::checkPort(edtPort->GetText()); if(!port) { SetText(_("Invalid port. The valid port-range is 1 to 65535!"), COLOR_RED, false); diff --git a/libs/s25main/ingameWindows/iwMapDebug.cpp b/libs/s25main/ingameWindows/iwMapDebug.cpp index 31f458929e..4cb4d65112 100644 --- a/libs/s25main/ingameWindows/iwMapDebug.cpp +++ b/libs/s25main/ingameWindows/iwMapDebug.cpp @@ -206,8 +206,8 @@ iwMapDebug::iwMapDebug(GameWorldView& gwv, bool allowCheating) players->AddItem(p.name); } players->SetSelection(0); - printer->showDataIdx = data->GetSelection().get(); - printer->playerIdx = players->GetSelection().get(); + printer->showDataIdx = *data->GetSelection(); + printer->playerIdx = *players->GetSelection(); } else { printer->showDataIdx = 0; diff --git a/libs/s25main/ingameWindows/iwMapGenerator.cpp b/libs/s25main/ingameWindows/iwMapGenerator.cpp index 3f64717a68..cffc9d82a0 100644 --- a/libs/s25main/ingameWindows/iwMapGenerator.cpp +++ b/libs/s25main/ingameWindows/iwMapGenerator.cpp @@ -133,7 +133,7 @@ void iwMapGenerator::Msg_ButtonClick(const unsigned ctrl_id) void iwMapGenerator::Apply() { - mapSettings.numPlayers = GetCtrl(ID_cbNumPlayers)->GetSelection().get() + 2; + mapSettings.numPlayers = *GetCtrl(ID_cbNumPlayers)->GetSelection() + 2; mapSettings.ratioGold = GetCtrl(ID_pgGoldRatio)->GetPosition(); mapSettings.ratioIron = GetCtrl(ID_pgIronRatio)->GetPosition(); mapSettings.ratioCoal = GetCtrl(ID_pgCoalRatio)->GetPosition(); @@ -156,9 +156,9 @@ void iwMapGenerator::Apply() case 2: mapSettings.style = MapStyle::Mixed; break; } mapSettings.size.x = - s25util::fromStringClassic(GetCtrl(ID_cbMapSizeX)->GetSelectedText().get_value_or("128")); + s25util::fromStringClassic(GetCtrl(ID_cbMapSizeX)->GetSelectedText().value_or("128")); mapSettings.size.y = - s25util::fromStringClassic(GetCtrl(ID_cbMapSizeY)->GetSelectedText().get_value_or("128")); + s25util::fromStringClassic(GetCtrl(ID_cbMapSizeY)->GetSelectedText().value_or("128")); switch(*GetCtrl(ID_cbIslands)->GetSelection()) { case 0: mapSettings.islands = IslandAmount::Few; break; diff --git a/libs/s25main/ingameWindows/iwSave.cpp b/libs/s25main/ingameWindows/iwSave.cpp index f13f232bd7..295e7a2fac 100644 --- a/libs/s25main/ingameWindows/iwSave.cpp +++ b/libs/s25main/ingameWindows/iwSave.cpp @@ -74,7 +74,7 @@ void iwSaveLoad::Msg_ButtonClick(const unsigned ctrl_id) SaveLoad(); } -void iwSaveLoad::Msg_TableSelectItem(const unsigned /*ctrl_id*/, const boost::optional& selection) +void iwSaveLoad::Msg_TableSelectItem(const unsigned /*ctrl_id*/, const std::optional& selection) { // On selecting a table entry put the filename into the edit control GetCtrl(ID_edtFilename) diff --git a/libs/s25main/ingameWindows/iwSave.h b/libs/s25main/ingameWindows/iwSave.h index 701863e4a6..d330fc5323 100644 --- a/libs/s25main/ingameWindows/iwSave.h +++ b/libs/s25main/ingameWindows/iwSave.h @@ -24,7 +24,7 @@ class iwSaveLoad : public IngameWindow void Msg_EditEnter(unsigned ctrl_id) override; void Msg_ButtonClick(unsigned ctrl_id) override; - void Msg_TableSelectItem(unsigned ctrl_id, const boost::optional& selection) override; + void Msg_TableSelectItem(unsigned ctrl_id, const std::optional& selection) override; }; class iwSave : public iwSaveLoad diff --git a/libs/s25main/ingameWindows/iwSettings.cpp b/libs/s25main/ingameWindows/iwSettings.cpp index ba791f6c6e..3a21c615f5 100644 --- a/libs/s25main/ingameWindows/iwSettings.cpp +++ b/libs/s25main/ingameWindows/iwSettings.cpp @@ -133,11 +133,10 @@ void iwSettings::Msg_ButtonClick(unsigned ctrl_id) SETTINGS.video.displayMode = DisplayMode(*GetCtrl(ID_cbDisplayMode)->GetSelection()); SETTINGS.video.displayMode.resizeable = !grpWindowSize.GetCtrl(ID_cbLockWindowSize)->isChecked(); SETTINGS.interface.mapScrollMode = - static_cast(GetCtrl(ID_cbMapScrollMode)->GetSelection().get()); + static_cast(*GetCtrl(ID_cbMapScrollMode)->GetSelection()); SETTINGS.video.fullscreenSize = supportedResolutions_ - [GetCtrl(ID_grpResolution)->GetCtrl(ID_cbResolution)->GetSelection().get()]; - const unsigned windowSizeSelection = - grpWindowSize.GetCtrl(ID_cbWindowSize)->GetSelection().get(); + [*GetCtrl(ID_grpResolution)->GetCtrl(ID_cbResolution)->GetSelection()]; + const unsigned windowSizeSelection = *grpWindowSize.GetCtrl(ID_cbWindowSize)->GetSelection(); if(windowSizeSelection > 0) SETTINGS.video.windowedSize = windowSizes_[windowSizeSelection - 1]; else if(VIDEODRIVER.GetDisplayMode() == DisplayMode::Windowed) diff --git a/libs/s25main/ingameWindows/iwTrade.cpp b/libs/s25main/ingameWindows/iwTrade.cpp index 13aebe03f7..1b4c03d980 100644 --- a/libs/s25main/ingameWindows/iwTrade.cpp +++ b/libs/s25main/ingameWindows/iwTrade.cpp @@ -77,7 +77,7 @@ iwTrade::iwTrade(const nobBaseWarehouse& wh, const GameWorldViewer& gwv, GameCom void iwTrade::Msg_ButtonClick(const unsigned /*ctrl_id*/) { // pressed the send button - const unsigned short ware_figure_selection = GetCtrl(4)->GetSelection().get(); + const unsigned short ware_figure_selection = *GetCtrl(4)->GetSelection(); const bool isJob = this->GetCtrl(2)->GetSelection() == 1u; boost_variant2 what; if(isJob) diff --git a/libs/s25main/network/GameServer.cpp b/libs/s25main/network/GameServer.cpp index 905968063f..cc867e2f3f 100644 --- a/libs/s25main/network/GameServer.cpp +++ b/libs/s25main/network/GameServer.cpp @@ -188,7 +188,7 @@ bool GameServer::Start(const CreateServerInfo& csi, const MapDescription& map, c if(map.lua_path.has_value() && !bfs::is_regular_file(*map.lua_path)) return false; - bfs::path luaFilePath = map.lua_path.get_value_or(bfs::path(mapinfo.filepath).replace_extension("lua")); + bfs::path luaFilePath = map.lua_path.value_or(bfs::path(mapinfo.filepath).replace_extension("lua")); if(bfs::is_regular_file(luaFilePath)) { if(!mapinfo.luaData.CompressFromFile(luaFilePath, &mapinfo.luaChecksum)) diff --git a/libs/s25main/nodeObjs/noAnimal.cpp b/libs/s25main/nodeObjs/noAnimal.cpp index 50c900b57f..43139a83e2 100644 --- a/libs/s25main/nodeObjs/noAnimal.cpp +++ b/libs/s25main/nodeObjs/noAnimal.cpp @@ -310,14 +310,14 @@ helpers::OptionalEnum noAnimal::FindDir() for(const auto dir2 : helpers::EnumRange{}) { if(world->GetPointRoad(dst, dir2) != PointRoad::None) - return boost::none; + return std::nullopt; } return dir; } } // kein Weg mehr gefunden - return boost::none; + return std::nullopt; } bool noAnimal::CanBeSkinned() const diff --git a/libs/s25main/pathfinding/RoadPathFinder.h b/libs/s25main/pathfinding/RoadPathFinder.h index 3d11347e0a..ccebdf87de 100644 --- a/libs/s25main/pathfinding/RoadPathFinder.h +++ b/libs/s25main/pathfinding/RoadPathFinder.h @@ -22,7 +22,7 @@ class RoadPathFinder /// Calculates the best path from start to goal /// Outputs are only valid if true is returned! - /// Direction might additionally be boost::none or SHIP_DIR + /// Direction might additionally be std::nullopt_t or SHIP_DIR /// /// @param wareMode True when path will be used by a ware (Allow boat roads and check for faster roads when road /// points have already many wares) diff --git a/libs/s25main/resources/ArchiveLocator.cpp b/libs/s25main/resources/ArchiveLocator.cpp index ca3c41ae07..7aaa562453 100644 --- a/libs/s25main/resources/ArchiveLocator.cpp +++ b/libs/s25main/resources/ArchiveLocator.cpp @@ -9,9 +9,9 @@ #include "resources/ResourceId.h" #include "s25util/Log.h" #include -#include #include #include +#include #include #include @@ -19,14 +19,14 @@ namespace fs = boost::filesystem; ArchiveLocator::ArchiveLocator(Log& logger) : logger_(logger) {} -static boost::optional makeResourceId(const fs::path& filename) +static std::optional makeResourceId(const fs::path& filename) { try { return ResourceId::make(filename); } catch(const std::invalid_argument&) { - return boost::none; + return std::nullopt; } } diff --git a/libs/s25main/world/GameWorld.cpp b/libs/s25main/world/GameWorld.cpp index 1922cfb443..6f1fe3314d 100644 --- a/libs/s25main/world/GameWorld.cpp +++ b/libs/s25main/world/GameWorld.cpp @@ -994,7 +994,7 @@ bool GameWorld::ValidWaitingAroundBuildingPoint(const MapPoint pt, const MapPoin return false; } // object wall or impassable terrain increasing my path to target length to a higher value than the direct distance? - return FindHumanPath(pt, center, CalcDistance(pt, center)) != boost::none; + return FindHumanPath(pt, center, CalcDistance(pt, center)) != std::nullopt; } bool GameWorld::IsValidPointForFighting(MapPoint pt, const nofActiveSoldier& soldier, diff --git a/libs/s25main/world/GameWorld.h b/libs/s25main/world/GameWorld.h index 0686a2c525..8e7bbcaf43 100644 --- a/libs/s25main/world/GameWorld.h +++ b/libs/s25main/world/GameWorld.h @@ -69,7 +69,7 @@ class GameWorld : public GameWorldBase /// Kann dieser Punkt von auf Straßen laufenden Menschen betreten werden? (Kämpfe!) bool IsRoadNodeForFigures(MapPoint pt); /// Lässt alle Figuren, die auf diesen Punkt auf Wegen zulaufen, anhalten auf dem Weg (wegen einem Kampf) - void StopOnRoads(MapPoint pt, helpers::OptionalEnum dir = boost::none); + void StopOnRoads(MapPoint pt, helpers::OptionalEnum dir = std::nullopt); /// Sagt Bescheid, dass der Punkt wieder freigeworden ist und lässt ggf. Figuren drumherum wieder weiterlaufen void RoadNodeAvailable(MapPoint pt); diff --git a/libs/s25main/world/GameWorldBase.h b/libs/s25main/world/GameWorldBase.h index 0a9ed60e36..13494c1c8d 100644 --- a/libs/s25main/world/GameWorldBase.h +++ b/libs/s25main/world/GameWorldBase.h @@ -127,9 +127,9 @@ class GameWorldBase : public World /// Return flag that is on road at given point. dir will be set to the direction of the road from the returned flag /// prevDir (if set) will be skipped when searching for the road points - noFlag* GetRoadFlag(MapPoint pt, Direction& dir, helpers::OptionalEnum prevDir = boost::none); + noFlag* GetRoadFlag(MapPoint pt, Direction& dir, helpers::OptionalEnum prevDir = std::nullopt); const noFlag* GetRoadFlag(MapPoint pt, Direction& dir, - helpers::OptionalEnum prevDir = boost::none) const; + helpers::OptionalEnum prevDir = std::nullopt) const; /// Gets the (height adjusted) global coordinates of the node (e.g. for drawing) Position GetNodePos(MapPoint pt) const; diff --git a/libs/s25main/world/TradeRoute.cpp b/libs/s25main/world/TradeRoute.cpp index aefba94938..66331ea7cd 100644 --- a/libs/s25main/world/TradeRoute.cpp +++ b/libs/s25main/world/TradeRoute.cpp @@ -31,7 +31,7 @@ helpers::OptionalEnum TradeRoute::GetNextDir() return TradeDirection::ReachedGoal; if(curRouteIdx >= path.route.size()) - return boost::none; + return std::nullopt; Direction nextDir; // Check if the route is still valid @@ -68,7 +68,7 @@ helpers::OptionalEnum TradeRoute::RecalcRoute() if(nextDir) return TradeDirection(rttr::enum_cast(*nextDir)); else - return boost::none; + return std::nullopt; } /// Assigns new start and goal positions and hence, a new route diff --git a/libs/s25main/world/TradeRoute.h b/libs/s25main/world/TradeRoute.h index 661100a267..99503b985c 100644 --- a/libs/s25main/world/TradeRoute.h +++ b/libs/s25main/world/TradeRoute.h @@ -29,7 +29,7 @@ class TradeRoute void Serialize(SerializedGameData& sgd) const; - /// Gets the next direction the caravane has to take, TradeDirection::ReachedGoal or boost::none + /// Gets the next direction the caravane has to take, TradeDirection::ReachedGoal or std::nullopt_t helpers::OptionalEnum GetNextDir(); /// Returns the current position. This is assumed to be the position currently walking to and reached by the time /// GetNextDir should be called diff --git a/tests/common/testOptionalEnum.cpp b/tests/common/testOptionalEnum.cpp index a511b32004..6369dbfdcb 100644 --- a/tests/common/testOptionalEnum.cpp +++ b/tests/common/testOptionalEnum.cpp @@ -58,14 +58,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(EmptyContainsNoValue, T, EnumsToTest) helpers::OptionalEnum defConstruct; BOOST_TEST(!defConstruct); BOOST_TEST(!defConstruct.has_value()); - BOOST_CHECK_THROW(defConstruct.value(), boost::bad_optional_access); + BOOST_CHECK_THROW(defConstruct.value(), std::bad_optional_access); BOOST_TEST(defConstruct.value_or(T::Value1) == T::Value1); BOOST_TEST(defConstruct.value_or(T::Value2) == T::Value2); - helpers::OptionalEnum noneConstruct(boost::none); + helpers::OptionalEnum noneConstruct(std::nullopt); BOOST_TEST(!noneConstruct); BOOST_TEST(!noneConstruct.has_value()); - BOOST_CHECK_THROW(noneConstruct.value(), boost::bad_optional_access); + BOOST_CHECK_THROW(noneConstruct.value(), std::bad_optional_access); BOOST_TEST(noneConstruct.value_or(T::Value1) == T::Value1); BOOST_TEST(noneConstruct.value_or(T::Value2) == T::Value2); } diff --git a/tests/s25Main/UI/testComboBox.cpp b/tests/s25Main/UI/testComboBox.cpp index 49af44ee4e..d35021e6b5 100644 --- a/tests/s25Main/UI/testComboBox.cpp +++ b/tests/s25Main/UI/testComboBox.cpp @@ -8,8 +8,8 @@ #include "uiHelper/uiHelpers.hpp" #include #include -#include #include +#include //-V:MOCK_METHOD:813 //-V:MOCK_EXPECT:807 diff --git a/tests/s25Main/integration/testSettings.cpp b/tests/s25Main/integration/testSettings.cpp index 79e8bb5617..d0f4fdc9e6 100644 --- a/tests/s25Main/integration/testSettings.cpp +++ b/tests/s25Main/integration/testSettings.cpp @@ -3,8 +3,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "Settings.h" -#include #include +#include BOOST_AUTO_TEST_SUITE(SettingsSuite) @@ -16,7 +16,7 @@ BOOST_AUTO_TEST_CASE(CheckPort) BOOST_TEST_REQUIRE(!validate::checkPort("-1")); BOOST_TEST_REQUIRE(!validate::checkPort("1-6")); BOOST_TEST_REQUIRE(!validate::checkPort("1.1")); - boost::optional port = validate::checkPort("1"); + std::optional port = validate::checkPort("1"); BOOST_TEST_REQUIRE(port); BOOST_TEST_REQUIRE(*port == 1u); port = validate::checkPort("100"); diff --git a/tests/s25Main/simple/testGameData.cpp b/tests/s25Main/simple/testGameData.cpp index a4d01887db..68a6a24f4f 100644 --- a/tests/s25Main/simple/testGameData.cpp +++ b/tests/s25Main/simple/testGameData.cpp @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(ProductionBuildingsAreNobUsual) if(!BuildingProperties::IsValid(bld)) continue; // Only nobUsuals can produce wares (though not all do) - if(!holds_alternative(BLD_WORK_DESC[bld].producedWare)) + if(!holds_alternative(BLD_WORK_DESC[bld].producedWare)) { BOOST_TEST_INFO("bld: " << bld); BOOST_TEST(BuildingProperties::IsUsual(bld));