!std::is_abstract<Value>::value,
"Optional may not be used with abstract types");
!std::is_abstract<Value>::value,
"Optional may not be used with abstract types");
+ FOLLY_CPP14_CONSTEXPR Optional() noexcept {}
Optional(const Optional& src) noexcept(
std::is_nothrow_copy_constructible<Value>::value) {
Optional(const Optional& src) noexcept(
std::is_nothrow_copy_constructible<Value>::value) {
- /* implicit */ Optional(const None&) noexcept {}
+ FOLLY_CPP14_CONSTEXPR /* implicit */ Optional(const None&) noexcept {}
- /* implicit */ Optional(Value&& newValue) noexcept(
+ FOLLY_CPP14_CONSTEXPR /* implicit */ Optional(Value&& newValue) noexcept(
std::is_nothrow_move_constructible<Value>::value) {
storage_.construct(std::move(newValue));
}
std::is_nothrow_move_constructible<Value>::value) {
storage_.construct(std::move(newValue));
}
- /* implicit */ Optional(const Value& newValue) noexcept(
+ FOLLY_CPP14_CONSTEXPR /* implicit */ Optional(const Value& newValue) noexcept(
std::is_nothrow_copy_constructible<Value>::value) {
storage_.construct(newValue);
}
template <typename... Args>
std::is_nothrow_copy_constructible<Value>::value) {
storage_.construct(newValue);
}
template <typename... Args>
- explicit Optional(in_place_t, Args&&... args) noexcept(
+ FOLLY_CPP14_CONSTEXPR explicit Optional(in_place_t, Args&&... args) noexcept(
std::is_nothrow_constructible<Value, Args...>::value) {
storage_.construct(std::forward<Args>(args)...);
}
std::is_nothrow_constructible<Value, Args...>::value) {
storage_.construct(std::forward<Args>(args)...);
}
- const Value& value() const & {
+ FOLLY_CPP14_CONSTEXPR const Value& value() const & {
require_value();
return *storage_.value_pointer();
}
require_value();
return *storage_.value_pointer();
}
+ FOLLY_CPP14_CONSTEXPR Value& value() & {
require_value();
return *storage_.value_pointer();
}
require_value();
return *storage_.value_pointer();
}
+ FOLLY_CPP14_CONSTEXPR Value&& value() && {
require_value();
return std::move(*storage_.value_pointer());
}
require_value();
return std::move(*storage_.value_pointer());
}
- const Value&& value() const && {
+ FOLLY_CPP14_CONSTEXPR const Value&& value() const && {
require_value();
return std::move(*storage_.value_pointer());
}
require_value();
return std::move(*storage_.value_pointer());
}
}
Value* get_pointer() && = delete;
}
Value* get_pointer() && = delete;
- bool hasValue() const noexcept {
+ FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept {
return storage_.hasValue();
}
return storage_.hasValue();
}
- explicit operator bool() const noexcept {
+ FOLLY_CPP14_CONSTEXPR explicit operator bool() const noexcept {
- const Value& operator*() const & {
+ FOLLY_CPP14_CONSTEXPR const Value& operator*() const & {
+ FOLLY_CPP14_CONSTEXPR Value& operator*() & {
- const Value&& operator*() const && {
+ FOLLY_CPP14_CONSTEXPR const Value&& operator*() const && {
return std::move(value());
}
return std::move(value());
}
- Value&& operator*() && {
+ FOLLY_CPP14_CONSTEXPR Value&& operator*() && {
return std::move(value());
}
return std::move(value());
}
- const Value* operator->() const {
+ FOLLY_CPP14_CONSTEXPR const Value* operator->() const {
+ FOLLY_CPP14_CONSTEXPR Value* operator->() {
return &value();
}
// Return a copy of the value if set, or a given default if not.
template <class U>
return &value();
}
// Return a copy of the value if set, or a given default if not.
template <class U>
- Value value_or(U&& dflt) const & {
+ FOLLY_CPP14_CONSTEXPR Value value_or(U&& dflt) const & {
if (storage_.hasValue()) {
return *storage_.value_pointer();
}
if (storage_.hasValue()) {
return *storage_.value_pointer();
}
- Value value_or(U&& dflt) && {
+ FOLLY_CPP14_CONSTEXPR Value value_or(U&& dflt) && {
if (storage_.hasValue()) {
return std::move(*storage_.value_pointer());
}
if (storage_.hasValue()) {
return std::move(*storage_.value_pointer());
}
}
template <class T, class Opt = Optional<typename std::decay<T>::type>>
}
template <class T, class Opt = Optional<typename std::decay<T>::type>>
-Opt make_optional(T&& v) {
+constexpr Opt make_optional(T&& v) {
return Opt(std::forward<T>(v));
}
return Opt(std::forward<T>(v));
}
// Comparisons.
template <class U, class V>
// Comparisons.
template <class U, class V>
-bool operator==(const Optional<U>& a, const V& b) {
+constexpr bool operator==(const Optional<U>& a, const V& b) {
return a.hasValue() && a.value() == b;
}
template <class U, class V>
return a.hasValue() && a.value() == b;
}
template <class U, class V>
-bool operator!=(const Optional<U>& a, const V& b) {
+constexpr bool operator!=(const Optional<U>& a, const V& b) {
return !(a == b);
}
template <class U, class V>
return !(a == b);
}
template <class U, class V>
-bool operator==(const U& a, const Optional<V>& b) {
+constexpr bool operator==(const U& a, const Optional<V>& b) {
return b.hasValue() && b.value() == a;
}
template <class U, class V>
return b.hasValue() && b.value() == a;
}
template <class U, class V>
-bool operator!=(const U& a, const Optional<V>& b) {
+constexpr bool operator!=(const U& a, const Optional<V>& b) {
return !(a == b);
}
template <class U, class V>
return !(a == b);
}
template <class U, class V>
-bool operator==(const Optional<U>& a, const Optional<V>& b) {
+FOLLY_CPP14_CONSTEXPR bool operator==(
+ const Optional<U>& a,
+ const Optional<V>& b) {
if (a.hasValue() != b.hasValue()) {
return false;
}
if (a.hasValue() != b.hasValue()) {
return false;
}
}
template <class U, class V>
}
template <class U, class V>
-bool operator!=(const Optional<U>& a, const Optional<V>& b) {
+constexpr bool operator!=(const Optional<U>& a, const Optional<V>& b) {
return !(a == b);
}
template <class U, class V>
return !(a == b);
}
template <class U, class V>
-bool operator<(const Optional<U>& a, const Optional<V>& b) {
+FOLLY_CPP14_CONSTEXPR bool operator<(
+ const Optional<U>& a,
+ const Optional<V>& b) {
if (a.hasValue() != b.hasValue()) {
return a.hasValue() < b.hasValue();
}
if (a.hasValue() != b.hasValue()) {
return a.hasValue() < b.hasValue();
}
}
template <class U, class V>
}
template <class U, class V>
-bool operator>(const Optional<U>& a, const Optional<V>& b) {
+constexpr bool operator>(const Optional<U>& a, const Optional<V>& b) {
return b < a;
}
template <class U, class V>
return b < a;
}
template <class U, class V>
-bool operator<=(const Optional<U>& a, const Optional<V>& b) {
+constexpr bool operator<=(const Optional<U>& a, const Optional<V>& b) {
return !(b < a);
}
template <class U, class V>
return !(b < a);
}
template <class U, class V>
-bool operator>=(const Optional<U>& a, const Optional<V>& b) {
+constexpr bool operator>=(const Optional<U>& a, const Optional<V>& b) {
// Comparisons with none
template <class V>
// Comparisons with none
template <class V>
-bool operator==(const Optional<V>& a, None) noexcept {
+constexpr bool operator==(const Optional<V>& a, None) noexcept {
return !a.hasValue();
}
template <class V>
return !a.hasValue();
}
template <class V>
-bool operator==(None, const Optional<V>& a) noexcept {
+constexpr bool operator==(None, const Optional<V>& a) noexcept {
return !a.hasValue();
}
template <class V>
return !a.hasValue();
}
template <class V>
-bool operator<(const Optional<V>&, None) noexcept {
+constexpr bool operator<(const Optional<V>&, None) noexcept {
return false;
}
template <class V>
return false;
}
template <class V>
-bool operator<(None, const Optional<V>& a) noexcept {
+constexpr bool operator<(None, const Optional<V>& a) noexcept {
return a.hasValue();
}
template <class V>
return a.hasValue();
}
template <class V>
-bool operator>(const Optional<V>& a, None) noexcept {
+constexpr bool operator>(const Optional<V>& a, None) noexcept {
return a.hasValue();
}
template <class V>
return a.hasValue();
}
template <class V>
-bool operator>(None, const Optional<V>&) noexcept {
+constexpr bool operator>(None, const Optional<V>&) noexcept {
return false;
}
template <class V>
return false;
}
template <class V>
-bool operator<=(None, const Optional<V>&) noexcept {
+constexpr bool operator<=(None, const Optional<V>&) noexcept {
return true;
}
template <class V>
return true;
}
template <class V>
-bool operator<=(const Optional<V>& a, None) noexcept {
+constexpr bool operator<=(const Optional<V>& a, None) noexcept {
return !a.hasValue();
}
template <class V>
return !a.hasValue();
}
template <class V>
-bool operator>=(const Optional<V>&, None) noexcept {
+constexpr bool operator>=(const Optional<V>&, None) noexcept {
return true;
}
template <class V>
return true;
}
template <class V>
-bool operator>=(None, const Optional<V>& a) noexcept {
+constexpr bool operator>=(None, const Optional<V>& a) noexcept {