+template<class T,
+ class Opt = Optional<typename std::decay<T>::type>>
+Opt make_optional(T&& v) {
+ return Opt(std::forward<T>(v));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Comparisons.
+
+template<class V>
+bool operator==(const Optional<V>& a, const V& b) {
+ return a.hasValue() && a.value() == b;
+}
+
+template<class V>
+bool operator!=(const Optional<V>& a, const V& b) {
+ return !(a == b);
+}
+
+template<class V>
+bool operator==(const V& a, const Optional<V>& b) {
+ return b.hasValue() && b.value() == a;
+}
+
+template<class V>
+bool operator!=(const V& a, const Optional<V>& b) {
+ return !(a == b);
+}
+
+template<class V>
+bool operator==(const Optional<V>& a, const Optional<V>& b) {
+ if (a.hasValue() != b.hasValue()) { return false; }
+ if (a.hasValue()) { return a.value() == b.value(); }
+ return true;
+}
+
+template<class V>
+bool operator!=(const Optional<V>& a, const Optional<V>& b) {
+ return !(a == b);
+}
+
+template<class V>
+bool operator< (const Optional<V>& a, const Optional<V>& b) {
+ if (a.hasValue() != b.hasValue()) { return a.hasValue() < b.hasValue(); }
+ if (a.hasValue()) { return a.value() < b.value(); }
+ return false;
+}
+
+template<class V>
+bool operator> (const Optional<V>& a, const Optional<V>& b) {
+ return b < a;
+}
+
+template<class V>
+bool operator<=(const Optional<V>& a, const Optional<V>& b) {
+ return !(b < a);
+}
+
+template<class V>
+bool operator>=(const Optional<V>& a, const Optional<V>& b) {
+ return !(a < b);
+}
+
+// Suppress comparability of Optional<T> with T, despite implicit conversion.
+template<class V> bool operator< (const Optional<V>&, const V& other) = delete;
+template<class V> bool operator<=(const Optional<V>&, const V& other) = delete;
+template<class V> bool operator>=(const Optional<V>&, const V& other) = delete;
+template<class V> bool operator> (const Optional<V>&, const V& other) = delete;
+template<class V> bool operator< (const V& other, const Optional<V>&) = delete;
+template<class V> bool operator<=(const V& other, const Optional<V>&) = delete;
+template<class V> bool operator>=(const V& other, const Optional<V>&) = delete;
+template<class V> bool operator> (const V& other, const Optional<V>&) = delete;
+
+///////////////////////////////////////////////////////////////////////////////
+
+} // namespace folly