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

Retrieving with optional of reference wrapper #79

Merged
merged 3 commits into from
Dec 24, 2023

Conversation

ftschirpke
Copy link
Owner

This PR merges the feature branch that was intended for the implementation of functions which would provide tools to deal with the different types of effects providers.
While implementing this I starting changing a lot of the content libraries' APIs.
Previously, one would first ask the library if something exists, and then get it, because get() would throw if the object wouldn't exist.

if (library.contains(item_name)) {
    const auto& item = library.get(item_name);
}

With the new approach, using std::optional in combination with std::reference_wrapper, only one hash has to be evaluated and we still have the security of references.

auto item_optional = library.get(item_name);
if (item_optional.has_value()) {
    const auto& item = item_optional.value();
}

This approach still has few problems, but I am going to merge it for now and open an issue about addressing these issues.

@ftschirpke ftschirpke merged commit 2926d79 into main Dec 24, 2023
12 checks passed
@ftschirpke ftschirpke deleted the effects_provider_differentiation branch December 24, 2023 01:48
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.

1 participant