Boost logo

Boost :

Subject: [boost] [functors] proposal
From: Piotr Wygocki (vwygos_at_[hidden])
Date: 2013-10-22 16:16:12


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

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>

Regards,

Piotr


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