llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (Sirraide)

<details>
<summary>Changes</summary>

This adds two `value_or` overloads to `UnsignedOrNone`. I’ve had a use for 
these in something I’m currently working on and thought it might make sense to 
add them separately. The overload that takes an `UnsignedOrNone` might seem a 
bit strange at first, but I think it makes sense given how specific this class 
already is.

---
Full diff: https://github.com/llvm/llvm-project/pull/143516.diff


1 Files Affected:

- (modified) clang/include/clang/Basic/UnsignedOrNone.h (+8) 


``````````diff
diff --git a/clang/include/clang/Basic/UnsignedOrNone.h 
b/clang/include/clang/Basic/UnsignedOrNone.h
index 659fd8c6487d2..5081e3c2a9e32 100644
--- a/clang/include/clang/Basic/UnsignedOrNone.h
+++ b/clang/include/clang/Basic/UnsignedOrNone.h
@@ -29,6 +29,14 @@ struct UnsignedOrNone {
   }
   constexpr unsigned toInternalRepresentation() const { return Rep; }
 
+  constexpr unsigned value_or(unsigned val) const {
+    return operator bool() ? **this : val;
+  }
+
+  constexpr UnsignedOrNone value_or(UnsignedOrNone val) const {
+    return operator bool() ? *this : val;
+  }
+
   explicit constexpr operator bool() const { return Rep != 0; }
   unsigned operator*() const {
     assert(operator bool());

``````````

</details>


https://github.com/llvm/llvm-project/pull/143516
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to