Nullopt and InPlace should be structs, not enum values
[WebKit-https.git] / Source / WTF / wtf / Optional.h
index 979f097..fa0edf7 100644 (file)
 
 namespace WTF {
 
-enum InPlaceTag { InPlace };
-enum NulloptTag { Nullopt };
+struct InPlaceTag { };
+constexpr InPlaceTag InPlace { };
+
+struct NulloptTag { explicit constexpr NulloptTag(int) { } };
+constexpr NulloptTag Nullopt { 0 };
 
 template<typename T>
 class Optional {
@@ -193,10 +196,18 @@ private:
     typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type m_value;
 };
 
+template<typename T>
+Optional<typename std::decay<T>::type>
+makeOptional(T&& value)
+{
+    return Optional<typename std::decay<T>::type>(std::forward<T>(value));
+}
+
 } // namespace WTF
 
 using WTF::InPlace;
 using WTF::Nullopt;
 using WTF::Optional;
+using WTF::makeOptional;
 
 #endif // Optional_h