https://github.com/Sirraide created https://github.com/llvm/llvm-project/pull/143516
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. >From 4680bcde0d6abda40dac303275e4ac42f1573109 Mon Sep 17 00:00:00 2001 From: Sirraide <aeternalm...@gmail.com> Date: Sun, 8 Jun 2025 17:21:13 +0200 Subject: [PATCH] Add a 'value_or' helper to 'UnsignedOrNone' --- clang/include/clang/Basic/UnsignedOrNone.h | 8 ++++++++ 1 file changed, 8 insertions(+) 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()); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits