Skip to content

Commit df729b3

Browse files
author
Christian Parpart
committed
Make use of C++17 std::optional<> instead of boost::optional<>.
1 parent 302a51a commit df729b3

67 files changed

Lines changed: 173 additions & 168 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CODING_STYLE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Use `solAssert` and `solUnimplementedAssert` generously to check assumptions tha
119119
4. Favour declarations close to use; don't habitually declare at top of scope ala C.
120120
5. Pass non-trivial parameters as const reference, unless the data is to be copied into the function, then either pass by const reference or by value and use std::move.
121121
6. If a function returns multiple values, use std::tuple (std::pair acceptable) or better introduce a struct type. Do not use */& arguments.
122-
7. Use parameters of pointer type only if ``nullptr`` is a valid argument, use references otherwise. Often, ``boost::optional`` is better suited than a raw pointer.
122+
7. Use parameters of pointer type only if ``nullptr`` is a valid argument, use references otherwise. Often, ``std::optional`` is better suited than a raw pointer.
123123
8. Never use a macro where adequate non-preprocessor C++ can be written.
124124
9. Only use ``auto`` if the type is very long and rather irrelevant.
125125
10. Do not pass bools: prefer enumerations instead.

libdevcore/CommonData.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525

2626
#include <libdevcore/Common.h>
2727

28-
#include <boost/optional.hpp>
29-
3028
#include <vector>
3129
#include <type_traits>
3230
#include <cstring>
31+
#include <optional>
3332
#include <string>
3433
#include <set>
3534
#include <functional>
@@ -277,7 +276,7 @@ void iterateReplacing(std::vector<T>& _vector, F const& _f)
277276
std::vector<T> modifiedVector;
278277
for (size_t i = 0; i < _vector.size(); ++i)
279278
{
280-
if (boost::optional<std::vector<T>> r = _f(_vector[i]))
279+
if (std::optional<std::vector<T>> r = _f(_vector[i]))
281280
{
282281
if (!useModified)
283282
{
@@ -305,7 +304,7 @@ void iterateReplacingWindow(std::vector<T>& _vector, F const& _f, std::index_seq
305304
size_t i = 0;
306305
for (; i + sizeof...(I) <= _vector.size(); ++i)
307306
{
308-
if (boost::optional<std::vector<T>> r = _f(_vector[i + I]...))
307+
if (std::optional<std::vector<T>> r = _f(_vector[i + I]...))
309308
{
310309
if (!useModified)
311310
{

liblangutil/EVMVersion.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
#include <libevmasm/Instruction.h>
2424

25+
#include <optional>
2526
#include <string>
2627

27-
#include <boost/optional.hpp>
2828
#include <boost/operators.hpp>
2929

3030

@@ -51,12 +51,12 @@ class EVMVersion:
5151
static EVMVersion istanbul() { return {Version::Istanbul}; }
5252
static EVMVersion berlin() { return {Version::Berlin}; }
5353

54-
static boost::optional<EVMVersion> fromString(std::string const& _version)
54+
static std::optional<EVMVersion> fromString(std::string const& _version)
5555
{
5656
for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople(), petersburg(), istanbul(), berlin()})
5757
if (_version == v.name())
5858
return v;
59-
return {};
59+
return std::nullopt;
6060
}
6161

6262
bool operator==(EVMVersion const& _other) const { return m_version == _other.m_version; }

liblangutil/Scanner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
#include <liblangutil/Common.h>
5454
#include <liblangutil/Exceptions.h>
5555
#include <liblangutil/Scanner.h>
56-
#include <boost/optional.hpp>
56+
5757
#include <algorithm>
58+
#include <optional>
5859
#include <ostream>
5960
#include <tuple>
6061

@@ -187,7 +188,7 @@ bool Scanner::scanHexByte(char& o_scannedByte)
187188
return true;
188189
}
189190

190-
boost::optional<unsigned> Scanner::scanUnicode()
191+
std::optional<unsigned> Scanner::scanUnicode()
191192
{
192193
unsigned x = 0;
193194
for (int i = 0; i < 4; i++)
@@ -718,7 +719,7 @@ bool Scanner::scanEscape()
718719
break;
719720
case 'u':
720721
{
721-
if (boost::optional<unsigned> codepoint = scanUnicode())
722+
if (auto const codepoint = scanUnicode(); codepoint.has_value())
722723
addUnicodeAsUTF8(*codepoint);
723724
else
724725
return false;

liblangutil/Scanner.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
#include <liblangutil/SourceLocation.h>
5858
#include <libdevcore/Common.h>
5959
#include <libdevcore/CommonData.h>
60+
61+
#include <optional>
6062
#include <iosfwd>
6163

6264
namespace langutil
@@ -207,7 +209,7 @@ class Scanner
207209
inline Token selectToken(char _next, Token _then, Token _else);
208210

209211
bool scanHexByte(char& o_scannedByte);
210-
boost::optional<unsigned> scanUnicode();
212+
std::optional<unsigned> scanUnicode();
211213

212214
/// Scans a single Solidity token.
213215
void scanToken();

libsolidity/analysis/ReferencesResolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ bool ReferencesResolver::visit(ElementaryTypeName const& _typeName)
122122
if (!_typeName.annotation().type)
123123
{
124124
_typeName.annotation().type = TypeProvider::fromElementaryTypeName(_typeName.typeName());
125-
if (_typeName.stateMutability().is_initialized())
125+
if (_typeName.stateMutability().has_value())
126126
{
127127
// for non-address types this was already caught by the parser
128128
solAssert(_typeName.annotation().type->category() == Type::Category::Address, "");
@@ -323,7 +323,7 @@ bool ReferencesResolver::visit(InlineAssembly const& _inlineAssembly)
323323
// Will be re-generated later with correct information
324324
// We use the latest EVM version because we will re-run it anyway.
325325
yul::AsmAnalysisInfo analysisInfo;
326-
boost::optional<Error::Type> errorTypeForLoose = Error::Type::SyntaxError;
326+
std::optional<Error::Type> errorTypeForLoose = Error::Type::SyntaxError;
327327
yul::AsmAnalyzer(
328328
analysisInfo,
329329
errorsIgnored,

libsolidity/analysis/ViewPureChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void ViewPureChecker::endVisit(InlineAssembly const& _inlineAssembly)
241241
void ViewPureChecker::reportMutability(
242242
StateMutability _mutability,
243243
SourceLocation const& _location,
244-
boost::optional<SourceLocation> const& _nestedLocation
244+
std::optional<SourceLocation> const& _nestedLocation
245245
)
246246
{
247247
if (_mutability > m_bestMutabilityAndLocation.mutability)

libsolidity/analysis/ViewPureChecker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <map>
2525
#include <memory>
26+
#include <optional>
2627

2728
namespace langutil
2829
{
@@ -67,7 +68,7 @@ class ViewPureChecker: private ASTConstVisitor
6768
void reportMutability(
6869
StateMutability _mutability,
6970
langutil::SourceLocation const& _location,
70-
boost::optional<langutil::SourceLocation> const& _nestedLocation = {}
71+
std::optional<langutil::SourceLocation> const& _nestedLocation = {}
7172
);
7273

7374
std::vector<std::shared_ptr<ASTNode>> const& m_ast;

libsolidity/ast/AST.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <json/json.h>
3737

3838
#include <memory>
39+
#include <optional>
3940
#include <string>
4041
#include <vector>
4142

@@ -912,22 +913,22 @@ class ElementaryTypeName: public TypeName
912913
ElementaryTypeName(
913914
SourceLocation const& _location,
914915
ElementaryTypeNameToken const& _elem,
915-
boost::optional<StateMutability> _stateMutability = {}
916+
std::optional<StateMutability> _stateMutability = {}
916917
): TypeName(_location), m_type(_elem), m_stateMutability(_stateMutability)
917918
{
918-
solAssert(!_stateMutability.is_initialized() || _elem.token() == Token::Address, "");
919+
solAssert(!_stateMutability.has_value() || _elem.token() == Token::Address, "");
919920
}
920921

921922
void accept(ASTVisitor& _visitor) override;
922923
void accept(ASTConstVisitor& _visitor) const override;
923924

924925
ElementaryTypeNameToken const& typeName() const { return m_type; }
925926

926-
boost::optional<StateMutability> const& stateMutability() const { return m_stateMutability; }
927+
std::optional<StateMutability> const& stateMutability() const { return m_stateMutability; }
927928

928929
private:
929930
ElementaryTypeNameToken m_type;
930-
boost::optional<StateMutability> m_stateMutability; ///< state mutability for address type
931+
std::optional<StateMutability> m_stateMutability; ///< state mutability for address type
931932
};
932933

933934
/**

libsolidity/ast/ASTAnnotations.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
#include <libsolidity/ast/ASTEnums.h>
2727
#include <libsolidity/ast/ExperimentalFeatures.h>
2828

29-
#include <boost/optional.hpp>
30-
3129
#include <map>
3230
#include <memory>
31+
#include <optional>
3332
#include <set>
3433
#include <vector>
3534

@@ -183,7 +182,7 @@ struct ExpressionAnnotation: ASTAnnotation
183182

184183
/// Types and - if given - names of arguments if the expr. is a function
185184
/// that is called, used for overload resoultion
186-
boost::optional<FuncCallArguments> arguments;
185+
std::optional<FuncCallArguments> arguments;
187186
};
188187

189188
struct IdentifierAnnotation: ExpressionAnnotation

0 commit comments

Comments
 (0)