Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++] Implement bind_back #81055

Merged
merged 12 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions libcxx/docs/FeatureTestMacroTable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Status
---------------------------------------------------------- -----------------
``__cpp_lib_associative_heterogeneous_erasure`` *unimplemented*
---------------------------------------------------------- -----------------
``__cpp_lib_bind_back`` *unimplemented*
``__cpp_lib_bind_back`` ``202202L``
---------------------------------------------------------- -----------------
``__cpp_lib_byteswap`` ``202110L``
---------------------------------------------------------- -----------------
Expand Down Expand Up @@ -398,8 +398,6 @@ Status
---------------------------------------------------------- -----------------
``__cpp_lib_atomic_min_max`` *unimplemented*
---------------------------------------------------------- -----------------
``__cpp_lib_bind_back`` *unimplemented*
---------------------------------------------------------- -----------------
``__cpp_lib_bind_front`` ``202306L``
---------------------------------------------------------- -----------------
``__cpp_lib_bitset`` ``202306L``
Expand Down
1 change: 1 addition & 0 deletions libcxx/docs/Status/Cxx23.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Paper Status
.. [#note-P0533R9] P0533R9: ``isfinite``, ``isinf``, ``isnan`` and ``isnormal`` are implemented.
.. [#note-P1413R3] P1413R3: ``std::aligned_storage_t`` and ``std::aligned_union_t`` are marked deprecated, but
clang doesn't issue a diagnostic for deprecated using template declarations.
.. [#note-P2387R3] P2387R3: ``bind_back`` only
.. [#note-P2520R0] P2520R0: Libc++ implemented this paper as a DR in C++20 as well.
.. [#note-P2711R1] P2711R1: ``join_with_view`` hasn't been done yet since this type isn't implemented yet.
.. [#note-P2770R0] P2770R0: ``join_with_view`` hasn't been done yet since this type isn't implemented yet.
Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx23Papers.csv
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"`P1413R3 <https://wg21.link/P1413R3>`__","LWG","Deprecate ``std::aligned_storage`` and ``std::aligned_union``","February 2022","|Complete| [#note-P1413R3]_",""
"`P2255R2 <https://wg21.link/P2255R2>`__","LWG","A type trait to detect reference binding to temporary","February 2022","",""
"`P2273R3 <https://wg21.link/P2273R3>`__","LWG","Making ``std::unique_ptr`` constexpr","February 2022","|Complete|","16.0"
"`P2387R3 <https://wg21.link/P2387R3>`__","LWG","Pipe support for user-defined range adaptors","February 2022","","","|ranges|"
"`P2387R3 <https://wg21.link/P2387R3>`__","LWG","Pipe support for user-defined range adaptors","February 2022","|Partial| [#note-P2387R3]_","","|ranges|"
"`P2440R1 <https://wg21.link/P2440R1>`__","LWG","``ranges::iota``, ``ranges::shift_left`` and ``ranges::shift_right``","February 2022","","","|ranges|"
"`P2441R2 <https://wg21.link/P2441R2>`__","LWG","``views::join_with``","February 2022","|In Progress|","","|ranges|"
"`P2442R1 <https://wg21.link/P2442R1>`__","LWG","Windowing range adaptors: ``views::chunk`` and ``views::slide``","February 2022","","","|ranges|"
Expand Down
14 changes: 14 additions & 0 deletions libcxx/include/__functional/bind_back.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __bind_back(_Fn&& __f, _Args&&... __args) n
std::forward<_Fn>(__f), std::forward_as_tuple(std::forward<_Args>(__args)...));
}

# if _LIBCPP_STD_VER >= 23
template <class _Fn, class... _Args>
_LIBCPP_HIDE_FROM_ABI constexpr auto bind_back(_Fn&& __f, _Args&&... __args) {
static_assert(is_constructible_v<decay_t<_Fn>, _Fn>, "bind_back requires decay_t<F> to be constructible from F");
static_assert(is_move_constructible_v<decay_t<_Fn>>, "bind_back requires decay_t<F> to be move constructible");
static_assert((is_constructible_v<decay_t<_Args>, _Args> && ...),
"bind_back requires all decay_t<Args> to be constructible from respective Args");
static_assert((is_move_constructible_v<decay_t<_Args>> && ...),
"bind_back requires all decay_t<Args> to be move constructible");
return __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(
std::forward<_Fn>(__f), std::forward_as_tuple(std::forward<_Args>(__args)...));
}
# endif // _LIBCPP_STD_VER >= 23

#endif // _LIBCPP_STD_VER >= 20

_LIBCPP_END_NAMESPACE_STD
Expand Down
6 changes: 6 additions & 0 deletions libcxx/include/functional
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ binary_negate<Predicate> not2(const Predicate& pred);
template <class F>
constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20

// [func.bind.partial], function templates bind_front and bind_back
template<class F, class... Args>
constexpr unspecified bind_front(F&&, Args&&...); // C++20
template<class F, class... Args>
constexpr unspecified bind_back(F&&, Args&&...); // C++23

template<class T> struct is_bind_expression;
template<class T> struct is_placeholder;

Expand Down
7 changes: 2 additions & 5 deletions libcxx/include/version
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ __cpp_lib_atomic_shared_ptr 201711L <atomic>
__cpp_lib_atomic_value_initialization 201911L <atomic> <memory>
__cpp_lib_atomic_wait 201907L <atomic>
__cpp_lib_barrier 201907L <barrier>
__cpp_lib_bind_back 202306L <functional>
202202L // C++23
__cpp_lib_bind_back 202202L <functional>
__cpp_lib_bind_front 202306L <functional>
201907L // C++20
__cpp_lib_bit_cast 201806L <bit>
Expand Down Expand Up @@ -449,7 +448,7 @@ __cpp_lib_within_lifetime 202306L <type_traits>
# define __cpp_lib_adaptor_iterator_pair_constructor 202106L
# define __cpp_lib_allocate_at_least 202302L
// # define __cpp_lib_associative_heterogeneous_erasure 202110L
// # define __cpp_lib_bind_back 202202L
# define __cpp_lib_bind_back 202202L
# define __cpp_lib_byteswap 202110L
# define __cpp_lib_constexpr_bitset 202207L
# define __cpp_lib_constexpr_charconv 202207L
Expand Down Expand Up @@ -498,8 +497,6 @@ __cpp_lib_within_lifetime 202306L <type_traits>
#if _LIBCPP_STD_VER >= 26
// # define __cpp_lib_associative_heterogeneous_insertion 202306L
// # define __cpp_lib_atomic_min_max 202403L
# undef __cpp_lib_bind_back
// # define __cpp_lib_bind_back 202306L
# undef __cpp_lib_bind_front
# define __cpp_lib_bind_front 202306L
# define __cpp_lib_bitset 202306L
Expand Down
4 changes: 3 additions & 1 deletion libcxx/modules/std/functional.inc
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export namespace std {
using std::not_fn;

// [func.bind.partial], function templates bind_front and bind_back
// using std::bind_back;
using std::bind_front;
#if _LIBCPP_STD_VER >= 23
using std::bind_back;
#endif

// [func.bind], bind
using std::is_bind_expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

/* Constant Value
__cpp_lib_bind_back 202202L [C++23]
202306L [C++26]
__cpp_lib_bind_front 201907L [C++20]
202306L [C++26]
__cpp_lib_boyer_moore_searcher 201603L [C++17]
Expand Down Expand Up @@ -337,17 +336,11 @@

#elif TEST_STD_VER == 23

# if !defined(_LIBCPP_VERSION)
# ifndef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should be defined in c++23"
# endif
# if __cpp_lib_bind_back != 202202L
# error "__cpp_lib_bind_back should have the value 202202L in c++23"
# endif
# else // _LIBCPP_VERSION
# ifdef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should not be defined because it is unimplemented in libc++!"
# endif
# ifndef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should be defined in c++23"
# endif
# if __cpp_lib_bind_back != 202202L
# error "__cpp_lib_bind_back should have the value 202202L in c++23"
# endif

# ifndef __cpp_lib_bind_front
Expand Down Expand Up @@ -447,17 +440,11 @@

#elif TEST_STD_VER > 23

# if !defined(_LIBCPP_VERSION)
# ifndef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should be defined in c++26"
# endif
# if __cpp_lib_bind_back != 202306L
# error "__cpp_lib_bind_back should have the value 202306L in c++26"
# endif
# else // _LIBCPP_VERSION
# ifdef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should not be defined because it is unimplemented in libc++!"
# endif
# ifndef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should be defined in c++26"
# endif
# if __cpp_lib_bind_back != 202202L
# error "__cpp_lib_bind_back should have the value 202202L in c++26"
# endif

# ifndef __cpp_lib_bind_front
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
__cpp_lib_atomic_wait 201907L [C++20]
__cpp_lib_barrier 201907L [C++20]
__cpp_lib_bind_back 202202L [C++23]
202306L [C++26]
__cpp_lib_bind_front 201907L [C++20]
202306L [C++26]
__cpp_lib_bit_cast 201806L [C++20]
Expand Down Expand Up @@ -4605,17 +4604,11 @@
# endif
# endif

# if !defined(_LIBCPP_VERSION)
# ifndef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should be defined in c++23"
# endif
# if __cpp_lib_bind_back != 202202L
# error "__cpp_lib_bind_back should have the value 202202L in c++23"
# endif
# else // _LIBCPP_VERSION
# ifdef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should not be defined because it is unimplemented in libc++!"
# endif
# ifndef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should be defined in c++23"
# endif
# if __cpp_lib_bind_back != 202202L
# error "__cpp_lib_bind_back should have the value 202202L in c++23"
# endif

# ifndef __cpp_lib_bind_front
Expand Down Expand Up @@ -6240,17 +6233,11 @@
# endif
# endif

# if !defined(_LIBCPP_VERSION)
# ifndef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should be defined in c++26"
# endif
# if __cpp_lib_bind_back != 202306L
# error "__cpp_lib_bind_back should have the value 202306L in c++26"
# endif
# else // _LIBCPP_VERSION
# ifdef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should not be defined because it is unimplemented in libc++!"
# endif
# ifndef __cpp_lib_bind_back
# error "__cpp_lib_bind_back should be defined in c++26"
# endif
# if __cpp_lib_bind_back != 202202L
# error "__cpp_lib_bind_back should have the value 202202L in c++26"
# endif

# ifndef __cpp_lib_bind_front
Expand Down
Loading
Loading