|
Boost : |
From: Shunsuke Sogame (mb2act_at_[hidden])
Date: 2006-07-21 02:26:04
Pavol Droba wrote:
> Hi,
>
> First of all, I'd like to thank you for the nice benchmarks.
>
> Now my comments to your patches:
>
> 1.) const Predicate& Pred
> Although this change can bring a performance benefits, it has one big
> drawback. You cannot pass an ordinary C function as predicate.
> At least not in VC++ 7.1
>
> Following code will not work:
>
> int func(int a)
> {
> return a+2;
> }
>
> template<typename TFunc>
> int sum(TFunc f, unsigned int a)
> {
> int acum=0;
> for(unsigned int i=0; i<a; i++)
> {
> acum+=f(i);
> }
>
> return acum;
> }
>
> ...
>
> sum(func, 1000);
It is surprising for me.
VC++ seems to need overloads:
int func(int a)
{
return a+2;
}
struct func_t
{
int operator()(int a) const
{
return a+2;
}
};
template<typename TFunc>
int sum_aux(TFunc& f, unsigned int a)
{
int acum=0;
for(unsigned int i=0; i<a; i++)
{
acum+=f(i);
}
return acum;
}
template<typename TFunc>
int sum(TFunc const& f, unsigned int a)
{
return ::sum_aux(f, a);
}
template<typename TFunc>
int sum(TFunc& f, unsigned int a)
{
return ::sum_aux(f, a);
}
void test()
{
::sum(::func, 1000);
::sum(&::func, 1000);
::sum(::func_t(), 1000);
}
Looks working well under gcc and vc.
But, the forwarding problem will come...
-- Shunsuke Sogame
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk