Skip to content

Commit

Permalink
std::function does not need cata::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrox committed Feb 29, 2020
1 parent 70aba01 commit 8124697
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/cata_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <algorithm>
#include <type_traits>

#include "optional.h"
#include "units.h"

class JsonIn;
Expand Down Expand Up @@ -514,19 +513,19 @@ int modulo( int v, int m );
class on_out_of_scope
{
private:
cata::optional<std::function<void()>> func;
std::function<void()> func;
public:
on_out_of_scope( const std::function<void()> &func ) : func( func ) {
}

~on_out_of_scope() {
if( func ) {
( *func )();
func();
}
}

void cancel() {
func.reset();
func = nullptr;
}
};

Expand Down
10 changes: 5 additions & 5 deletions src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ void editmap::update_view_with_help( const std::string &txt, const std::string &
#ifdef TILES
if( use_tiles ) {
if( draw_target_override ) {
draw_target_override.value()( p );
draw_target_override( p );
} else {
g->draw_highlight( p );
}
Expand Down Expand Up @@ -959,7 +959,7 @@ void editmap::edit_feature()
draw_override( p, override );
};
} else {
draw_target_override = cata::nullopt;
draw_target_override = nullptr;
}
input_context ctxt( emenu.input_category );
update_view_with_help( string_format( pgettext( "keybinding descriptions", "%s, %s, %s, %s, %s" ),
Expand Down Expand Up @@ -997,7 +997,7 @@ void editmap::edit_feature()
blink = emenu.ret == UILIST_TIMEOUT ? !blink : true;
} while( !quit );
blink = false;
draw_target_override = cata::nullopt;
draw_target_override = nullptr;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1061,7 +1061,7 @@ void editmap::edit_fld()
g->draw_field_override( p, override );
};
} else {
draw_target_override = cata::nullopt;
draw_target_override = nullptr;
}
input_context ctxt( fmenu.input_category );
// \u00A0 is the non-breaking space
Expand Down Expand Up @@ -1175,7 +1175,7 @@ void editmap::edit_fld()
blink = fmenu.ret == UILIST_TIMEOUT ? !blink : true;
} while( fmenu.ret != UILIST_CANCEL );
blink = false;
draw_target_override = cata::nullopt;
draw_target_override = nullptr;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/editmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class editmap
shapetype editshape;

std::vector<tripoint> target_list;
cata::optional<std::function<void( const tripoint &p )>> draw_target_override;
std::function<void( const tripoint &p )> draw_target_override;
std::map<std::string, editmap_hilight> hilights;
bool blink;
bool altblink;
Expand Down

0 comments on commit 8124697

Please sign in to comment.