Skip to content

Commit 09c1f8f

Browse files
committed
[multi_llvm] Provide implicit conversion from Optional to std::optional
1 parent e94d628 commit 09c1f8f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

modules/compiler/multi_llvm/include/multi_llvm/optional_helper.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
#include <llvm/ADT/Optional.h>
2525
#endif
2626

27-
#if (LLVM_VERSION_MAJOR >= 16)
2827
#include <optional>
29-
#endif
3028

3129
namespace multi_llvm {
3230

@@ -64,6 +62,13 @@ class Optional : public llvm::Optional<T> {
6462
inline constexpr bool has_value() const {
6563
return llvm::Optional<T>::hasValue();
6664
}
65+
66+
// Provide implicit conversions to the future proof std::optional.
67+
inline constexpr operator std::optional<T>() const {
68+
return llvm::Optional<T>::hasValue()
69+
? std::optional<T>(llvm::Optional<T>::getValue())
70+
: std::nullopt;
71+
}
6772
};
6873

6974
#endif

0 commit comments

Comments
 (0)