/*============================================================================= Copyright (c) 2016 Paul Fultz II limit.h Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ #ifndef BOOST_HOF_GUARD_LIMIT_H #define BOOST_HOF_GUARD_LIMIT_H /// limit /// ===== /// /// Description /// ----------- /// /// The `limit` function decorator annotates the function with the max number /// of parameters. The `limit_c` version can be used to give the max number /// directly(instead of relying on an integral constant). The parameter limit /// can be read by using the [`function_param_limit`](function_param_limit) /// trait. Using `limit` is useful to improve error reporting with partially /// evaluated functions. /// /// Synopsis /// -------- /// /// template /// constexpr auto limit(IntegralConstant); /// /// template /// constexpr auto limit_c(F); /// /// Requirements /// ------------ /// /// IntegralConstant must be: /// /// * IntegralConstant /// /// F must be: /// /// * [ConstInvocable](ConstInvocable) /// * MoveConstructible /// /// Example /// ------- /// /// #include /// #include /// using namespace boost::hof; /// /// struct sum_f /// { /// template /// int operator()(T x, T y) const /// { /// return x+y; /// } /// }; /// BOOST_HOF_STATIC_FUNCTION(sum) = limit_c<2>(sum_f()); /// /// int main() { /// assert(3 == sum(1, 2)); /// } /// /// See Also /// -------- /// /// * [Partial function evaluation]() /// * [function_param_limit](function_param_limit) /// #include #include #include #include #include #include #include namespace boost { namespace hof { namespace detail { // TODO: Make this work with fit_rewritable1_tag template struct limit_adaptor : detail::callable_base { typedef std::integral_constant fit_function_param_limit; BOOST_HOF_INHERIT_CONSTRUCTOR(limit_adaptor, detail::callable_base) template constexpr const detail::callable_base& base_function(Ts&&... xs) const { return boost::hof::always_ref(*this)(xs...); } BOOST_HOF_RETURNS_CLASS(limit_adaptor); template::type> constexpr BOOST_HOF_SFINAE_RESULT(const detail::callable_base&, id_...) operator()(Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS ( (BOOST_HOF_MANGLE_CAST(const detail::callable_base&)(BOOST_HOF_CONST_THIS->base_function(xs...))) (BOOST_HOF_FORWARD(Ts)(xs)...) ); }; template struct make_limit_f { constexpr make_limit_f() {} template constexpr limit_adaptor operator()(F f) const { return limit_adaptor(static_cast(f)); } }; struct limit_f { template constexpr make_limit_f operator()(IntegralConstant) const { return {}; } }; } template constexpr detail::limit_adaptor limit_c(F f) { return detail::limit_adaptor(static_cast(f)); } BOOST_HOF_DECLARE_STATIC_VAR(limit, detail::limit_f); }} // namespace boost::hof #endif