[libcxx-commits] [libcxx] [libc++] Implement `bind_back` (PR #81055)
Jakub Mazurkiewicz via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 14 06:27:46 PDT 2024
================
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <functional>
+
+// template<class F, class... Args>
+// constexpr unspecified bind_back(F&& f, Args&&... args);
+
+#include <functional>
+
+#include "types.h"
+
+void test() {
+ { // Various failures
+ auto p = std::bind_back(pass, 1);
+ static_assert(p() == 1); // expected-error {{static assertion expression is not an integral constant expression}}
+
+ auto d = std::bind_back(do_nothing, 2); // expected-error {{no matching function for call to 'bind_back'}}
----------------
JMazurkiewicz wrote:
This test checks if there exists some (incorrect) overload of `std::bind_back`. I'm going to add comment with clarification.
> You can't pass an overloaded function as an argument.
You can do something like [this](https://godbolt.org/z/xzcEcGcr5):
```c++
namespace std {
template<class F, class... Args>
auto bind_back(F&&, Args&&...);
void bind_back(int (*)(int));
}
template<class T>
T do_nothing(T t) {
return t;
}
void use() {
std::bind_back(do_nothing);
}
```
BTW, I've copied this test from `bind_front.verify.cpp`:
https://github.com/llvm/llvm-project/blob/1c3b15e9f5bc671e40bcf5d3475f5425466754ce/libcxx/test/std/utilities/function.objects/func.bind_front/bind_front.verify.cpp#L42
https://github.com/llvm/llvm-project/pull/81055
More information about the libcxx-commits
mailing list