File indexing completed on 2025-01-18 09:38:15
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_HOF_GUARD_FUNCTION_INFIX_H
0009 #define BOOST_HOF_GUARD_FUNCTION_INFIX_H
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 #include <boost/hof/detail/delegate.hpp>
0082 #include <boost/hof/detail/callable_base.hpp>
0083 #include <boost/hof/always.hpp>
0084 #include <boost/hof/reveal.hpp>
0085 #include <boost/hof/detail/move.hpp>
0086 #include <boost/hof/detail/make.hpp>
0087 #include <boost/hof/detail/static_const_var.hpp>
0088
0089 namespace boost { namespace hof {
0090
0091 namespace detail{
0092 template<class T, class F>
0093 struct postfix_adaptor : F
0094 {
0095 T x;
0096
0097 template<class X, class XF>
0098 constexpr postfix_adaptor(X&& xp, XF&& fp)
0099 BOOST_HOF_NOEXCEPT(BOOST_HOF_IS_NOTHROW_CONSTRUCTIBLE(F, XF&&) && BOOST_HOF_IS_NOTHROW_CONSTRUCTIBLE(T, X&&))
0100 : F(BOOST_HOF_FORWARD(XF)(fp)), x(BOOST_HOF_FORWARD(X)(xp))
0101 {}
0102
0103 template<class... Ts>
0104 constexpr const F& base_function(Ts&&... xs) const noexcept
0105 {
0106 return boost::hof::always_ref(*this)(xs...);
0107 }
0108
0109 BOOST_HOF_RETURNS_CLASS(postfix_adaptor);
0110
0111 template<class... Ts>
0112 constexpr BOOST_HOF_SFINAE_RESULT(const F&, id_<T&&>, id_<Ts>...)
0113 operator()(Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS
0114 (
0115 (BOOST_HOF_MANGLE_CAST(const F&)(BOOST_HOF_CONST_THIS->base_function(xs...)))(BOOST_HOF_RETURNS_C_CAST(T&&)(BOOST_HOF_CONST_THIS->x), BOOST_HOF_FORWARD(Ts)(xs)...)
0116 );
0117
0118 template<class A>
0119 constexpr BOOST_HOF_SFINAE_RESULT(const F&, id_<T&&>, id_<A>)
0120 operator>(A&& a) const BOOST_HOF_SFINAE_RETURNS
0121 (
0122 (BOOST_HOF_MANGLE_CAST(const F&)(BOOST_HOF_CONST_THIS->base_function(a)))(BOOST_HOF_RETURNS_C_CAST(T&&)(BOOST_HOF_CONST_THIS->x), BOOST_HOF_FORWARD(A)(a))
0123 );
0124 };
0125
0126 template<class T, class F>
0127 constexpr postfix_adaptor<T, F> make_postfix_adaptor(T&& x, F f)
0128 BOOST_HOF_NOEXCEPT_CONSTRUCTIBLE(postfix_adaptor<T, F>, T&&, F&&)
0129 {
0130 return postfix_adaptor<T, F>(BOOST_HOF_FORWARD(T)(x), static_cast<F&&>(f));
0131 }
0132 }
0133
0134 template<class F>
0135 struct infix_adaptor : detail::callable_base<F>
0136 {
0137 typedef infix_adaptor fit_rewritable1_tag;
0138 BOOST_HOF_INHERIT_CONSTRUCTOR(infix_adaptor, detail::callable_base<F>);
0139
0140 template<class... Ts>
0141 constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const noexcept
0142 {
0143 return boost::hof::always_ref(*this)(xs...);
0144 }
0145
0146 template<class... Ts>
0147 constexpr const detail::callable_base<F>& infix_base_function(Ts&&... xs) const noexcept
0148 {
0149 return boost::hof::always_ref(*this)(xs...);
0150 }
0151
0152 BOOST_HOF_RETURNS_CLASS(infix_adaptor);
0153
0154 template<class... Ts>
0155 constexpr auto operator()(Ts&&... xs) const BOOST_HOF_RETURNS
0156 (
0157 (BOOST_HOF_MANGLE_CAST(const detail::callable_base<F>&)(BOOST_HOF_CONST_THIS->base_function(xs...)))(BOOST_HOF_FORWARD(Ts)(xs)...)
0158 );
0159 };
0160
0161 template<class T, class F>
0162 constexpr auto operator<(T&& x, const infix_adaptor<F>& i) BOOST_HOF_RETURNS
0163 (detail::make_postfix_adaptor(BOOST_HOF_FORWARD(T)(x), boost::hof::move(i.base_function(x))));
0164
0165
0166
0167 namespace detail {
0168
0169 template<class F>
0170 struct static_function_wrapper;
0171
0172
0173 template<class T, class F>
0174 auto operator<(T&& x, const boost::hof::detail::static_function_wrapper<F>& f) BOOST_HOF_RETURNS
0175 (
0176 detail::make_postfix_adaptor(BOOST_HOF_FORWARD(T)(x), boost::hof::move(f.base_function().infix_base_function()))
0177 );
0178
0179 template<class F>
0180 struct static_default_function;
0181
0182
0183 template<class T, class F>
0184 auto operator<(T&& x, const boost::hof::detail::static_default_function<F>&) BOOST_HOF_RETURNS
0185 (
0186 detail::make_postfix_adaptor(BOOST_HOF_FORWARD(T)(x), boost::hof::move(F().infix_base_function()))
0187 );
0188 }
0189
0190 template<class T, class F>
0191 constexpr auto operator<(T&& x, const boost::hof::reveal_adaptor<F>& f) BOOST_HOF_RETURNS
0192 (
0193 detail::make_postfix_adaptor(BOOST_HOF_FORWARD(T)(x), f.infix_base_function())
0194 );
0195
0196 BOOST_HOF_DECLARE_STATIC_VAR(infix, detail::make<infix_adaptor>);
0197
0198 }}
0199
0200 #endif