From d1d273a84a3acaa846dc7421d9a4c254707ea455 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 15 Jul 2013 22:50:40 +0900 Subject: [PATCH] fic cbind --- sprout/functional/bind/bind.hpp | 53 ++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/sprout/functional/bind/bind.hpp b/sprout/functional/bind/bind.hpp index e37a4a27..4cbed89f 100644 --- a/sprout/functional/bind/bind.hpp +++ b/sprout/functional/bind/bind.hpp @@ -694,7 +694,7 @@ namespace sprout { } public: template - explicit res_binder_impl(Functor const& f, Args&&... args) + explicit SPROUT_CONSTEXPR res_binder_impl(Functor const& f, Args&&... args) : f_(f) , bound_args_(sprout::forward(args)...) {} @@ -893,12 +893,41 @@ namespace sprout { > >::type {}; + template + struct res_binder_complete_placeholders_impl< + I, N, Bounds, sprout::res_cbinder, + typename std::enable_if<(I < sprout::tuples::tuple_size::value)>::type + > + : public std::conditional< + sprout::is_positional_placeholder::type>::value, + sprout::detail::res_binder_complete_placeholders_impl< + I + 1, N + 1, Bounds, + sprout::res_cbinder)> + >, + sprout::detail::res_binder_complete_placeholders_impl< + I + 1, N, Bounds, + sprout::res_cbinder::type)> + > + >::type + {}; + template + struct res_binder_complete_placeholders; template - struct res_binder_complete_placeholders + struct res_binder_complete_placeholders< + false, Result, Func, BoundArgs... + > : public sprout::detail::res_binder_complete_placeholders_impl< 0, 0, sprout::types::type_tuple, sprout::res_binder > {}; + template + struct res_binder_complete_placeholders< + true, Result, Func, BoundArgs... + > + : public sprout::detail::res_binder_complete_placeholders_impl< + 0, 0, sprout::types::type_tuple, sprout::res_cbinder + > + {}; template struct bind_helper { @@ -907,12 +936,12 @@ namespace sprout { typedef typename maybe_type::type func_type; typedef typename sprout::detail::binder_complete_placeholders::type...>::type type; }; - template + template struct res_bind_helper { public: typedef sprout::detail::maybe_wrap_member_pointer::type> maybe_type; typedef typename maybe_type::type functor_type; - typedef typename sprout::detail::res_binder_complete_placeholders::type...>::type type; + typedef typename sprout::detail::res_binder_complete_placeholders::type...>::type type; }; } // namespace detail @@ -937,7 +966,12 @@ namespace sprout { template struct res_bind_result { public: - typedef typename sprout::detail::res_bind_helper::type type; + typedef typename sprout::detail::res_bind_helper::type type; + }; + template + struct res_cbind_result { + public: + typedef typename sprout::detail::res_bind_helper::type type; }; // @@ -954,7 +988,7 @@ namespace sprout { template inline SPROUT_CONSTEXPR typename sprout::res_bind_result::type bind(F&& f, BoundArgs&&... args) { - typedef sprout::detail::res_bind_helper helper_type; + typedef sprout::detail::res_bind_helper helper_type; typedef typename helper_type::maybe_type maybe_type; typedef typename helper_type::type result_type; return result_type(maybe_type::do_wrap(sprout::forward(f)), sprout::forward(args)...); @@ -972,9 +1006,12 @@ namespace sprout { return result_type(maybe_type::do_wrap(sprout::forward(f)), sprout::forward(args)...); } template - inline SPROUT_CONSTEXPR typename sprout::detail::res_bind_helper::type const + inline SPROUT_CONSTEXPR typename sprout::res_cbind_result::type cbind(F&& f, BoundArgs&&... args) { - return sprout::bind(sprout::forward(f), sprout::forward(args)...); + typedef sprout::detail::res_bind_helper helper_type; + typedef typename helper_type::maybe_type maybe_type; + typedef typename helper_type::type result_type; + return result_type(maybe_type::do_wrap(sprout::forward(f)), sprout::forward(args)...); } } // namespace sprout