[libcxx-commits] [libcxx] [libc++][optional][NFC] Use variable templates instead of class templates (PR #212443)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 28 02:49:50 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Hristo Hristov (H-G-Hristov)
<details>
<summary>Changes</summary>
Modernizing similar to: https://github.com/llvm/llvm-project/pull/199481
---
Full diff: https://github.com/llvm/llvm-project/pull/212443.diff
1 Files Affected:
- (modified) libcxx/include/optional (+12-11)
``````````diff
diff --git a/libcxx/include/optional b/libcxx/include/optional
index 2499479348892..ffa071c2304ba 100644
--- a/libcxx/include/optional
+++ b/libcxx/include/optional
@@ -757,9 +757,10 @@ concept __is_derived_from_optional = requires(const _Tp& __t) { []<class _Up>(co
# endif // _LIBCPP_STD_VER >= 20
template <class _Tp>
-struct __is_std_optional : false_type {};
+inline constexpr bool __is_std_optional_v = false;
+
template <class _Tp>
-struct __is_std_optional<optional<_Tp>> : true_type {};
+inline constexpr bool __is_std_optional_v<optional<_Tp>> = true;
# if _LIBCPP_STD_VER < 26
template <class _Tp>
@@ -903,7 +904,7 @@ private:
template <class _Up>
using _CheckOptionalArgsCtor _LIBCPP_NODEBUG =
_If< _IsNotSame<__remove_cvref_t<_Up>, in_place_t>::value && _IsNotSame<__remove_cvref_t<_Up>, optional>::value &&
- (!is_same_v<remove_cv_t<_Tp>, bool> || !__is_std_optional<__remove_cvref_t<_Up>>::value),
+ (!is_same_v<remove_cv_t<_Tp>, bool> || !__is_std_optional_v<__remove_cvref_t<_Up>>),
_CheckOptionalArgsConstructor,
__check_tuple_constructor_fail >;
template <class _QualUp>
@@ -1093,8 +1094,8 @@ public:
template <class _Func>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) & {
using _Up = invoke_result_t<_Func, _Tp&>;
- static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
- "Result of f(value()) must be a specialization of std::optional");
+ static_assert(
+ __is_std_optional_v<remove_cvref_t<_Up>>, "Result of f(value()) must be a specialization of std::optional");
if (*this)
return std::invoke(std::forward<_Func>(__f), value());
return remove_cvref_t<_Up>();
@@ -1103,8 +1104,8 @@ public:
template <class _Func>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const& {
using _Up = invoke_result_t<_Func, const _Tp&>;
- static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
- "Result of f(value()) must be a specialization of std::optional");
+ static_assert(
+ __is_std_optional_v<remove_cvref_t<_Up>>, "Result of f(value()) must be a specialization of std::optional");
if (*this)
return std::invoke(std::forward<_Func>(__f), value());
return remove_cvref_t<_Up>();
@@ -1113,7 +1114,7 @@ public:
template <class _Func>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) && {
using _Up = invoke_result_t<_Func, _Tp&&>;
- static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
+ static_assert(__is_std_optional_v<remove_cvref_t<_Up>>,
"Result of f(std::move(value())) must be a specialization of std::optional");
if (*this)
return std::invoke(std::forward<_Func>(__f), std::move(value()));
@@ -1123,7 +1124,7 @@ public:
template <class _Func>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const&& {
using _Up = invoke_result_t<_Func, const _Tp&&>;
- static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
+ static_assert(__is_std_optional_v<remove_cvref_t<_Up>>,
"Result of f(std::move(value())) must be a specialization of std::optional");
if (*this)
return std::invoke(std::forward<_Func>(__f), std::move(value()));
@@ -1338,8 +1339,8 @@ public:
template <class _Func>
[[nodiscard]] constexpr auto and_then(_Func&& __f) const {
using _Up = invoke_result_t<_Func, _Tp&>;
- static_assert(__is_std_optional<remove_cvref_t<_Up>>::value,
- "Result of f(value()) must be a specialization of std::optional");
+ static_assert(
+ __is_std_optional_v<remove_cvref_t<_Up>>, "Result of f(value()) must be a specialization of std::optional");
if (*this)
return std::invoke(std::forward<_Func>(__f), value());
return remove_cvref_t<_Up>();
``````````
</details>
https://github.com/llvm/llvm-project/pull/212443
More information about the libcxx-commits
mailing list