Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional_vpart_position should be removed #3821

Open
Tracked by #3143
scarf005 opened this issue Dec 5, 2023 · 0 comments
Open
Tracked by #3143

optional_vpart_position should be removed #3821

scarf005 opened this issue Dec 5, 2023 · 0 comments

Comments

@scarf005
Copy link
Member

scarf005 commented Dec 5, 2023

The Situation

/**
* Simple wrapper to forward functions that may return a @ref std::optional
* to @ref vpart_position. They generally return an empty `optional`, or
* forward to the same function in `vpart_position`.
*/
class optional_vpart_position : public std::optional<vpart_position>
{
public:
optional_vpart_position( std::optional<vpart_position> p ) : std::optional<vpart_position>
( std::move( p ) ) { }
std::optional<std::string> get_label() const {
return has_value() ? value().get_label() : std::nullopt;
}
std::optional<vpart_reference> part_with_feature( const std::string &f, bool unbroken ) const;
std::optional<vpart_reference> part_with_feature( vpart_bitflags f, bool unbroken ) const;
std::optional<vpart_reference> obstacle_at_part() const;
std::optional<vpart_reference> part_displayed() const;
};

Why is it not desirable?

  1. It existed because it was before C++17 and used cata::optional. However with Migrate to C++17 #1953 and cata::and_then, it does not have special utility anymore.
  2. I'm a newbie in C++, but i think it's less preferable to extend class from STL and forward its methods.

image

  1. Clang-tidy raises false positive over its every single usage.

The solution

  1. convert all usages of optional_vpart_position into std::optional<vpart_position>.
  2. use cata::and_then for forwarding member functions.
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

No branches or pull requests

1 participant