• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 #ifndef _LIBCPP___FUNCTIONAL_COMPOSE_H
11 #define _LIBCPP___FUNCTIONAL_COMPOSE_H
12 
13 #include <__config>
14 #include <__functional/invoke.h>
15 #include <__functional/perfect_forward.h>
16 #include <__utility/forward.h>
17 
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 #  pragma GCC system_header
20 #endif
21 
22 _LIBCPP_BEGIN_NAMESPACE_STD
23 
24 #if _LIBCPP_STD_VER >= 20
25 
26 struct __compose_op {
27     template<class _Fn1, class _Fn2, class ..._Args>
28     _LIBCPP_HIDE_FROM_ABI
29     constexpr auto operator()(_Fn1&& __f1, _Fn2&& __f2, _Args&&... __args) const
30         noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Fn1>(__f1), _VSTD::invoke(_VSTD::forward<_Fn2>(__f2), _VSTD::forward<_Args>(__args)...))))
31         -> decltype(      _VSTD::invoke(_VSTD::forward<_Fn1>(__f1), _VSTD::invoke(_VSTD::forward<_Fn2>(__f2), _VSTD::forward<_Args>(__args)...)))
32         { return          _VSTD::invoke(_VSTD::forward<_Fn1>(__f1), _VSTD::invoke(_VSTD::forward<_Fn2>(__f2), _VSTD::forward<_Args>(__args)...)); }
33 };
34 
35 template <class _Fn1, class _Fn2>
36 struct __compose_t : __perfect_forward<__compose_op, _Fn1, _Fn2> {
37     using __perfect_forward<__compose_op, _Fn1, _Fn2>::__perfect_forward;
38 };
39 
40 template <class _Fn1, class _Fn2>
41 _LIBCPP_HIDE_FROM_ABI
42 constexpr auto __compose(_Fn1&& __f1, _Fn2&& __f2)
43     noexcept(noexcept(__compose_t<decay_t<_Fn1>, decay_t<_Fn2>>(_VSTD::forward<_Fn1>(__f1), _VSTD::forward<_Fn2>(__f2))))
44     -> decltype(      __compose_t<decay_t<_Fn1>, decay_t<_Fn2>>(_VSTD::forward<_Fn1>(__f1), _VSTD::forward<_Fn2>(__f2)))
45     { return          __compose_t<decay_t<_Fn1>, decay_t<_Fn2>>(_VSTD::forward<_Fn1>(__f1), _VSTD::forward<_Fn2>(__f2)); }
46 
47 #endif // _LIBCPP_STD_VER >= 20
48 
49 _LIBCPP_END_NAMESPACE_STD
50 
51 #endif // _LIBCPP___FUNCTIONAL_COMPOSE_H
52