Skip to content

replace boost::optional by std::optional (C++17)#7467

Closed
theStack wants to merge 3 commits intoargotorg:developfrom
theStack:20190921-replace-boost_optional-by-std_optional
Closed

replace boost::optional by std::optional (C++17)#7467
theStack wants to merge 3 commits intoargotorg:developfrom
theStack:20190921-replace-boost_optional-by-std_optional

Conversation

@theStack
Copy link
Copy Markdown

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:

  1. 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)

  2. 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())

  3. 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.sh leads 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.

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.
@theStack
Copy link
Copy Markdown
Author

Oh no, as the Travis run shows, this doesn't compile with g++, failing on the file libyul/backends/wasm/WordSizeTransform.cpp. Should have tested it with more than just clang. Unfortunately I can't make any sense of the many-pages-long template error messages, the only thing I can deduce that there seems to be some problem with boost::variant. Any help to resolve this is appreciated.

@erak
Copy link
Copy Markdown
Collaborator

erak commented Oct 23, 2019

I think this is superseded by #7551, isn't it? Can we close this then? @christianparpart

@erak
Copy link
Copy Markdown
Collaborator

erak commented Oct 28, 2019

Closing this now since all required changes are done in #7551.

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