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

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 17 09:17:51 PDT 2026


================
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// constant_wrapper
+
+// The class template constant_wrapper aids in metaprogramming by ensuring that the
+// evaluation of expressions comprised entirely of constant_wrapper are core constant
+// expressions ([expr.const]), regardless of the context in which they appear. In particular,
+// this enables use of constant_wrapper values that are passed as arguments to constexpr
+// functions to be used in constant expressions.
+
+#include <cassert>
+#include <concepts>
+#include <type_traits>
+#include <utility>
+#include <iostream>
+
+#include "helpers.h"
+#include "test_macros.h"
+
+constexpr auto initial_phase(auto quantity_1, auto quantity_2) { return quantity_1 + quantity_2; }
+
+constexpr auto middle_phase(auto tbd) { return tbd; }
+
+void final_phase(auto gathered, auto available) {
+  if constexpr (gathered == available)
+    std::cout << "Profit!\n";
----------------
frederick-vs-ja wrote:

Now CI is failing for using `cout` for generic-no-localization build. I don't think we really need to use `cout` here. Could we just use `static_assert`?

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


More information about the libcxx-commits mailing list