[libcxx-commits] [libcxx] [libcxx] Implement `std::constant_wrapper` (PR #191695)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 17 11:06:13 PDT 2026


================
@@ -0,0 +1,338 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___UTILITY_CONSTANT_WRAPPER_H
+#define _LIBCPP___UTILITY_CONSTANT_WRAPPER_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+#include <__functional/invoke.h>
+#include <__type_traits/is_constructible.h>
+#include <__type_traits/remove_cvref.h>
+#include <__utility/forward.h>
+#include <__utility/integer_sequence.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 26
+
+template <class _Tp>
+struct __cw_fixed_value {
+  using __type _LIBCPP_NODEBUG = _Tp;
+  _LIBCPP_HIDE_FROM_ABI constexpr __cw_fixed_value(__type __v) noexcept : __data(__v) {}
+  _Tp __data;
+};
+
+template <__cw_fixed_value _Xp,
+#  ifdef _LIBCPP_COMPILER_GCC
+          // gcc bug:  https://gcc.gnu.org/PR117392
+          class = typename decltype(__cw_fixed_value(_Xp))::__type
+#  else
+          class = typename decltype(_Xp)::__type
+#  endif
+          >
+struct constant_wrapper;
+
+template <class _Tp>
+concept __constexpr_param = requires { typename constant_wrapper<_Tp::value>; };
+
+template <__cw_fixed_value _Xp>
+constexpr auto cw = constant_wrapper<_Xp>{};
+
+template <class _Tp, size_t _Extent>
+struct __cw_fixed_value<_Tp[_Extent]> {
----------------
ldionne wrote:

I would move this partial specialization up.

https://github.com/llvm/llvm-project/pull/191695


More information about the libcxx-commits mailing list