replace boost::optional by std::optional (C++17)#7467
Closed
theStack wants to merge 3 commits intoargotorg:developfrom
Closed
replace boost::optional by std::optional (C++17)#7467theStack wants to merge 3 commits intoargotorg:developfrom
theStack wants to merge 3 commits intoargotorg:developfrom
Conversation
the following strings are replaced:
#include <boost/optional.hpp> -> #include <optional>
boost::optional -> std::optional
boost::make_optional -> std::make_optional
boost::none -> std::nullopt
this was done automatically with the following commands:
$ find . \( -name "*.cpp" -o -name "*.h" \) -exec sed -i 's/#include <boost\/optional.hpp>/#include <optional>/g' {} +
$ find . \( -name "*.cpp" -o -name "*.h" \) -exec sed -i 's/boost::optional/std::optional/g' {} +
$ find . \( -name "*.cpp" -o -name "*.h" \) -exec sed -i 's/boost::make_optional/std::make_optional/g' {} +
$ find . \( -name "*.cpp" -o -name "*.h" \) -exec sed -i 's/boost::none/std::nullopt/g' {} +
manual replacements: replaced boost::optional::is_initialized() by std::optional::has_value() replaced boost::optional::get() by std::optional::value()
for the conditional version of make_optional(), boost::make_optional(bool condition, T const& v); there is no corresponding function in C++17, hence we have to reconstruct its behaviour: that is, return the one-argument version of make_optional() if the condition is true and return std::nullopt otherwise.
Author
|
Oh no, as the Travis run shows, this doesn't compile with g++, failing on the file |
9 tasks
Collaborator
|
I think this is superseded by #7551, isn't it? Can we close this then? @christianparpart |
Collaborator
|
Closing this now since all required changes are done in #7551. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes one of three tasks of #7259 (Replace boost constructs with their C++17 STL equivalents.)
The replacement was done in three steps, one commit each:
automatic replacements through find/sed commands in all .cpp and .h files (
#include <boost/optional.hpp>->#include <optional>,boost::optional->std::optional,boost::make_optional->std::make_optional,boost::none->std::nullopt)manual replacements of functions to test for initialization and get value (
boost::optional::is_initialized()->std::optional::has_value(),boost::optional::get()->std::optional::value())manual replacements for conditional
boost::make_optional()(there is no equivalent in std::optional C++17, see commit message for further explanation)Compilation tested with clang 6.0.0. Running tests via
./scripts/test.shleads to 21 SolidityTests failures:*** 21 failures are detected in the test module "SolidityTests"but the number was exactly the same as for the latest commit in branch develop, hence I conclude that this PR doesn't break anything.