binder2nd.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___FUNCTIONAL_BINDER2ND_H
  10. #define _LIBCPP___FUNCTIONAL_BINDER2ND_H
  11. #include <__config>
  12. #include <__functional/unary_function.h>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. # pragma GCC system_header
  15. #endif
  16. _LIBCPP_BEGIN_NAMESPACE_STD
  17. #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
  18. template <class __Operation>
  19. class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
  20. : public __unary_function<typename __Operation::first_argument_type, typename __Operation::result_type>
  21. {
  22. protected:
  23. __Operation op;
  24. typename __Operation::second_argument_type value;
  25. public:
  26. _LIBCPP_INLINE_VISIBILITY
  27. binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
  28. : op(__x), value(__y) {}
  29. _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
  30. ( typename __Operation::first_argument_type& __x) const
  31. {return op(__x, value);}
  32. _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
  33. (const typename __Operation::first_argument_type& __x) const
  34. {return op(__x, value);}
  35. };
  36. template <class __Operation, class _Tp>
  37. _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
  38. binder2nd<__Operation>
  39. bind2nd(const __Operation& __op, const _Tp& __x)
  40. {return binder2nd<__Operation>(__op, __x);}
  41. #endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
  42. _LIBCPP_END_NAMESPACE_STD
  43. #endif // _LIBCPP___FUNCTIONAL_BINDER2ND_H