[PATCH] D138468: [ADT] Define None as std::nullopt (NFC)

Kazu Hirata via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 21 19:20:56 PST 2022


kazu created this revision.
Herald added a project: All.
kazu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch defines NoneType and None as std::nullopt_t and
std::nullopt, respectively.

This patch effectively makes None and std::nullopt interchangeable, so
we can gradually replace None with std::nullopt all while we continue
to use llvm::Optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138468

Files:
  llvm/include/llvm/ADT/None.h


Index: llvm/include/llvm/ADT/None.h
===================================================================
--- llvm/include/llvm/ADT/None.h
+++ llvm/include/llvm/ADT/None.h
@@ -16,11 +16,13 @@
 #ifndef LLVM_ADT_NONE_H
 #define LLVM_ADT_NONE_H
 
+#include <optional>
+
 namespace llvm {
 /// A simple null object to allow implicit construction of Optional<T>
 /// and similar types without having to spell out the specialization's name.
-enum class NoneType { None };
-const NoneType None = NoneType::None;
+using NoneType = std::nullopt_t;
+inline constexpr std::nullopt_t None = std::nullopt;
 }
 
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138468.477046.patch
Type: text/x-patch
Size: 604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221122/7599fad2/attachment.bin>


More information about the llvm-commits mailing list