[llvm] [ADT] Add and use (for AArch64) `ValueWithSentinel<T, Sentinel>` (PR #158120)
Jakub Kuderski via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 10:36:40 PDT 2025
================
@@ -0,0 +1,75 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file defines the ValueWithSentinel class, which is a type akin to a
+/// std::optional, but uses a sentinel rather than an additional "valid" flag.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ADT_VALUEWITHSENTINEL_H
+#define LLVM_ADT_VALUEWITHSENTINEL_H
+
+#include <cassert>
+#include <limits>
+#include <utility>
+
+namespace llvm {
+
+template <typename T, T Sentinel> class ValueWithSentinel {
+public:
+ ValueWithSentinel() = default;
+
+ ValueWithSentinel(T Value) : Value(std::move(Value)) {
+ assert(Value != Sentinel && "Value is sentinel (use default constructor)");
+ };
+
+ ValueWithSentinel &operator=(T const &NewValue) {
----------------
kuhar wrote:
Could we switch the style of const references to `const T &` throughout the class? This seems much more common in ADT code.
https://github.com/llvm/llvm-project/pull/158120
More information about the llvm-commits
mailing list