Skip to content

Commit

Permalink
cut guards for std::optional in folly::Optional
Browse files Browse the repository at this point in the history
Summary: We may always assume C++17, and therefore `<optional>` and `std::optional`, to be available.

Differential Revision: D55202536

fbshipit-source-id: 3b9f98583b13d9e86ff05f608ca1abd39161fe70
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Mar 30, 2024
1 parent cbdc201 commit 8203c08
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
10 changes: 3 additions & 7 deletions folly/Optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@
#include <cstddef>
#include <functional>
#include <new>
#include <optional>
#include <stdexcept>
#include <type_traits>
#include <utility>
#if __cplusplus >= 201703L && __has_include(<optional>)
#define FOLLY_HAS_STD_OPTIONAL
#include <optional>
#endif

#include <folly/Portability.h>
#include <folly/Traits.h>
Expand Down Expand Up @@ -182,8 +179,8 @@ class Optional {
p.promise_->value_ = this;
}

// Conversions to ease migration to std::optional
#ifdef FOLLY_HAS_STD_OPTIONAL
// Conversions to ease migration to std::optional

/// Allow construction of Optional from std::optional.
template <
typename U,
Expand Down Expand Up @@ -219,7 +216,6 @@ class Optional {
return storage_.hasValue ? std::optional<Value>(storage_.value)
: std::nullopt;
}
#endif

/// Set the Optional
/// @methodset Modifiers
Expand Down
2 changes: 0 additions & 2 deletions folly/test/OptionalTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,6 @@ TEST(Optional, NoneMatchesNullopt) {
EXPECT_FALSE(op.has_value());
}

#if __cplusplus >= 201703L && __has_include(<optional>)
TEST(Optional, StdOptionalConversions) {
folly::Optional<int> f = 42;
std::optional<int> s = static_cast<std::optional<int>>(f);
Expand All @@ -858,7 +857,6 @@ TEST(Optional, StdOptionalConversions) {
EXPECT_EQ(**fp, 42);
EXPECT_FALSE(sp);
}
#endif

TEST(Optional, MovedFromOptionalIsEmpty) {
// moved-from folly::Optional is empty, unlike std::optional!
Expand Down

0 comments on commit 8203c08

Please sign in to comment.