Merge pull request #7551 from ethereum/060-cxx17-std-optional

Use `std::optional<>` rather than `boost::optional<>`
This commit is contained in:
chriseth
2019-10-28 12:17:31 +01:00
committed by GitHub
67 changed files with 173 additions and 168 deletions
+1 -1
View File
@@ -150,7 +150,7 @@ private:
bytes const& m_metadata;
};
boost::optional<map<string, string>> parseCBORMetadata(bytes const& _metadata)
std::optional<map<string, string>> parseCBORMetadata(bytes const& _metadata)
{
try
{
+2 -3
View File
@@ -21,9 +21,8 @@
#include <libdevcore/CommonData.h>
#include <boost/optional.hpp>
#include <map>
#include <optional>
#include <string>
namespace dev
@@ -48,7 +47,7 @@ std::string bytecodeSansMetadata(std::string const& _bytecode);
/// - bytes into hex strings
/// - booleans into "true"/"false" strings
/// - everything else is invalid
boost::optional<std::map<std::string, std::string>> parseCBORMetadata(bytes const& _metadata);
std::optional<std::map<std::string, std::string>> parseCBORMetadata(bytes const& _metadata);
/// Expects a serialised metadata JSON and returns true if the
/// content is valid metadata.
+1 -1
View File
@@ -184,7 +184,7 @@ bool EVMVersionRestrictedTestCase::validateSettings(langutil::EVMVersion _evmVer
break;
versionString = versionString.substr(versionBegin);
boost::optional<langutil::EVMVersion> version = langutil::EVMVersion::fromString(versionString);
std::optional<langutil::EVMVersion> version = langutil::EVMVersion::fromString(versionString);
if (!version)
throw runtime_error("Invalid EVM version: \"" + versionString + "\"");
+5 -5
View File
@@ -34,7 +34,7 @@ BOOST_AUTO_TEST_SUITE(IterateReplacing)
BOOST_AUTO_TEST_CASE(no_replacement)
{
vector<string> v{"abc", "def", "ghi"};
function<boost::optional<vector<string>>(string&)> f = [](string&) -> boost::optional<vector<string>> { return {}; };
function<std::optional<vector<string>>(string&)> f = [](string&) -> std::optional<vector<string>> { return {}; };
iterateReplacing(v, f);
vector<string> expectation{"abc", "def", "ghi"};
BOOST_CHECK(v == expectation);
@@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(no_replacement)
BOOST_AUTO_TEST_CASE(empty_input)
{
vector<string> v;
function<boost::optional<vector<string>>(string&)> f = [](string&) -> boost::optional<vector<string>> { return {}; };
function<std::optional<vector<string>>(string&)> f = [](string&) -> std::optional<vector<string>> { return {}; };
iterateReplacing(v, f);
vector<string> expectation;
BOOST_CHECK(v == expectation);
@@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(empty_input)
BOOST_AUTO_TEST_CASE(delete_some)
{
vector<string> v{"abc", "def", "ghi"};
function<boost::optional<vector<string>>(string&)> f = [](string& _s) -> boost::optional<vector<string>> {
function<std::optional<vector<string>>(string&)> f = [](string& _s) -> std::optional<vector<string>> {
if (_s == "def")
return vector<string>();
else
@@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE(delete_some)
BOOST_AUTO_TEST_CASE(inject_some_start)
{
vector<string> v{"abc", "def", "ghi"};
function<boost::optional<vector<string>>(string&)> f = [](string& _s) -> boost::optional<vector<string>> {
function<std::optional<vector<string>>(string&)> f = [](string& _s) -> std::optional<vector<string>> {
if (_s == "abc")
return vector<string>{"x", "y"};
else
@@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(inject_some_start)
BOOST_AUTO_TEST_CASE(inject_some_end)
{
vector<string> v{"abc", "def", "ghi"};
function<boost::optional<vector<string>>(string&)> f = [](string& _s) -> boost::optional<vector<string>> {
function<std::optional<vector<string>>(string&)> f = [](string& _s) -> std::optional<vector<string>> {
if (_s == "ghi")
return vector<string>{"x", "y"};
else
+3 -3
View File
@@ -34,11 +34,11 @@
#include <libevmasm/Assembly.h>
#include <boost/optional.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <string>
#include <memory>
#include <optional>
#include <string>
using namespace std;
using namespace langutil;
@@ -54,7 +54,7 @@ namespace test
namespace
{
boost::optional<Error> parseAndReturnFirstError(
std::optional<Error> parseAndReturnFirstError(
string const& _source,
bool _assemble = false,
bool _allowWarnings = true,
+1 -1
View File
@@ -41,7 +41,7 @@ map<string, string> requireParsedCBORMetadata(bytes const& _bytecode)
{
bytes cborMetadata = dev::test::onlyMetadata(_bytecode);
BOOST_REQUIRE(!cborMetadata.empty());
boost::optional<map<string, string>> tmp = dev::test::parseCBORMetadata(cborMetadata);
std::optional<map<string, string>> tmp = dev::test::parseCBORMetadata(cborMetadata);
BOOST_REQUIRE(tmp);
return *tmp;
}
+1 -1
View File
@@ -104,7 +104,7 @@ public:
/// @returns the number of instructions in the given bytecode, not taking the metadata hash
/// into account.
size_t numInstructions(bytes const& _bytecode, boost::optional<Instruction> _which = boost::optional<Instruction>{})
size_t numInstructions(bytes const& _bytecode, std::optional<Instruction> _which = std::optional<Instruction>{})
{
bytes realCode = bytecodeSansMetadata(_bytecode);
BOOST_REQUIRE_MESSAGE(!realCode.empty(), "Invalid or missing metadata in bytecode.");
+5 -5
View File
@@ -141,14 +141,14 @@ string functionSignatureFromABI(Json::Value const& _functionABI)
}
boost::optional<dev::solidity::test::ParameterList> ContractABIUtils::parametersFromJsonOutputs(
std::optional<dev::solidity::test::ParameterList> ContractABIUtils::parametersFromJsonOutputs(
ErrorReporter& _errorReporter,
Json::Value const& _contractABI,
string const& _functionSignature
)
{
if (!_contractABI)
return boost::none;
return std::nullopt;
for (auto const& function: _contractABI)
if (_functionSignature == functionSignatureFromABI(function))
@@ -177,17 +177,17 @@ boost::optional<dev::solidity::test::ParameterList> ContractABIUtils::parameters
"Could not convert \"" + type +
"\" to internal ABI type representation. Falling back to default encoding."
);
return boost::none;
return std::nullopt;
}
finalParams += inplaceTypeParams;
inplaceTypeParams.clear();
}
return boost::optional<ParameterList>(finalParams + dynamicTypeParams);
return std::optional<ParameterList>(finalParams + dynamicTypeParams);
}
return boost::none;
return std::nullopt;
}
bool ContractABIUtils::appendTypesFromName(
+1 -1
View File
@@ -42,7 +42,7 @@ public:
/// a list of internal type representations of isoltest.
/// Creates parameters from Contract ABI and is used to generate values for
/// auto-correction during interactive update routine.
static boost::optional<ParameterList> parametersFromJsonOutputs(
static std::optional<ParameterList> parametersFromJsonOutputs(
ErrorReporter& _errorReporter,
Json::Value const& _contractABI,
std::string const& _functionSignature
+1 -1
View File
@@ -24,11 +24,11 @@
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/optional.hpp>
#include <boost/throw_exception.hpp>
#include <fstream>
#include <memory>
#include <optional>
#include <stdexcept>
using namespace dev;
+9 -9
View File
@@ -20,8 +20,8 @@
#include <libdevcore/AnsiColorized.h>
#include <boost/algorithm/string/replace.hpp>
#include <boost/optional/optional.hpp>
#include <optional>
#include <stdexcept>
#include <string>
@@ -124,12 +124,12 @@ string TestFunctionCall::format(
if (!matchesExpectation())
{
boost::optional<ParameterList> abiParams;
std::optional<ParameterList> abiParams;
if (isFailure)
{
if (!output.empty())
abiParams = boost::make_optional(ContractABIUtils::failureParameters(output));
abiParams = ContractABIUtils::failureParameters(output);
}
else
abiParams = ContractABIUtils::parametersFromJsonOutputs(
@@ -139,7 +139,7 @@ string TestFunctionCall::format(
);
string bytesOutput = abiParams ?
BytesUtils::formatRawBytes(output, abiParams.get(), _linePrefix) :
BytesUtils::formatRawBytes(output, abiParams.value(), _linePrefix) :
BytesUtils::formatRawBytes(
output,
ContractABIUtils::defaultParameters(ceil(output.size() / 32)),
@@ -208,7 +208,7 @@ string TestFunctionCall::formatBytesParameters(
}
else
{
boost::optional<ParameterList> abiParams = ContractABIUtils::parametersFromJsonOutputs(
std::optional<ParameterList> abiParams = ContractABIUtils::parametersFromJsonOutputs(
_errorReporter,
m_contractABI,
_signature
@@ -216,17 +216,17 @@ string TestFunctionCall::formatBytesParameters(
if (abiParams)
{
boost::optional<ParameterList> preferredParams = ContractABIUtils::preferredParameters(
std::optional<ParameterList> preferredParams = ContractABIUtils::preferredParameters(
_errorReporter,
_parameters,
abiParams.get(),
abiParams.value(),
_bytes
);
if (preferredParams)
{
ContractABIUtils::overwriteParameters(_errorReporter, preferredParams.get(), abiParams.get());
os << BytesUtils::formatBytesRange(_bytes, preferredParams.get(), _highlight);
ContractABIUtils::overwriteParameters(_errorReporter, preferredParams.value(), abiParams.value());
os << BytesUtils::formatBytesRange(_bytes, preferredParams.value(), _highlight);
}
}
else
+3 -3
View File
@@ -27,11 +27,11 @@
#include <libsolidity/interface/OptimiserSettings.h>
#include <boost/optional.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <string>
#include <memory>
#include <optional>
#include <string>
using namespace std;
using namespace langutil;
@@ -63,7 +63,7 @@ std::pair<bool, ErrorList> parse(string const& _source)
return {false, {}};
}
boost::optional<Error> parseAndReturnFirstError(string const& _source, bool _allowWarnings = true)
std::optional<Error> parseAndReturnFirstError(string const& _source, bool _allowWarnings = true)
{
bool success;
ErrorList errors;
+4 -4
View File
@@ -31,11 +31,11 @@
#include <liblangutil/Scanner.h>
#include <liblangutil/ErrorReporter.h>
#include <boost/optional.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <string>
#include <memory>
#include <optional>
#include <string>
using namespace std;
using namespace dev;
@@ -61,7 +61,7 @@ bool parse(string const& _source, Dialect const& _dialect, ErrorReporter& errorR
return (yul::AsmAnalyzer(
analysisInfo,
errorReporter,
boost::none,
std::nullopt,
_dialect
)).analyze(*parserResult);
}
@@ -73,7 +73,7 @@ bool parse(string const& _source, Dialect const& _dialect, ErrorReporter& errorR
return false;
}
boost::optional<Error> parseAndReturnFirstError(string const& _source, Dialect const& _dialect, bool _allowWarnings = true)
std::optional<Error> parseAndReturnFirstError(string const& _source, Dialect const& _dialect, bool _allowWarnings = true)
{
ErrorList errors;
ErrorReporter errorReporter(errors);
+2 -2
View File
@@ -350,7 +350,7 @@ void setupTerminal()
#endif
}
boost::optional<TestStats> runTestSuite(
std::optional<TestStats> runTestSuite(
TestCreator _testCaseCreator,
TestOptions const& _options,
fs::path const& _basePath,
@@ -364,7 +364,7 @@ boost::optional<TestStats> runTestSuite(
if (!fs::exists(testPath) || !fs::is_directory(testPath))
{
cerr << _name << " tests not found. Use the --testpath argument." << endl;
return {};
return std::nullopt;
}
TestStats stats = TestTool::processPath(