|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-01-23 23:31:16
"Joel de Guzman" <djowel_at_[hidden]> writes:
> ----- Original Message -----
> From: "Aleksey Gurtovoy" <agurtovoy_at_[hidden]>
>
>> My current understanding (which, admittedly, is not backed up by a
>> real-world experience) is that if you care about higher-orderness of your
>> generic algorithms, a preferred implementation construct for those
>> algorithms is not a function template, but a static _function object_ (a
>> technique used in FC++):
>>
>> struct my_function_
>> {
>> template< typename U >
>> void operator()(std::string const& text, U)
>> {
>> // ...
>> }
>>
>> } my_function; // here!
>>
>>
>> For ordinary uses, the above will act just like a plain function template
>> (minus ADL/explicit template arguments specification):
>>
>> my_function("text", int());
>>
>> and it will also allow one to do something like this:
>>
>> std::string text("text");
>> mpl::for_each< my_types >(boost::bind<void>(my_function, text, _1));
>
> This technique is adopted by Phoenix. With this, you can even do
> (as suggested by Joel Young):
>
> - \ \
> double - /\ f . /\ x. f(f x)
> - / \ / \
>
> struct square_ {
>
> template <typename X>
> struct result { typedef X type; };
>
> template <typename X>
> X operator()(X x)
> {
> return x * x;
> }
> };
This is similar to my "universal identity" suggestion from many months
back. However, "result" should be "apply" to make it an MPL
metafunction class <wink>.
Hum, that result template looks like identity, and not square. Am I
missing something? I'd have thought:
template <typename X>
struct result : mpl::times<X,X> {};
> function<square_> square;
>
> template <typename F>
> struct ffx {
>
> template <typename X>
> struct result { typedef X type; };
Mighty confused. Not
template <typename X>
struct result : mpl::apply<F, typename mpl::apply<F,X>::type> {};
??
If not, what's the point of "result"?
> PS> Jaakko and I are working on the LL/Phoenix merger.
Yay! What about my tuples question?
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk