[llvm] r175696 - Provide a "None" value for convenience when using Optional<T>()
David Blaikie
dblaikie at gmail.com
Wed Feb 20 16:27:28 PST 2013
Author: dblaikie
Date: Wed Feb 20 18:27:28 2013
New Revision: 175696
URL: http://llvm.org/viewvc/llvm-project?rev=175696&view=rev
Log:
Provide a "None" value for convenience when using Optional<T>()
This implementation of NoneType/None does have some holes but I haven't
found one that doesn't - open to improvement.
Added:
llvm/trunk/include/llvm/ADT/None.h
Modified:
llvm/trunk/include/llvm/ADT/Optional.h
llvm/trunk/lib/Support/LockFileManager.cpp
Added: llvm/trunk/include/llvm/ADT/None.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/None.h?rev=175696&view=auto
==============================================================================
--- llvm/trunk/include/llvm/ADT/None.h (added)
+++ llvm/trunk/include/llvm/ADT/None.h Wed Feb 20 18:27:28 2013
@@ -0,0 +1,27 @@
+//===-- None.h - Simple null value for implicit construction ------*- C++ -*-=//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides None, an enumerant for use in implicit constructors
+// of various (usually templated) types to make such construction more
+// terse.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ADT_NONE_H
+#define LLVM_ADT_NONE_H
+
+namespace llvm {
+/// \brief A simple null object to allow implicit construction of Optional<T>
+/// and similar types without having to spell out the specialization's name.
+enum NoneType {
+ None
+};
+}
+
+#endif
Modified: llvm/trunk/include/llvm/ADT/Optional.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Optional.h?rev=175696&r1=175695&r2=175696&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/Optional.h (original)
+++ llvm/trunk/include/llvm/ADT/Optional.h Wed Feb 20 18:27:28 2013
@@ -16,6 +16,7 @@
#ifndef LLVM_ADT_OPTIONAL_H
#define LLVM_ADT_OPTIONAL_H
+#include "llvm/ADT/None.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/AlignOf.h"
#include <cassert>
@@ -31,6 +32,7 @@ class Optional {
AlignedCharArrayUnion<T> storage;
bool hasVal;
public:
+ Optional(NoneType) : hasVal(false) {}
explicit Optional() : hasVal(false) {}
Optional(const T &y) : hasVal(true) {
new (storage.buffer) T(y);
Modified: llvm/trunk/lib/Support/LockFileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/LockFileManager.cpp?rev=175696&r1=175695&r2=175696&view=diff
==============================================================================
--- llvm/trunk/lib/Support/LockFileManager.cpp (original)
+++ llvm/trunk/lib/Support/LockFileManager.cpp Wed Feb 20 18:27:28 2013
@@ -31,7 +31,7 @@ LockFileManager::readLockFile(StringRef
// to read, so we just return.
bool Exists = false;
if (sys::fs::exists(LockFileName, Exists) || !Exists)
- return Optional<std::pair<std::string, int> >();
+ return None;
// Read the owning host and PID out of the lock file. If it appears that the
// owning process is dead, the lock file is invalid.
@@ -45,7 +45,7 @@ LockFileManager::readLockFile(StringRef
// Delete the lock file. It's invalid anyway.
bool Existed;
sys::fs::remove(LockFileName, Existed);
- return Optional<std::pair<std::string, int> >();
+ return None;
}
bool LockFileManager::processStillExecuting(StringRef Hostname, int PID) {
More information about the llvm-commits
mailing list