Core/Misc: Replace boost::optional with std::optional (#25047)

C++17 is already mandatory, so it's a safe thing to do
This commit is contained in:
Peter Keresztes Schmidt
2020-07-15 10:22:29 +02:00
committed by GitHub
parent ce1e2c0f9b
commit 202fd41389
16 changed files with 44 additions and 77 deletions

View File

@@ -83,10 +83,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_CHRONO_NO_LIB
-DBOOST_SERIALIZATION_NO_LIB
-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE
-DBOOST_ASIO_NO_DEPRECATED

View File

@@ -318,9 +318,9 @@ void DynamicMapTree::getAreaAndLiquidData(float x, float y, float z, uint32 phas
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(0,
data.areaInfo.emplace(0,
intersectionCallBack.GetLocationInfo().rootId,
intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(),
intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags());

View File

@@ -287,7 +287,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);
@@ -304,10 +304,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());
}
}
}

View File

@@ -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__

View File

@@ -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__

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -498,7 +498,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; }

View File

@@ -20,7 +20,6 @@
#include "Object.h"
#include "CombatManager.h"
#include "OptionalFwd.h"
#include "SpellAuraDefines.h"
#include "ThreatManager.h"
#include "Timer.h"

View File

@@ -2759,7 +2759,7 @@ void Map::GetFullTerrainStatusForPosition(uint32 phaseMask, float x, float y, fl
{
if (wmoData->areaInfo)
{
data.areaInfo = boost::in_place(wmoData->areaInfo->adtId, wmoData->areaInfo->rootId, wmoData->areaInfo->groupId, wmoData->areaInfo->mogpFlags);
data.areaInfo.emplace(wmoData->areaInfo->adtId, wmoData->areaInfo->rootId, wmoData->areaInfo->groupId, wmoData->areaInfo->mogpFlags);
// wmo found
WMOAreaTableEntry const* wmoEntry = GetWMOAreaTableEntryByTripple(wmoData->areaInfo->rootId, wmoData->areaInfo->adtId, wmoData->areaInfo->groupId);
data.outdoors = (wmoData->areaInfo->mogpFlags & 0x8) != 0;
@@ -2820,7 +2820,7 @@ void Map::GetFullTerrainStatusForPosition(uint32 phaseMask, float x, float y, fl
}
}
data.liquidInfo = boost::in_place();
data.liquidInfo.emplace();
data.liquidInfo->level = wmoData->liquidInfo->level;
data.liquidInfo->depth_level = wmoData->floorZ;
data.liquidInfo->entry = liquidType;

View File

@@ -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;

View File

@@ -185,14 +185,14 @@ void SpellCastTargets::Write(WorldPackets::Spells::SpellTargetData& data)
if (m_targetMask & (TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM))
{
data.Item = boost::in_place();
data.Item.emplace();
if (m_itemTarget)
data.Item = m_itemTarget->GetGUID();
}
if (m_targetMask & TARGET_FLAG_SOURCE_LOCATION)
{
data.SrcLocation = boost::in_place();
data.SrcLocation.emplace();
data.SrcLocation->Transport = m_src._transportGUID;
if (!m_src._transportGUID.IsEmpty())
data.SrcLocation->Location = m_src._transportOffset;
@@ -202,7 +202,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;
if (m_dst._transportGUID)
data.DstLocation->Location = m_dst._transportOffset;
@@ -4214,13 +4214,13 @@ void Spell::SendSpellStart()
if (castFlags & CAST_FLAG_AMMO)
{
castData.Ammo = boost::in_place();
castData.Ammo.emplace();
UpdateSpellCastDataAmmo(*castData.Ammo);
}
if (castFlags & CAST_FLAG_IMMUNITY)
{
castData.Immunities = boost::in_place();
castData.Immunities.emplace();
castData.Immunities->School = schoolImmunityMask;
castData.Immunities->Value = mechanicImmunityMask;
}
@@ -4290,7 +4290,7 @@ void Spell::SendSpellGo()
if (castFlags & CAST_FLAG_RUNE_LIST && !m_spellInfo->HasAura(SPELL_AURA_CONVERT_RUNE)) // 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 cast by a creature
// The creature is the mover of a player, so HandleCastSpellOpcode uses it as the caster
@@ -4316,14 +4316,14 @@ void Spell::SendSpellGo()
if (castFlags & CAST_FLAG_ADJUST_MISSILE)
{
castData.MissileTrajectory = boost::in_place();
castData.MissileTrajectory.emplace();
castData.MissileTrajectory->Pitch = m_targets.GetElevation();
castData.MissileTrajectory->TravelTime = m_delayMoment;
}
if (castFlags & CAST_FLAG_AMMO)
{
castData.Ammo = boost::in_place();
castData.Ammo.emplace();
UpdateSpellCastDataAmmo(*castData.Ammo);
}
@@ -4337,7 +4337,7 @@ void Spell::SendSpellGo()
// update nearby players (remove flag)
castData.CastFlags &= ~CAST_FLAG_POWER_LEFT_SELF;
castData.RemainingPower = boost::none;
castData.RemainingPower = std::nullopt;
m_caster->SendMessageToSet(packet.Write(), false);
}
else
@@ -4431,8 +4431,8 @@ void Spell::UpdateSpellCastDataAmmo(WorldPackets::Spells::SpellAmmo& ammo)
/// Writes miss and hit targets for a SMSG_SPELL_GO packet
void Spell::UpdateSpellCastDataTargets(WorldPackets::Spells::SpellCastData& data)
{
data.HitTargets = boost::in_place();
data.MissStatus = boost::in_place();
data.HitTargets.emplace();
data.MissStatus.emplace();
// This function also fill data for channeled spells:
// m_needAliveTargetMask req for stop channelig if one target die

View File

@@ -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;
}

View File

@@ -1917,7 +1917,7 @@ public:
auto mapId = args->TryConsume<uint32>();
if (mapId)
{
sMapMgr->DoForAllMapsWithMapId(mapId.get(),
sMapMgr->DoForAllMapsWithMapId(mapId.value(),
[handler](Map* map) -> void
{
HandleDebugGuidLimitsMap(handler, map);
@@ -1950,7 +1950,7 @@ public:
auto mapId = args->TryConsume<uint32>();
if (mapId)
{
sMapMgr->DoForAllMapsWithMapId(mapId.get(),
sMapMgr->DoForAllMapsWithMapId(mapId.value(),
[handler](Map* map) -> void
{
HandleDebugObjectCountMap(handler, map);

View File

@@ -214,7 +214,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;
@@ -337,7 +337,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))
@@ -359,7 +359,7 @@ public:
z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(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);
}
static bool HandleGoTicketCommand(ChatHandler* handler, uint32 ticketId)
@@ -386,7 +386,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);
}