Boost logo

Boost :

Subject: Re: [boost] [review] Review of PolyCollection starts today (May 3rd)
From: Edward Diener (eldiener_at_[hidden])
Date: 2017-05-06 14:49:45


On 5/6/2017 5:07 AM, Joaquin M López Muñoz via Boost wrote:
> El 06/05/2017 a las 5:53, Edward Diener via Boost escribió:
>> On 5/2/2017 7:46 PM, Ion Gaztañaga via Boost wrote:
>>> Hi everyone,
>>>
>>> The formal review of Joaquín M. López Muñoz's PolyCollection library
>>> starts today.
>>> [...]
>>>
>>> * boost::function_collection
>>
>> I could not understand from the documentation what it is I am supposed
>> to be
>> inserting into a function_collection. The tutorial did not explain
>> this to me and the
>> reference's technical explanation on this eluded me.
>
> You can insert into a boost::function_collection<Signature> any entity
> that a
> std::function<Signature> object could be constructed from. For instance,
> boost::function_collection<double(int)> holds callable entities that can
> be invoked with
> a (convertible to) int argument and return a (convertible to) double
> result:
>
> double f(int n){return (double)n;}
>
> struct g
> {
> double operator()(int n)const{return (double)2*n;}
> };
>
> boost::function_collection<double(int)> c;
> c.insert(&f);
> c.insert(g{});
> double factor=3;
> c.insert([=](int n){return factor*n;});
>
> for(const auto& x:c)std::cout<<x(1)<<" "; // prints 3 1 2
>
> This is explained in http://tinyurl.com/kddv9nz . Didn't you find this
> section
> sufficiently explanatory?

The explanation you cite with the link above is a tutorial, not an
explanation. Furthermore, perhaps for the sake of syntactical brevity,
you cite an example in which a lambda function returns another lambda
function !!! This may be exceedingly clever but it can hardly be a
mainstream explanation of your functionality which most programmers
would easily understand as how a function collection "works". Your
examples above are a much better and more mainstream example of how the
function_collection works, and even the short explanation you have given
me should have been in the documentation.

It is also hard to understand what the advantage of a poly collection of
these objects entail over a more normal C++ collection ( vector, array
etc. ) of std::function<Signature> objects, since the latter object type
already represents a generalized callable construct in C++. Some of your
performance tests suggest there is little or no advantage, so a
discussion of this would have been welcome in the documentation.

>
> Joaquín M López Muñoz


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