Skip to content

Replace boost::optional by std::optional#1947

Open
Flamefire wants to merge 4 commits into
masterfrom
std-optional
Open

Replace boost::optional by std::optional#1947
Flamefire wants to merge 4 commits into
masterfrom
std-optional

Conversation

@Flamefire

@Flamefire Flamefire commented Jun 15, 2026

Copy link
Copy Markdown
Member

Unify uses now that we require C++17

@Flamefire Flamefire requested a review from Flow86 June 15, 2026 13:45
@Flamefire Flamefire mentioned this pull request Jun 15, 2026
Comment thread extras/ai-battle/main.cpp
Comment on lines +20 to +26
#if BOOST_VERSION >= 109000
# include <optional>
using std::optional;
#else
# include <boost/optional.hpp>
using boost::optional;
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this backward support?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we want to require Boost 1.90+. Prior to that Boost.programOptions didn't support std::optional. I wanted to make it clear when we can switch and remove "old" stuff

Comment thread libs/s25main/figures/nofDefender.h Outdated
Comment on lines 25 to 28

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move implementation into cpp file, then we dont need the stdexcept include here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

helpers::OptionalEnum<Job> job = std::nullopt;
/// Ware produced, if any
boost_variant2<GoodType, Job, boost::none_t> producedWare = boost::none;
boost_variant2<GoodType, Job, std::nullopt_t> producedWare = std::nullopt;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use std::variant too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boost_variant2 is never valueless which makes it easier to work with

[GetCtrl<ctrlGroup>(ID_grpResolution)->GetCtrl<ctrlComboBox>(ID_cbResolution)->GetSelection().get()];
const unsigned windowSizeSelection =
grpWindowSize.GetCtrl<ctrlComboBox>(ID_cbWindowSize)->GetSelection().get();
[*GetCtrl<ctrlGroup>(ID_grpResolution)->GetCtrl<ctrlComboBox>(ID_cbResolution)->GetSelection()];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the * is ambigious, maybe use explicit .value() here, also can we make sure a selection does exist? (clang-tidy with specific settings would cause a unchecked optional access warning here)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm missing a get or similar unchecked access method for std::optional
But speed doesn't matter here anyway so .value() it is

Comment thread libs/s25main/world/GameWorld.cpp Outdated
}
// object wall or impassable terrain increasing my path to target length to a higher value than the direct distance?
return FindHumanPath(pt, center, CalcDistance(pt, center)) != boost::none;
return FindHumanPath(pt, center, CalcDistance(pt, center)) != std::nullopt;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a .has_value()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a matter of style. But sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants