Boost logo

Boost :

Subject: Re: [boost] [range] treating N-ary function with N-1 default args as unary
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-06-30 00:21:59


> Some Boost.Range adaptors, such as 'transformed' or 'filtered', require
> a unary function. The documentation does not formally define "unary
> function", but it's pretty clear what it ought to be: a function (object)
> that's callable with one argument.
>
> Thus, to me, the following is a perfectly valid unary function:
>
> int foo(int a, int b = 0);
>
> as it is callable with one argument.
>
> However, Boost.Range does not accept such a function as an argument to
> 'transformed' or 'filtered'.
>
> [snip]
>
> Would it be possible to treat N-ary functions with N-1 default arguments
> as unary?

To motivate this request a bit further, suppose 'foo' is a function in
some library, so that I can't just replace it with two overloads, and
consider possible workarounds:

1. range | transformed(bind(foo, _1, let_me_repeat_the_default_arg_here));

2. range | transformed([](let_me_write_out_the_type_of_foo's_argument_here x)
                       { return foo(x); })

The first requires repeating the library function's default argument, which
introduces a risk of the actual behaviour becoming out of sync with the
desired behaviour if the default argument used by the library changes.
(Note that simply bind(foo, _1) will not work - it produces similar errors).

The second is messy (and would be even more so in C++03) and requires writing
out the potentially long type name of the function's argument.

I can't think of anything better at the moment.

Regards,
Nate

                                               


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