Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-12-06 07:14:32


From: "Richard Peters" <R.A.Peters_at_[hidden]>
> From: <nbecker_at_[hidden]>
> > While you're at it, I'd like to see constant. Something like:
> >
>
> What about a more general case: a constant generator, and a unary_function
> that ignores the first value but returns the generator instead? Combined
> they provide the functionality of your Constant, and they are also usable
as
> stand-alone functors. And maybe the generator class that behaves similar
to
> unary_function/binary_function (doesn't it already exist?)
>
> template<class Result>
> struct generator {
> typedef Result result_type;
> };
>
> template<class Arg, class Result, class Generator>
> struct unary_ignore: public unary_function<Arg, Result> {
> unary_ignore() {}
> unary_ignore(Generator thegenerator):
> generator(thegenerator) {}
> Result operator()(typename call_traits<Arg>::param_type)
> {
> return Generator();
> };
> private:
> Generator generator;
> };

boost::bind(thegenerator);

> template<class Result>
> struct constant: public generator<Result> {
> constant(Result thevalue):
> value(thevalue) {}
> Result operator()()
> {
> return value;
> }
> private:
> const Result value;
> };

boost::bind(identity<Result>(), value);

> and the same for the binary_function, you could ignore one of the two
> parameters:

Ditto.

--
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