Implement WTF::Expected
authorjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Nov 2016 19:28:36 +0000 (19:28 +0000)
committerjfbastien@apple.com <jfbastien@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Nov 2016 19:28:36 +0000 (19:28 +0000)
commit0e247a286810303e405a84835dea8024294ee828
tree193c8fec1c29afdfe1442a81662ede101d3b54fc
parentee55bc9174b5d5273a1b2668dbe48ab235d1b3d4
Implement WTF::Expected
https://bugs.webkit.org/show_bug.cgi?id=164526

Reviewed by Yusuke Suzuki.

std::expected isn't in C++17, and may be in C++20. It's a nice
complement to std::any / std::optional because it's a type-tagged
union which has a single expected result but could also contain an
error.

This would be useful in the WebAssembly parser, for example.

Using this implementation will allow us to provide feedback to the
standards committee and guide std::expected's design before it
gets standardized. I've already sent a bunch of feedback to the
author based on my experience implementing this.

This could supplement WTF::Either and WTF::ExceptionOr.

Source/WTF:

* WTF.xcodeproj/project.pbxproj:
* wtf/Compiler.h: Add RELAXED_CONSTEXPR
* wtf/Expected.h: Added.
(WTF::UnexpectedType::UnexpectedType):
(WTF::UnexpectedType::value):
(WTF::operator==):
(WTF::operator!=):
(WTF::operator<):
(WTF::operator>):
(WTF::operator<=):
(WTF::operator>=):
(WTF::makeUnexpected):
(WTF::ExpectedDetail::Throw):
(WTF::ExpectedDetail::ConstexprBase::ConstexprBase):
(WTF::ExpectedDetail::Base::Base):
(WTF::ExpectedDetail::Base::~Base):
(WTF::Expected::Expected):
(WTF::Expected::operator=):
(WTF::Expected::swap):
(WTF::Expected::operator->):
(WTF::Expected::operator*):
(WTF::Expected::operator bool):
(WTF::Expected::hasValue):
(WTF::Expected::value):
(WTF::Expected::error):
(WTF::Expected::getUnexpected):
(WTF::Expected::valueOr):
(WTF::swap):
(WTF::makeExpected):
(WTF::makeExpectedFromError):

Tools:

* TestWebKitAPI/CMakeLists.txt:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/Expected.cpp: Added.
(WTF::operator<<):
(TestWebKitAPI::TEST):
(TestWebKitAPI::foo::foo):
(TestWebKitAPI::foo::~foo):
(TestWebKitAPI::foo::operator==):
(TestWebKitAPI::operator<<):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208670 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/Compiler.h
Source/WTF/wtf/Expected.h [new file with mode: 0644]
Tools/ChangeLog
Tools/DumpRenderTree/PlatformMac.cmake
Tools/TestWebKitAPI/CMakeLists.txt
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WTF/Expected.cpp [new file with mode: 0644]