|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-12-15 17:16:21
From: "Mat Marcus" <mmarcus_at_[hidden]>
> >I think that a compile-time port of boost.bind would be a valuable
addition
> >to MPL.
> >
> >See the end of the message for a starting point. This works on MSVC; a
full
> >port with nested binds and a bind<> syntax (not the numbered bind0,
bind1,
> >... variants) would be possible, too, and is actually not difficult on a
> >conforming compiler. On MSVC it'd be a bit harder, but doable.
> >
> >Comments?
>
> Peter,
>
> Cool. Now I have a question. In the runtime version of bind it seems
> like I can do something like this (borrowed from bind_as_compose.cpp):
>
> template<class F> void test(F f)
> {
> std::cout << f("x", "y") << '\n';
> }
>
> std::string f(std::string const & x)
>
> {
> return "f(" + x + ")";
> }
>
> std::string f(std::string x);
>
> test( bind(f, _1) );
> // emits "f(x)"
>
>
>
> That is, bind helps me avoid the use of compose_f_gxy and project1st.
Let me see if I understand. You want to use 'f' as a binary function that
ignores its second argument, right?
> I would like to do the same thing at compile time. For example, I
> would like to replace:
>
> mpl::compose_f_gxy<
> RightParent
> , :mpl::project1st<mpl::_1, mpl::_2>
> >
>
> with something like:
>
> bind2<RightParent, _1>
>
> Can you see how to do this?
I believe that this should already work, exactly as you've written it; the
bind.hpp header in bind.zip is a (reasonably) complete port of the runtime
bind. bind<RightParent, _1>::type can be used as a metafunction of arity 1
and above.
Actually the compile-time variant doesn't currently enforce even its minimum
arity (as the runtime bind does.)
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk