File indexing completed on 2025-10-31 08:42:25
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 #ifndef BOOST_HOF_GUARD_LIMIT_H
0009 #define BOOST_HOF_GUARD_LIMIT_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 #include <boost/hof/detail/callable_base.hpp>
0074 #include <boost/hof/detail/forward.hpp>
0075 #include <boost/hof/detail/delegate.hpp>
0076 #include <boost/hof/detail/move.hpp>
0077 #include <boost/hof/detail/static_const_var.hpp>
0078 #include <boost/hof/always.hpp>
0079 #include <boost/hof/function_param_limit.hpp>
0080 
0081 namespace boost { namespace hof {
0082 
0083 namespace detail {
0084 
0085 template<std::size_t N, class F>
0086 struct limit_adaptor : detail::callable_base<F>
0087 {
0088     typedef std::integral_constant<std::size_t, N> fit_function_param_limit;
0089     BOOST_HOF_INHERIT_CONSTRUCTOR(limit_adaptor, detail::callable_base<F>)
0090 
0091     template<class... Ts>
0092     constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const
0093     {
0094         return boost::hof::always_ref(*this)(xs...);
0095     }
0096 
0097     BOOST_HOF_RETURNS_CLASS(limit_adaptor);
0098 
0099     template<class... Ts, class=typename std::enable_if<(sizeof...(Ts) <= N)>::type>
0100     constexpr BOOST_HOF_SFINAE_RESULT(const detail::callable_base<F>&, id_<Ts>...) 
0101     operator()(Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS
0102     (
0103         (BOOST_HOF_MANGLE_CAST(const detail::callable_base<F>&)(BOOST_HOF_CONST_THIS->base_function(xs...)))
0104             (BOOST_HOF_FORWARD(Ts)(xs)...)
0105     );
0106 
0107 };
0108 
0109 template<std::size_t N>
0110 struct make_limit_f
0111 {
0112     constexpr make_limit_f()
0113     {}
0114     template<class F>
0115     constexpr limit_adaptor<N, F> operator()(F f) const
0116     {
0117         return limit_adaptor<N, F>(static_cast<F&&>(f));
0118     }
0119 };
0120 
0121 struct limit_f
0122 {
0123     template<class IntegralConstant, std::size_t N=IntegralConstant::type::value>
0124     constexpr make_limit_f<N> operator()(IntegralConstant) const
0125     {
0126         return {};
0127     }
0128 };
0129 
0130 }
0131 
0132 template<std::size_t N, class F>
0133 constexpr detail::limit_adaptor<N, F> limit_c(F f)
0134 {
0135     return detail::limit_adaptor<N, F>(static_cast<F&&>(f));
0136 }
0137 
0138 BOOST_HOF_DECLARE_STATIC_VAR(limit, detail::limit_f);
0139 
0140 }} 
0141 
0142 #endif