Changeset 231342 in webkit


Ignore:
Timestamp:
May 3, 2018 6:00:18 PM (6 years ago)
Author:
Yusuke Suzuki
Message:

Use default std::optional if it is provided
https://bugs.webkit.org/show_bug.cgi?id=185159

Reviewed by Michael Catanzaro.

Source/WebKit:

  • Shared/SandboxExtension.h:

(WebKit::SandboxExtension::Handle::decode):

  • Shared/TouchBarMenuItemData.cpp:

(WebKit::TouchBarMenuItemData::decode):

Source/WTF:

  • wtf/Expected.h:
  • wtf/Optional.h:

Do not use <optional> for clang currently.
(WTF::valueOrCompute):

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r231337 r231342  
     12018-05-03  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Use default std::optional if it is provided
     4        https://bugs.webkit.org/show_bug.cgi?id=185159
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        * wtf/Expected.h:
     9        * wtf/Optional.h:
     10        Do not use <optional> for clang currently.
     11        (WTF::valueOrCompute):
     12
    1132018-05-03  Filip Pizlo  <fpizlo@apple.com>
    214
  • trunk/Source/WTF/wtf/Expected.h

    r231308 r231342  
    574574}}} // namespace std::experimental::fundamentals_v3
    575575
    576 __EXPECTED_INLINE_VARIABLE constexpr std::experimental::unexpected_t& unexpect = std::experimental::unexpect;
     576__EXPECTED_INLINE_VARIABLE constexpr auto& unexpect = std::experimental::unexpect;
    577577template<class T, class E> using Expected = std::experimental::expected<T, E>;
  • trunk/Source/WTF/wtf/Optional.h

    r231308 r231342  
    4747# include <wtf/Compiler.h>
    4848# include <wtf/StdLibExtras.h>
     49
     50#if !COMPILER(MSVC) && !PLATFORM(COCOA) && __has_include(<optional>)
     51# include <optional>
     52#else
    4953
    5054# define TR2_OPTIONAL_REQUIRES(...) typename std::enable_if<__VA_ARGS__::value, bool>::type = false
     
    10131017} // namespace std
    10141018
     1019namespace std
     1020{
     1021  template <typename T>
     1022  struct hash<std::optional<T>>
     1023  {
     1024    typedef typename hash<T>::result_type result_type;
     1025    typedef std::optional<T> argument_type;
     1026
     1027    constexpr result_type operator()(argument_type const& arg) const {
     1028      return arg ? std::hash<T>{}(*arg) : result_type{};
     1029    }
     1030  };
     1031
     1032  template <typename T>
     1033  struct hash<std::optional<T&>>
     1034  {
     1035    typedef typename hash<T>::result_type result_type;
     1036    typedef std::optional<T&> argument_type;
     1037
     1038    constexpr result_type operator()(argument_type const& arg) const {
     1039      return arg ? std::hash<T>{}(*arg) : result_type{};
     1040    }
     1041  };
     1042}
     1043
     1044# undef TR2_OPTIONAL_REQUIRES
     1045# undef TR2_OPTIONAL_ASSERTED_EXPRESSION
     1046
     1047#endif // defined(__cpp_lib_optional)
     1048
    10151049namespace WTF {
    10161050
     
    10271061} // namespace WTF
    10281062
    1029 namespace std
    1030 {
    1031   template <typename T>
    1032   struct hash<std::optional<T>>
    1033   {
    1034     typedef typename hash<T>::result_type result_type;
    1035     typedef std::optional<T> argument_type;
    1036 
    1037     constexpr result_type operator()(argument_type const& arg) const {
    1038       return arg ? std::hash<T>{}(*arg) : result_type{};
    1039     }
    1040   };
    1041 
    1042   template <typename T>
    1043   struct hash<std::optional<T&>>
    1044   {
    1045     typedef typename hash<T>::result_type result_type;
    1046     typedef std::optional<T&> argument_type;
    1047 
    1048     constexpr result_type operator()(argument_type const& arg) const {
    1049       return arg ? std::hash<T>{}(*arg) : result_type{};
    1050     }
    1051   };
    1052 }
    1053 
    1054 # undef TR2_OPTIONAL_REQUIRES
    1055 # undef TR2_OPTIONAL_ASSERTED_EXPRESSION
    1056 
    10571063using WTF::valueOrCompute;
  • trunk/Source/WebKit/ChangeLog

    r231327 r231342  
     12018-05-03  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Use default std::optional if it is provided
     4        https://bugs.webkit.org/show_bug.cgi?id=185159
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        * Shared/SandboxExtension.h:
     9        (WebKit::SandboxExtension::Handle::decode):
     10        * Shared/TouchBarMenuItemData.cpp:
     11        (WebKit::TouchBarMenuItemData::decode):
     12
    1132018-05-03  Justin Fan  <justin_fan@apple.com>
    214
  • trunk/Source/WebKit/Shared/SandboxExtension.h

    r231308 r231342  
    121121inline SandboxExtension::Handle::~Handle() { }
    122122inline void SandboxExtension::Handle::encode(IPC::Encoder&) const { }
    123 inline std::optional<SandboxExtension::Handle> SandboxExtension::Handle::decode(IPC::Decoder&) { return {{ }}; }
     123inline std::optional<SandboxExtension::Handle> SandboxExtension::Handle::decode(IPC::Decoder&) { return SandboxExtension::Handle { }; }
    124124inline SandboxExtension::HandleArray::HandleArray() { }
    125125inline SandboxExtension::HandleArray::~HandleArray() { }
  • trunk/Source/WebKit/Shared/TouchBarMenuItemData.cpp

    r231308 r231342  
    6666        return std::nullopt;
    6767   
    68     return WTFMove(result);
     68    return std::make_optional(WTFMove(result));
    6969}
    7070
Note: See TracChangeset for help on using the changeset viewer.