Skip to content

Commit

Permalink
[libc++] Complete the implementation of N4190
Browse files Browse the repository at this point in the history
Fixes #37402

Reviewed By: ldionne

Spies: EricWF, avogelsgesang, libcxx-commits, arphaman

Differential Revision: https://reviews.llvm.org/D124346
  • Loading branch information
philnik777 committed Jun 22, 2022
1 parent c475e31 commit 681cde7
Show file tree
Hide file tree
Showing 53 changed files with 358 additions and 540 deletions.
10 changes: 8 additions & 2 deletions libcxx/docs/ReleaseNotes.rst
Expand Up @@ -43,8 +43,8 @@ Implemented Papers
- P0674R1 (Support arrays in ``make_shared`` and ``allocate_shared``)
- P0980R1 (Making ``std::string`` constexpr)
- P2216R3 (std::format improvements)

- Implemented P0174R2 (Deprecating Vestigial Library Parts in C++17)
- P0174R2 (Deprecating Vestigial Library Parts in C++17)
- N4190 (Removing auto_ptr, random_shuffle(), And Old <functional> Stuff)

- Marked the following papers as "Complete" (note that some of those might have
been implemented in a previous release but not marked as such):
Expand Down Expand Up @@ -152,6 +152,12 @@ API Changes
or upgrade to C++11 or later. It is possible to re-enable ``std::function`` in C++03 by defining
``_LIBCPP_ENABLE_CXX03_FUNCTION``. This option it will be removed in LLVM 16.

- ``unary_function`` and ``binary_function`` are no longer available in C++17 and C++20.
They can be re-enabled by defining ``_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION``.
They are also marked as ``[[deprecated]]`` in C++11 and later. To disable deprecation warnings
you have to define ``_LIBCPP_DISABLE_DEPRECATION_WARNINGS``. Note that this disables
all deprecation warnings.

ABI Changes
-----------

Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx17Papers.csv
Expand Up @@ -2,7 +2,7 @@
"`N3911 <https://wg21.link/n3911>`__","LWG","TransformationTrait Alias ``void_t``\ .","Urbana","|Complete|","3.6"
"`N4089 <https://wg21.link/n4089>`__","LWG","Safe conversions in ``unique_ptr<T[]>``\ .","Urbana","|In Progress|","3.9"
"`N4169 <https://wg21.link/n4169>`__","LWG","A proposal to add invoke function template","Urbana","|Complete|","3.7"
"`N4190 <https://wg21.link/n4190>`__","LWG","Removing auto_ptr, random_shuffle(), And Old <functional> Stuff.","Urbana","|In Progress|",""
"`N4190 <https://wg21.link/n4190>`__","LWG","Removing auto_ptr, random_shuffle(), And Old <functional> Stuff.","Urbana","|Complete|","15.0"
"`N4258 <https://wg21.link/n4258>`__","LWG","Cleaning-up noexcept in the Library.","Urbana","|In Progress|","3.7"
"`N4259 <https://wg21.link/n4259>`__","CWG","Wording for std::uncaught_exceptions","Urbana","|Complete|","3.7"
"`N4277 <https://wg21.link/n4277>`__","LWG","TriviallyCopyable ``reference_wrapper``\ .","Urbana","|Complete|","3.2"
Expand Down
4 changes: 1 addition & 3 deletions libcxx/include/__config
Expand Up @@ -83,9 +83,6 @@
# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
// In C++20 and later, don't derive std::plus from std::binary_function,
// nor std::negate from std::unary_function.
# define _LIBCPP_ABI_NO_BINDER_BASES
// Give reverse_iterator<T> one data member of type T, not two.
// Also, in C++17 and later, don't derive iterator types from std::iterator.
# define _LIBCPP_ABI_NO_ITERATOR_BASES
Expand Down Expand Up @@ -1116,6 +1113,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
# define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES

# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
Expand Down
25 changes: 24 additions & 1 deletion libcxx/include/__functional/binary_function.h
Expand Up @@ -18,14 +18,37 @@

_LIBCPP_BEGIN_NAMESPACE_STD

#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)

template <class _Arg1, class _Arg2, class _Result>
struct _LIBCPP_TEMPLATE_VIS binary_function
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binary_function
{
typedef _Arg1 first_argument_type;
typedef _Arg2 second_argument_type;
typedef _Result result_type;
};

#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)

template <class _Arg1, class _Arg2, class _Result> struct __binary_function_keep_layout_base {
#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
using first_argument_type _LIBCPP_DEPRECATED_IN_CXX17 = _Arg1;
using second_argument_type _LIBCPP_DEPRECATED_IN_CXX17 = _Arg2;
using result_type _LIBCPP_DEPRECATED_IN_CXX17 = _Result;
#endif
};

#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
_LIBCPP_DIAGNOSTIC_PUSH
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
template <class _Arg1, class _Arg2, class _Result>
using __binary_function = binary_function<_Arg1, _Arg2, _Result>;
_LIBCPP_DIAGNOSTIC_POP
#else
template <class _Arg1, class _Arg2, class _Result>
using __binary_function = __binary_function_keep_layout_base<_Arg1, _Arg2, _Result>;
#endif

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FUNCTIONAL_BINARY_FUNCTION_H
6 changes: 3 additions & 3 deletions libcxx/include/__functional/binary_negate.h
Expand Up @@ -23,9 +23,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD

template <class _Predicate>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
: public binary_function<typename _Predicate::first_argument_type,
typename _Predicate::second_argument_type,
bool>
: public __binary_function<typename _Predicate::first_argument_type,
typename _Predicate::second_argument_type,
bool>
{
_Predicate __pred_;
public:
Expand Down
5 changes: 1 addition & 4 deletions libcxx/include/__functional/bind.h
Expand Up @@ -264,10 +264,7 @@ __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
}

template<class _Fp, class ..._BoundArgs>
class __bind
#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
: public __weak_result_type<typename decay<_Fp>::type>
#endif
class __bind : public __weak_result_type<typename decay<_Fp>::type>
{
protected:
typedef typename decay<_Fp>::type _Fd;
Expand Down
3 changes: 1 addition & 2 deletions libcxx/include/__functional/binder1st.h
Expand Up @@ -23,8 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD

template <class __Operation>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
: public unary_function<typename __Operation::second_argument_type,
typename __Operation::result_type>
: public __unary_function<typename __Operation::second_argument_type, typename __Operation::result_type>
{
protected:
__Operation op;
Expand Down
3 changes: 1 addition & 2 deletions libcxx/include/__functional/binder2nd.h
Expand Up @@ -23,8 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD

template <class __Operation>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
: public unary_function<typename __Operation::first_argument_type,
typename __Operation::result_type>
: public __unary_function<typename __Operation::first_argument_type, typename __Operation::result_type>
{
protected:
__Operation op;
Expand Down
6 changes: 2 additions & 4 deletions libcxx/include/__functional/function.h
Expand Up @@ -85,7 +85,7 @@ struct __maybe_derive_from_unary_function

template<class _Rp, class _A1>
struct __maybe_derive_from_unary_function<_Rp(_A1)>
: public unary_function<_A1, _Rp>
: public __unary_function<_A1, _Rp>
{
};

Expand All @@ -96,7 +96,7 @@ struct __maybe_derive_from_binary_function

template<class _Rp, class _A1, class _A2>
struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
: public binary_function<_A1, _A2, _Rp>
: public __binary_function<_A1, _A2, _Rp>
{
};

Expand Down Expand Up @@ -956,10 +956,8 @@ class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>

template<class _Rp, class ..._ArgTypes>
class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
: public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
#endif
{
#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
Expand Down

0 comments on commit 681cde7

Please sign in to comment.