aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Keresztes Schmidt <carbenium@outlook.com>2020-07-15 10:22:29 +0200
committerShauren <shauren.trinity@gmail.com>2022-01-23 18:05:59 +0100
commit770fbcca0cae18faac981a326d73996afc20b9ba (patch)
tree2e173ff2e397e56975cb37a10ec11119ec3af41f
parentcd86a015c46f8da581f86857e313d9c596dba7fa (diff)
Core/Misc: Replace boost::optional with std::optional (#25047)
C++17 is already mandatory, so it's a safe thing to do (cherry picked from commit 202fd41389973322f63186fd8e5a368fce3e1b04)
-rw-r--r--dep/boost/CMakeLists.txt3
-rw-r--r--src/common/Collision/DynamicTree.cpp4
-rw-r--r--src/common/Collision/Management/VMapManager2.cpp6
-rw-r--r--src/common/Utilities/Optional.h8
-rw-r--r--src/common/Utilities/OptionalFwd.h31
-rw-r--r--src/common/Utilities/TaskScheduler.cpp2
-rw-r--r--src/common/Utilities/TaskScheduler.h3
-rw-r--r--src/server/game/Chat/ChatCommands/ChatCommand.h12
-rw-r--r--src/server/game/Entities/Object/Object.h2
-rw-r--r--src/server/game/Entities/Unit/Unit.h1
-rw-r--r--src/server/game/Movement/MovementGenerators/ChaseMovementGenerator.cpp2
-rw-r--r--src/server/game/Spells/Spell.cpp8
-rw-r--r--src/server/scripts/Commands/cs_account.cpp8
-rw-r--r--src/server/scripts/Commands/cs_debug.cpp4
-rw-r--r--src/server/scripts/Commands/cs_go.cpp8
15 files changed, 35 insertions, 67 deletions
diff --git a/dep/boost/CMakeLists.txt b/dep/boost/CMakeLists.txt
index 6e1b1953d45..7c50c6e6fc2 100644
--- a/dep/boost/CMakeLists.txt
+++ b/dep/boost/CMakeLists.txt
@@ -79,9 +79,6 @@ target_compile_definitions(boost
-DBOOST_DATE_TIME_NO_LIB
-DBOOST_REGEX_NO_LIB
-DBOOST_CHRONO_NO_LIB
- # Due to MSVC linking error boost::none" already defined in scripts_...
- # May be removed when the requirement is raised to boost 1.61 on windows.
- -DBOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE
-DBOOST_SERIALIZATION_NO_LIB
-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE
-DBOOST_ASIO_NO_DEPRECATED
diff --git a/src/common/Collision/DynamicTree.cpp b/src/common/Collision/DynamicTree.cpp
index 3d8ca49a4fe..bd7034bbb6c 100644
--- a/src/common/Collision/DynamicTree.cpp
+++ b/src/common/Collision/DynamicTree.cpp
@@ -295,9 +295,9 @@ void DynamicMapTree::getAreaAndLiquidData(float x, float y, float z, PhaseShift
float liquidLevel;
if (!reqLiquidType || (dynamic_cast<VMAP::VMapManager2*>(VMAP::VMapFactory::createOrGetVMapManager())->GetLiquidFlagsPtr(liquidType) & reqLiquidType))
if (intersectionCallBack.GetHitModel()->GetLiquidLevel(v, intersectionCallBack.GetLocationInfo(), liquidLevel))
- data.liquidInfo = boost::in_place(liquidType, liquidLevel);
+ data.liquidInfo.emplace(liquidType, liquidLevel);
- data.areaInfo = boost::in_place(intersectionCallBack.GetHitModel()->GetNameSetId(),
+ data.areaInfo.emplace(intersectionCallBack.GetHitModel()->GetNameSetId(),
intersectionCallBack.GetLocationInfo().rootId,
intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(),
intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags());
diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp
index 0e663a66023..d60453ef97f 100644
--- a/src/common/Collision/Management/VMapManager2.cpp
+++ b/src/common/Collision/Management/VMapManager2.cpp
@@ -340,7 +340,7 @@ namespace VMAP
int32 adtId, rootId, groupId;
uint32 flags;
if (getAreaInfo(mapId, x, y, data.floorZ, flags, adtId, rootId, groupId))
- data.areaInfo = boost::in_place(adtId, rootId, groupId, flags);
+ data.areaInfo.emplace(adtId, rootId, groupId, flags);
return;
}
InstanceTreeMap::const_iterator instanceTree = GetMapTree(mapId);
@@ -355,10 +355,10 @@ namespace VMAP
float liquidLevel;
if (!reqLiquidType || (GetLiquidFlagsPtr(liquidType) & reqLiquidType))
if (info.hitInstance->GetLiquidLevel(pos, info, liquidLevel))
- data.liquidInfo = boost::in_place(liquidType, liquidLevel);
+ data.liquidInfo.emplace(liquidType, liquidLevel);
if (!IsVMAPDisabledForPtr(mapId, VMAP_DISABLE_AREAFLAG))
- data.areaInfo = boost::in_place(info.hitInstance->adtId, info.rootId, info.hitModel->GetWmoID(), info.hitModel->GetMogpFlags());
+ data.areaInfo.emplace(info.hitInstance->adtId, info.rootId, info.hitModel->GetWmoID(), info.hitModel->GetMogpFlags());
}
}
}
diff --git a/src/common/Utilities/Optional.h b/src/common/Utilities/Optional.h
index dc5cd970970..55b9675fc59 100644
--- a/src/common/Utilities/Optional.h
+++ b/src/common/Utilities/Optional.h
@@ -18,8 +18,10 @@
#ifndef TrinityCore_Optional_h__
#define TrinityCore_Optional_h__
-#include "OptionalFwd.h"
-#include <boost/optional.hpp>
-#include <boost/utility/in_place_factory.hpp>
+#include <optional>
+
+//! Optional helper class to wrap optional values within.
+template <class T>
+using Optional = std::optional<T>;
#endif // TrinityCore_Optional_h__
diff --git a/src/common/Utilities/OptionalFwd.h b/src/common/Utilities/OptionalFwd.h
deleted file mode 100644
index 516ebeb772e..00000000000
--- a/src/common/Utilities/OptionalFwd.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef OptionalFwd_h__
-#define OptionalFwd_h__
-
-namespace boost
-{
- template <class T>
- class optional;
-}
-
-//! Optional helper class to wrap optional values within.
-template <class T>
-using Optional = boost::optional<T>;
-
-#endif // OptionalFwd_h__
diff --git a/src/common/Utilities/TaskScheduler.cpp b/src/common/Utilities/TaskScheduler.cpp
index 8b04a060cf3..4874885eed6 100644
--- a/src/common/Utilities/TaskScheduler.cpp
+++ b/src/common/Utilities/TaskScheduler.cpp
@@ -188,7 +188,7 @@ TaskContext& TaskContext::SetGroup(TaskScheduler::group_t const group)
TaskContext& TaskContext::ClearGroup()
{
- _task->_group = boost::none;
+ _task->_group = std::nullopt;
return *this;
}
diff --git a/src/common/Utilities/TaskScheduler.h b/src/common/Utilities/TaskScheduler.h
index 9d5eabd94e2..da80d02be88 100644
--- a/src/common/Utilities/TaskScheduler.h
+++ b/src/common/Utilities/TaskScheduler.h
@@ -23,6 +23,7 @@
#include "Random.h"
#include <algorithm>
#include <chrono>
+#include <functional>
#include <vector>
#include <queue>
#include <memory>
@@ -83,7 +84,7 @@ class TC_COMMON_API TaskScheduler
// Minimal Argument construct
Task(timepoint_t const& end, duration_t const& duration, task_handler_t const& task)
- : _end(end), _duration(duration), _group(boost::none), _repeated(0), _task(task) { }
+ : _end(end), _duration(duration), _group(std::nullopt), _repeated(0), _task(task) { }
// Copy construct
Task(Task const&) = delete;
diff --git a/src/server/game/Chat/ChatCommands/ChatCommand.h b/src/server/game/Chat/ChatCommands/ChatCommand.h
index fdcf38745ad..840915b4d2f 100644
--- a/src/server/game/Chat/ChatCommands/ChatCommand.h
+++ b/src/server/game/Chat/ChatCommands/ChatCommand.h
@@ -121,11 +121,11 @@ struct CommandArgsConsumerMulti<Tuple, Optional<NestedNextType>, offset>
// try with the argument
auto& myArg = std::get<offset>(tuple);
myArg.emplace();
- if (char const* next = CommandArgsConsumerSingle<NestedNextType>::TryConsumeTo(*(myArg.get_ptr()), args))
+ if (char const* next = CommandArgsConsumerSingle<NestedNextType>::TryConsumeTo(myArg.value(), args))
if ((next = CommandArgsConsumerNext<Tuple, offset+1>::GoNext(tuple, next)))
return next;
// try again omitting the argument
- myArg = boost::none;
+ myArg = std::nullopt;
if (char const* next = CommandArgsConsumerNext<Tuple, offset+1>::GoNext(tuple, args))
return next;
return nullptr;
@@ -160,8 +160,8 @@ class TC_GAME_API CommandArgs
{
Optional<std::tuple<advstd::remove_cvref_t<T1>, advstd::remove_cvref_t<T2>, advstd::remove_cvref_t<Ts>...>> rv;
rv.emplace();
- if (!TryConsumeToTuple<0>(*(rv.get_ptr())))
- rv = boost::none;
+ if (!TryConsumeToTuple<0>(rv.value()))
+ rv = std::nullopt;
return rv;
}
@@ -171,10 +171,10 @@ class TC_GAME_API CommandArgs
using T = advstd::remove_cvref_t<T1>;
Optional<T> rv;
rv.emplace();
- if (char const* next = CommandArgsConsumerSingle<T>::TryConsumeTo(*(rv.get_ptr()), _args))
+ if (char const* next = CommandArgsConsumerSingle<T>::TryConsumeTo(rv.value(), _args))
_args = next;
else
- rv = boost::none;
+ rv = std::nullopt;
return rv;
}
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index 0d727b55d2e..0d5f16a3f30 100644
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -673,7 +673,7 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
void setActive(bool isActiveObject);
bool IsFarVisible() const { return m_isFarVisible; }
void SetFarVisible(bool on);
- bool IsVisibilityOverridden() const { return m_visibilityDistanceOverride.is_initialized(); }
+ bool IsVisibilityOverridden() const { return m_visibilityDistanceOverride.has_value(); }
void SetVisibilityDistanceOverride(VisibilityDistanceType type);
void SetWorldObject(bool apply);
bool IsPermanentWorldObject() const { return m_isWorldObject; }
diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h
index a3b4861ea20..5098645b431 100644
--- a/src/server/game/Entities/Unit/Unit.h
+++ b/src/server/game/Entities/Unit/Unit.h
@@ -20,7 +20,6 @@
#include "Object.h"
#include "CombatManager.h"
-#include "OptionalFwd.h"
#include "SpellAuraDefines.h"
#include "ThreatManager.h"
#include "Timer.h"
diff --git a/src/server/game/Movement/MovementGenerators/ChaseMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/ChaseMovementGenerator.cpp
index b3e9e56c81e..e6e68190d80 100644
--- a/src/server/game/Movement/MovementGenerators/ChaseMovementGenerator.cpp
+++ b/src/server/game/Movement/MovementGenerators/ChaseMovementGenerator.cpp
@@ -151,7 +151,7 @@ bool ChaseMovementGenerator::Update(Unit* owner, uint32 diff)
}
// if the target moved, we have to consider whether to adjust
- if (!_lastTargetPosition || target->GetPosition() != _lastTargetPosition.get() || mutualChase != _mutualChase)
+ if (!_lastTargetPosition || target->GetPosition() != _lastTargetPosition.value() || mutualChase != _mutualChase)
{
_lastTargetPosition = target->GetPosition();
_mutualChase = mutualChase;
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 43c9b441e7a..53213475be5 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -175,7 +175,7 @@ void SpellCastTargets::Write(WorldPackets::Spells::SpellTargetData& data)
if (m_targetMask & TARGET_FLAG_SOURCE_LOCATION)
{
- data.SrcLocation = boost::in_place();
+ data.SrcLocation.emplace();
data.SrcLocation->Transport = m_src._transportGUID; // relative position guid here - transport for example
if (!m_src._transportGUID.IsEmpty())
data.SrcLocation->Location = m_src._transportOffset;
@@ -185,7 +185,7 @@ void SpellCastTargets::Write(WorldPackets::Spells::SpellTargetData& data)
if (m_targetMask & TARGET_FLAG_DEST_LOCATION)
{
- data.DstLocation = boost::in_place();
+ data.DstLocation.emplace();
data.DstLocation->Transport = m_dst._transportGUID; // relative position guid here - transport for example
if (!m_dst._transportGUID.IsEmpty())
data.DstLocation->Location = m_dst._transportOffset;
@@ -4479,7 +4479,7 @@ void Spell::SendSpellStart()
if (castFlags & CAST_FLAG_RUNE_LIST) // rune cooldowns list
{
- castData.RemainingRunes = boost::in_place();
+ castData.RemainingRunes.emplace();
//TODO: There is a crash caused by a spell with CAST_FLAG_RUNE_LIST casted by a creature
//The creature is the mover of a player, so HandleCastSpellOpcode uses it as the caster
@@ -4593,7 +4593,7 @@ void Spell::SendSpellGo()
if (castFlags & CAST_FLAG_RUNE_LIST) // rune cooldowns list
{
- castData.RemainingRunes = boost::in_place();
+ castData.RemainingRunes.emplace();
Player* player = ASSERT_NOTNULL(m_caster->ToPlayer());
castData.RemainingRunes->Start = m_runesState; // runes state before
diff --git a/src/server/scripts/Commands/cs_account.cpp b/src/server/scripts/Commands/cs_account.cpp
index 2a3cbf577a3..29cc59266d6 100644
--- a/src/server/scripts/Commands/cs_account.cpp
+++ b/src/server/scripts/Commands/cs_account.cpp
@@ -256,7 +256,7 @@ public:
return false;
}
- switch (sAccountMgr->CreateAccount(accountName, password, email.get_value_or("")))
+ switch (sAccountMgr->CreateAccount(accountName, password, email.value_or("")))
{
case AccountOpResult::AOR_OK:
handler->PSendSysMessage(LANG_ACCOUNT_CREATED, accountName);
@@ -265,7 +265,7 @@ public:
TC_LOG_INFO("entities.player.character", "Account: %d (IP: %s) Character:[%s] %s) created Account %s (Email: '%s')",
handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(),
- accountName.c_str(), email.get_value_or("").c_str());
+ accountName.c_str(), email.value_or("").c_str());
}
break;
case AccountOpResult::AOR_NAME_TOO_LONG:
@@ -527,7 +527,7 @@ public:
// This compares the old, current email to the entered email - however, only...
if ((pwConfig == PW_EMAIL || (pwConfig == PW_RBAC && handler->HasPermission(rbac::RBAC_PERM_EMAIL_CONFIRM_FOR_PASS_CHANGE))) // ...if either PW_EMAIL or PW_RBAC with the Permission is active...
- && !AccountMgr::CheckEmail(handler->GetSession()->GetAccountId(), confirmEmail.get_value_or(""))) // ... and returns false if the comparison fails.
+ && !AccountMgr::CheckEmail(handler->GetSession()->GetAccountId(), confirmEmail.value_or(""))) // ... and returns false if the comparison fails.
{
handler->SendSysMessage(LANG_COMMAND_WRONGEMAIL);
sScriptMgr->OnFailedPasswordChange(handler->GetSession()->GetAccountId());
@@ -535,7 +535,7 @@ public:
TC_LOG_INFO("entities.player.character", "Account: %u (IP: %s) Character:[%s] %s Tried to change password, but the entered email [%s] is wrong.",
handler->GetSession()->GetAccountId(), handler->GetSession()->GetRemoteAddress().c_str(),
handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(),
- confirmEmail.get_value_or("").c_str());
+ confirmEmail.value_or("").c_str());
return false;
}
diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp
index aac8b3379e5..5f5a0caf3e1 100644
--- a/src/server/scripts/Commands/cs_debug.cpp
+++ b/src/server/scripts/Commands/cs_debug.cpp
@@ -1814,7 +1814,7 @@ public:
auto mapId = args->TryConsume<uint32>();
if (mapId)
{
- sMapMgr->DoForAllMapsWithMapId(mapId.get(),
+ sMapMgr->DoForAllMapsWithMapId(mapId.value(),
[handler](Map* map) -> void
{
HandleDebugGuidLimitsMap(handler, map);
@@ -1847,7 +1847,7 @@ public:
auto mapId = args->TryConsume<uint32>();
if (mapId)
{
- sMapMgr->DoForAllMapsWithMapId(mapId.get(),
+ sMapMgr->DoForAllMapsWithMapId(mapId.value(),
[handler](Map* map) -> void
{
HandleDebugObjectCountMap(handler, map);
diff --git a/src/server/scripts/Commands/cs_go.cpp b/src/server/scripts/Commands/cs_go.cpp
index 47e1c737849..ddcbfbba710 100644
--- a/src/server/scripts/Commands/cs_go.cpp
+++ b/src/server/scripts/Commands/cs_go.cpp
@@ -220,7 +220,7 @@ public:
static bool HandleGoGridCommand(ChatHandler* handler, float gridX, float gridY, Optional<uint32> oMapId)
{
Player* player = handler->GetSession()->GetPlayer();
- uint32 mapId = oMapId.get_value_or(player->GetMapId());
+ uint32 mapId = oMapId.value_or(player->GetMapId());
// center of grid
float x = (gridX - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
@@ -408,7 +408,7 @@ public:
static bool HandleGoXYZCommand(ChatHandler* handler, float x, float y, Optional<float> z, Optional<uint32> id, Optional<float> o)
{
Player* player = handler->GetSession()->GetPlayer();
- uint32 mapId = id.get_value_or(player->GetMapId());
+ uint32 mapId = id.value_or(player->GetMapId());
if (z)
{
if (!MapManager::IsValidMapCoord(mapId, x, y, *z))
@@ -430,7 +430,7 @@ public:
z = std::max(map->GetStaticHeight(PhasingHandler::GetEmptyPhaseShift(), x, y, MAX_HEIGHT), map->GetWaterLevel(PhasingHandler::GetEmptyPhaseShift(), x, y));
}
- return DoTeleport(handler, { x, y, *z, o.get_value_or(0.0f) }, mapId);
+ return DoTeleport(handler, { x, y, *z, o.value_or(0.0f) }, mapId);
}
template<typename T>
@@ -458,7 +458,7 @@ public:
static bool HandleGoOffsetCommand(ChatHandler* handler, float dX, Optional<float> dY, Optional<float> dZ, Optional<float> dO)
{
Position loc = handler->GetSession()->GetPlayer()->GetPosition();
- loc.RelocateOffset({ dX, dY.get_value_or(0.0f), dZ.get_value_or(0.0f), dO.get_value_or(0.0f) });
+ loc.RelocateOffset({ dX, dY.value_or(0.0f), dZ.value_or(0.0f), dO.value_or(0.0f) });
return DoTeleport(handler, loc);
}