Skip to content

Commit

Permalink
Switch assertions in optional.h to use CHECK macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
miki151 committed Jun 9, 2017
1 parent 43f8033 commit 3b6d43d
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 49 deletions.
1 change: 1 addition & 0 deletions clock.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "stdafx.h"
#include "extern/optional.h"

class Clock {
public:
Expand Down
22 changes: 13 additions & 9 deletions extern/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# include <utility>
# include <type_traits>
# include <initializer_list>
# include <cassert>
#include "debug.h"
# include <functional>
# include <string>
# include <stdexcept>
Expand Down Expand Up @@ -199,7 +199,7 @@ template <class T> inline constexpr typename std::remove_reference<T>::type&& co
#if defined NDEBUG
# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR)
#else
# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert(!#CHECK);}(), (EXPR)))
# define TR2_OPTIONAL_ASSERTED_EXPRESSION(COND, EXPR) ((COND) ? (EXPR) : ([]{CHECK(!#COND);}(), (EXPR)))
#endif


Expand Down Expand Up @@ -380,15 +380,15 @@ class optional : private OptionalBase<T>
template <class... Args>
void initialize(Args&&... args) noexcept(noexcept(T(std::forward<Args>(args)...)))
{
assert(!OptionalBase<T>::init_);
CHECK(!OptionalBase<T>::init_);
::new (static_cast<void*>(dataptr())) T(std::forward<Args>(args)...);
OptionalBase<T>::init_ = true;
}

template <class U, class... Args>
void initialize(std::initializer_list<U> il, Args&&... args) noexcept(noexcept(T(il, std::forward<Args>(args)...)))
{
assert(!OptionalBase<T>::init_);
CHECK(!OptionalBase<T>::init_);
::new (static_cast<void*>(dataptr())) T(il, std::forward<Args>(args)...);
OptionalBase<T>::init_ = true;
}
Expand Down Expand Up @@ -513,7 +513,7 @@ class optional : private OptionalBase<T>
# if OPTIONAL_HAS_MOVE_ACCESSORS == 1

OPTIONAL_MUTABLE_CONSTEXPR T* operator ->() {
assert (initialized());
CHECK(initialized());
return dataptr();
}

Expand All @@ -522,12 +522,12 @@ class optional : private OptionalBase<T>
}

OPTIONAL_MUTABLE_CONSTEXPR T& operator *() & {
assert (initialized());
CHECK(initialized());
return contained_val();
}

OPTIONAL_MUTABLE_CONSTEXPR T&& operator *() && {
assert (initialized());
CHECK(initialized());
return constexpr_move(contained_val());
}

Expand All @@ -547,7 +547,7 @@ class optional : private OptionalBase<T>
# else

T* operator ->() {
assert (initialized());
CHECK(initialized());
return dataptr();
}

Expand All @@ -556,7 +556,7 @@ class optional : private OptionalBase<T>
}

T& operator *() {
assert (initialized());
CHECK(initialized());
return contained_val();
}

Expand Down Expand Up @@ -1065,4 +1065,8 @@ namespace std
# undef TR2_OPTIONAL_REQUIRES
# undef TR2_OPTIONAL_ASSERTED_EXPRESSION

using std::experimental::optional;
using none_t = std::experimental::nullopt_t;
using std::experimental::none;

# endif //___OPTIONAL_HPP___
1 change: 1 addition & 0 deletions extern/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdexcept>
#include <type_traits>
#include <utility>
#include "extern/optional.h"

template <typename... Lambdas>
struct LambdaVisitor;
Expand Down
1 change: 0 additions & 1 deletion gui_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,6 @@ SGuiElem GuiBuilder::getItemLine(const ItemInfo& item, function<void(Rectangle)>
line.addMiddleElem(gui.label(item.name, color));
auto mainLine = gui.stack(
gui.buttonRect(onClick),
gui.uiHighlight(),
line.buildHorizontalList(),
getTooltip(getItemHint(item), (int) item.ids.getHash()));
line.clear();
Expand Down
35 changes: 0 additions & 35 deletions player_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,41 +907,6 @@ VillageInfo::Village PlayerControl::getVillageInfo(WConstCollective col) const {
return info;
}

/*void PlayerControl::handleRecruiting(WCollective ally) {
ScrollPosition scrollPos;
vector<WCreature> recruited;
vector<WCreature> transfers;
while (1) {
vector<WCreature> recruits = ally->getRecruits();
if (recruits.empty())
break;
vector<CreatureInfo> creatures = transform2<CreatureInfo>(recruits,
[] (WConstCreature c) { return CreatureInfo(c);});
string warning;
if (getCollective()->getPopulationSize() >= getCollective()->getMaxPopulation())
warning = "You have reached minion limit.";
auto index = getView()->chooseRecruit("Recruit from " + ally->getName().getShort(), warning,
{ViewId::GOLD, getCollective()->numResource(ResourceId::GOLD)}, creatures, &scrollPos);
if (!index)
break;
for (WCreature c : recruits)
if (c->getUniqueId() == *index) {
ally->recruit(c, getCollective());
recruited.push_back(c);
if (c->getLevel()->getModel() != getModel())
transfers.push_back(c);
getCollective()->takeResource({ResourceId::GOLD, c->getAttributes().getRecruitmentCost()});
break;
}
}
for (auto& stack : Creature::stack(recruited))
getCollective()->addNewCreatureMessage(stack);
if (!transfers.empty())
for (WCreature c : transfers)
// if (getGame()->canTransferCreature(c, getCollective()->getLevel()->getModel()))
getGame()->transferCreature(c, getModel());
}*/

void PlayerControl::handleTrading(WCollective ally) {
ScrollPosition scrollPos;
const set<Position>& storage = getCollective()->getZones().getPositions(ZoneId::STORAGE_EQUIPMENT);
Expand Down
4 changes: 0 additions & 4 deletions stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
#include <mutex>
#include <atomic>
#include <condition_variable>
#include "extern/optional.h"

#ifdef DEBUG_STL

Expand Down Expand Up @@ -163,6 +162,3 @@ inline thread::id currentThreadId() { return std::this_thread::get_id(); }
using std::atomic;
using std::swap;
using std::remove_if;
using std::experimental::optional;
using none_t = std::experimental::nullopt_t;
using std::experimental::none;
1 change: 1 addition & 0 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "owner_pointer.h"
#include "hashing.h"
#include "extern/variant.h"
#include "extern/optional.h"

template <class T>
string toString(const T& t) {
Expand Down

0 comments on commit 3b6d43d

Please sign in to comment.