|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2007-04-27 20:16:20
Peter Dimov wrote:
> Eric Niebler wrote:
>> Peter Dimov wrote:
>>> Eric Niebler wrote:
>>>
>>>> Although I don't know all the details of bind and lambda, I had
>>>> hoped that _1 and _2 would be abstract proto entities, such that
>>>>
>>>> _1 == _2
>>>>
>>>> creates an expression template like:
>>>>
>>>> equal< terminal< arg<1> >, terminal< arg<2> > >
>>>>
>>>> which is a generic, abstract representation of an equals expression
>>>> with two placeholders. Can't bind and lambda both be implemented to
>>>> recognize such a type and do the appropriate thing with it?
>>> Possibly, if they are made to honor is_bind_expression
>>> specializations and result_of, if is_bind_expression reports true
>>> for the above type, if the above is a function object that actually
>>> returns x == y, and if result_of works for it.
>> Yes, that can all be made to work without much difficulty.
>
> The part about boost::bind using is_bind_expression and result_of cannot,
> not without major surgery and possibly compromising portability.
I'll have to take your word for it -- I'm not familiar enough with the
TR1 bind to appreciate the difficulty of respecting is_bind_expression.
It seems to me that is_bind_expression can be trivially implemented,
given appropriately defined placeholders. Eg. if they are defined in a
super-secret hidden namespace, like so:
namespace super_secret_hidden {
template<class I> struct arg { typedef I arity; };
template<class T> yes_type is_bind_expression_impl(T const *);
}
no_type is_bind_expression_impl(void const *);
Now _1 is:
proto::terminal<super_secret_hidden::arg<mpl::int_<1> > >::type const _1
= {{}};
And is_bind_expression<> is trivially implementable using ADL and
sizeof. Should work for older compilers, too, right? Are their compilers
we support that don't do ADL?
Result_of support for older compilers ... I suppose that requires
partial template specialization, right? Do we still support compilers
that don't do PTS?
> Sometimes I get excited about the new C++0x features and tell myself, why
> not rewrite boost::bind to take advantage of them? Then it occurs to me that
> C++0x has a std::bind built-in. :-) (Happened twice so far.)
Haha!
-- Eric Niebler Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk