Skip to content

Commit 3b0b9e2

Browse files
Pawel Poskrobkofacebook-github-bot
authored andcommitted
thrift: add to_optional to union_field_ref
Summary: Tried to use it for union similarly to optional fields in D79896911 and realized it doesn't exist. I think it would make sense? To just match `value_or` -- it either has value or doesn't, so returning optional would make sense, thoughts? Reviewed By: iahs Differential Revision: D79907872 fbshipit-source-id: fa6a8161ec5aa8cdeb4bbdb1a427e48371f9ac24
1 parent 044723a commit 3b0b9e2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

third-party/thrift/src/thrift/lib/cpp2/FieldRef.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,12 @@ class union_field_ref {
19121912
return *this;
19131913
}
19141914

1915+
FOLLY_ERASE std::optional<std::remove_const_t<value_type>> to_optional()
1916+
const {
1917+
using type = std::optional<std::remove_const_t<value_type>>;
1918+
return has_value() ? type(get_value()) : type();
1919+
}
1920+
19151921
FOLLY_ERASE bool has_value() const { return type_ == field_type_; }
19161922

19171923
FOLLY_ERASE explicit operator bool() const { return has_value(); }

0 commit comments

Comments
 (0)