Skip to content

Commit

Permalink
Added utils::has_optional_value
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Jan 3, 2021
1 parent 4b685a9 commit ba7ea3c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
6 changes: 1 addition & 5 deletions src/play_controller.hpp
Expand Up @@ -134,11 +134,7 @@ class play_controller : public controller_base, public events::observer, public
gamestate().end_level_data_.reset();
}
bool is_regular_game_end() const {
#if defined HAVE_CXX17 || BOOST_VERSION >= 106800
return gamestate().end_level_data_.has_value();
#else
return gamestate().end_level_data_ != utils::nullopt;
#endif
return utils::has_optional_value(gamestate().end_level_data_);
}
const end_level_data& get_end_level_data_const() const {
return *gamestate().end_level_data_;
Expand Down
6 changes: 1 addition & 5 deletions src/replay_controller.hpp
Expand Up @@ -48,11 +48,7 @@ class replay_controller : public events::observer
bool should_stop() const { return stop_condition_->should_stop(); }
bool can_execute_command(const hotkey::hotkey_command& cmd, int index) const;
bool is_controlling_view() const {
#if defined HAVE_CXX17 || BOOST_VERSION >= 106800
return vision_.has_value();
#else
return vision_ != utils::nullopt;
#endif
return utils::has_optional_value(vision_);
}
bool allow_reset_replay() const { return reset_state_.get() != nullptr; }
const std::shared_ptr<config>& get_reset_state() const { return reset_state_; }
Expand Down
6 changes: 1 addition & 5 deletions src/serialization/preprocessor.hpp
Expand Up @@ -93,11 +93,7 @@ struct preproc_define
version_info deprecation_version;

bool is_deprecated() const {
#if defined HAVE_CXX17 || BOOST_VERSION >= 106800
return deprecation_level.has_value();
#else
return deprecation_level != utils::nullopt;
#endif
return utils::has_optional_value(deprecation_level);
}

void write(config_writer&, const std::string&) const;
Expand Down
27 changes: 19 additions & 8 deletions src/utils/optional_fwd.hpp
@@ -1,14 +1,14 @@
/*
Copyright (C) 2020 by the Battle for Wesnoth Project http://www.wesnoth.org/
Copyright (C) 2020 by the Battle for Wesnoth Project http://www.wesnoth.org/
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.
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.
See the COPYING file for more details.
See the COPYING file for more details.
*/

#pragma once
Expand Down Expand Up @@ -36,4 +36,15 @@ using boost::optional;
static const boost::none_t nullopt{boost::none_t::init_tag{}};

#endif

template<typename T>
bool has_optional_value(const optional<T>& opt)
{
#if defined HAVE_CXX17 || BOOST_VERSION >= 106800
return opt.has_value();
#else
return opt != nullopt;
#endif
}

} // end namespace utils

0 comments on commit ba7ea3c

Please sign in to comment.