Added utils::has_optional_value

This commit is contained in:
Charles Dang 2021-01-03 15:50:59 +11:00
parent 4b685a93e6
commit ba7ea3ca98
4 changed files with 22 additions and 23 deletions

View File

@ -134,11 +134,7 @@ 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_;

View File

@ -48,11 +48,7 @@ public:
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_; }

View File

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

View File

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