WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
156266
Implement operator== and operator!= for Optional<>
https://bugs.webkit.org/show_bug.cgi?id=156266
Summary
Implement operator== and operator!= for Optional<>
Simon Fraser (smfr)
Reported
2016-04-05 17:21:44 PDT
Implement operator== and operator!= for Optional<>
Attachments
Patch
(4.81 KB, patch)
2016-04-05 17:22 PDT
,
Simon Fraser (smfr)
andersca
: review+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Simon Fraser (smfr)
Comment 1
2016-04-05 17:22:48 PDT
Created
attachment 275726
[details]
Patch
WebKit Commit Bot
Comment 2
2016-04-05 17:23:33 PDT
Attachment 275726
[details]
did not pass style-queue: ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:115: Consider using EXPECT_EQ instead of EXPECT_TRUE(a == b) [readability/check] [2] ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:116: Consider using EXPECT_EQ instead of EXPECT_TRUE(a == b) [readability/check] [2] ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:117: Consider using EXPECT_NE instead of EXPECT_FALSE(a == b) [readability/check] [2] ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:118: Consider using EXPECT_NE instead of EXPECT_FALSE(a == b) [readability/check] [2] ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:140: Consider using EXPECT_EQ instead of EXPECT_FALSE(a != b) [readability/check] [2] ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:141: Consider using EXPECT_NE instead of EXPECT_TRUE(a != b) [readability/check] [2] ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:142: Consider using EXPECT_EQ instead of EXPECT_FALSE(a != b) [readability/check] [2] ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:143: Consider using EXPECT_NE instead of EXPECT_TRUE(a != b) [readability/check] [2] ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:145: Consider using EXPECT_NE instead of EXPECT_TRUE(a != b) [readability/check] [2] ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:146: Consider using EXPECT_NE instead of EXPECT_TRUE(a != b) [readability/check] [2] Total errors found: 10 in 4 files If any of these errors are false positives, please file a bug against check-webkit-style.
Myles C. Maxfield
Comment 3
2016-04-05 17:28:33 PDT
Comment on
attachment 275726
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=275726&action=review
I think I should wait for Anders to give the r+, but LGTM.
> Source/WTF/wtf/Optional.h:202 > + return static_cast<bool>(lhs) == static_cast<bool>(rhs) && (!static_cast<bool>(lhs) || lhs.value() == rhs.value());
Wouldn't an if statement be cleaner? Are these taken directly from C++ docs?
> Source/WTF/wtf/Optional.h:256 > + return !(value == opt);
Perhaps it would be useful to make one with two template types, and static_cast one to the other, to try to compare things which aren't the same type but are convertible.
Simon Fraser (smfr)
Comment 4
2016-04-05 17:31:30 PDT
(In reply to
comment #2
)
>
Attachment 275726
[details]
did not pass style-queue: > > > ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:115: Consider using > EXPECT_EQ instead of EXPECT_TRUE(a == b) [readability/check] [2]
Using these didn't compile.(In reply to
comment #3
)
> Comment on
attachment 275726
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=275726&action=review
> > I think I should wait for Anders to give the r+, but LGTM. > > > Source/WTF/wtf/Optional.h:202 > > + return static_cast<bool>(lhs) == static_cast<bool>(rhs) && (!static_cast<bool>(lhs) || lhs.value() == rhs.value()); > > Wouldn't an if statement be cleaner?
But this is branchless.
> > Are these taken directly from C++ docs?
Some are.
Anders Carlsson
Comment 5
2016-04-06 11:35:18 PDT
(In reply to
comment #4
)
> (In reply to
comment #2
) > >
Attachment 275726
[details]
did not pass style-queue: > > > > > > ERROR: Tools/TestWebKitAPI/Tests/WTF/Optional.cpp:115: Consider using > > EXPECT_EQ instead of EXPECT_TRUE(a == b) [readability/check] [2] > > Using these didn't compile.(In reply to
comment #3
) > > > Comment on
attachment 275726
[details]
> > Patch > > > > View in context: > >
https://bugs.webkit.org/attachment.cgi?id=275726&action=review
> > > > I think I should wait for Anders to give the r+, but LGTM. > > > > > Source/WTF/wtf/Optional.h:202 > > > + return static_cast<bool>(lhs) == static_cast<bool>(rhs) && (!static_cast<bool>(lhs) || lhs.value() == rhs.value()); > > > > Wouldn't an if statement be cleaner? > > But this is branchless.
Pretty sure it isn't branchless. && and || always form branches. Besides, the compiler will be able to get rid of unnecessary branches - even if you use if statements.
> > > > Are these taken directly from C++ docs? > > Some are.
Simon Fraser (smfr)
Comment 6
2016-04-06 12:04:00 PDT
http://trac.webkit.org/changeset/199107
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug