binder1st.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_BINDER1ST_H
  10. #define _LIBCPP___FUNCTIONAL_BINDER1ST_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 binder1st
  20. : public unary_function<typename __Operation::second_argument_type,
  21. typename __Operation::result_type>
  22. {
  23. protected:
  24. __Operation op;
  25. typename __Operation::first_argument_type value;
  26. public:
  27. _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
  28. const typename __Operation::first_argument_type __y)
  29. : op(__x), value(__y) {}
  30. _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
  31. (typename __Operation::second_argument_type& __x) const
  32. {return op(value, __x);}
  33. _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
  34. (const typename __Operation::second_argument_type& __x) const
  35. {return op(value, __x);}
  36. };
  37. template <class __Operation, class _Tp>
  38. _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
  39. binder1st<__Operation>
  40. bind1st(const __Operation& __op, const _Tp& __x)
  41. {return binder1st<__Operation>(__op, __x);}
  42. #endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
  43. _LIBCPP_END_NAMESPACE_STD
  44. #endif // _LIBCPP___FUNCTIONAL_BINDER1ST_H