Boost logo

Boost :

Subject: Re: [boost] [functors] proposal
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2013-10-23 06:33:20


2013/10/23 Edward Diener <eldiener_at_[hidden]>

> On 10/22/2013 4:16 PM, Piotr Wygocki wrote:
>
>> Hi, I've developed a small set of functors and functor adaptors.
>> Although this code is very simple it might be very useful for some subset
>> of the community.
>>
>> Do you think it might become a part of the boost library?
>> If not I'm still very interested in any feedback.
>> I think it's not big enough to be a separate library.
>> To my knowledge of boost it fits in the utility lib.
>>
>> The code can be found here:
>>
>> https://github.com/wygos/**functors <https://github.com/wygos/functors>
>>
>> List of utilities:
>>
>> SkipFunctor
>> takes any number of arguments; does completely nothing
>>
>> ReturnSomethingFunctor<T,t>
>> takes any number of arguments; returns t;
>>
>> IdentityFunctor
>> takes one parameter and returns it.
>>
>> ReturnFalseFunctor
>> takes any number of arguments; returns false;
>>
>> ReturnTrueFunctor
>> takes any number of arguments; returns true;
>>
>> ReturnZeroFunctor
>> takes any number of arguments; returns 0;
>>
>> AssertFunctor
>> takes any number of arguments; asserts;
>>
>> ArrayToFunctor<Array>
>> Stores an object which provides operator[].
>> Provides operator()().
>>
>> A set of non-template comparison functors (only operator() is templated):
>> * Greater
>> * Less
>> * GreaterEqual
>> * LessEqual
>> * EqualTo
>> * NotEqualTo
>>
>>
>> FunctorToComparator<Functor, Compare>
>> This comparator takes a functor "f" and a comparator "c".
>> For elements (x,y) it returns c(f(x), f(y))
>> c is Less by default
>>
>>
>> FunctorToOutputIterator<**Functor>
>> The output iterator stores a functor and
>> each time the operator= is called the given functor is called
>>
>> Logical operators as functors:
>> * Not
>> * Or
>> * And
>> * Xor
>>
>> LiftBinaryOperatorFunctor<**Operator, FunctorLeft, FunctorRight>
>> Functor stores a binary operator "o" and two functors "f" and "g".
>> For given arguments args returns o(f(args), g(args)).
>>
>> Boolean functor adapters. Each of them stores a boolean functor
>> and performs an appropriate logical operation in the operator().
>>
>> * NotFunctor<Functor>
>> * OrFunctor<FunctorLeft, FunctorRight>
>> * AndFunctor<FunctorLeft, FunctorRight>
>> * XorFunctor<FunctorLeft, FunctorRight>
>>
>
> Are you aware of Boost.Phoenix ( or its predecessor Boost.Lambda ) ? Also
> some of the functors appear to duplicate functors in the C++ standard
> library in functional.
>
> Logical Xor ?
>
> New and useful functors are always welcome but please look at Phoenix
> first. If you feel you still have new functors maybe you can talk to the
> Phoenix developers to see if they will fit in Phoenix, or submit your
> library if there is enough interest by others.
>
>
>
>
>> Regards,
>>
>> Piotr
>>
>> Hi Piotr,

Like Edward suggested, Boost.Phoenix is your library for these kinds of
things and much more.

I had some fun rewriting your examples with Boost.Phoenix, please see the
attached file.

I omitted two cases: SkipFunctor and AssertFunctor. I'm not sure how to do
that, nor do I see a potential use case for those ;-)

Regards,
Kris




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk