different member function signatures based on class template arguments

Hello, I have a long chain of calls of functions where a template argument is passed from 1 function to the next. Different template arguments required slightly different arguments in the following signature: template< typename Interp> struct InterExtrap { static void Process( xbegin, xend, x, AdditionalArguments<Interp> ); // this calls static function inside Interp }; AdditionalArguments<Interp> is: . empty for a couple of Interp . size_t for a couple of others . double d0, double d1 for a couple of others. If all cases had exactly 1 argument which varied, I would have done above: typename AdditionalArguments<Interp>::type I could do struct S { double d1; double d2; }; I have in mind optimization issues as well as many of these intermediate functions are inlined. So I am concerned about process(xbegin, xend, x, const S& s) // then access s.d1 and s.d2 as I measured it is slower than process(xbegin, xend, x, double d1, double d2) Initial function (specifies Interp and therefore knows whether to pass empty, or size_t, or double double) calls a number of intermediate functions that are not interested in this detail, but still have the Interp template argument, and finally call static functions inside Interp which then know what they require as arguments. Is it possible to write the intermediate functions (member of template classes) in a generic way? Would SFINAE or the sizeof trick or any MPL Fusion facility allow this? Regards,

Hicham Mouline a écrit :
How did you performed your benchmark ? Most modern compiler should produce similar code for those two interface. Are you sure you pass your structure by reference ? How large is your sample measures ? -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

I tried something along these lines: http://codepad.org/ieS3W2aO but it failed to compile... Shouldn't the enable_if metafct remove the invalid functions from the overload set? Regards,

Hicham Mouline a écrit :
It probably failed because you use typename inside the enable_if condition. Make a meta-function that do your test and invoke it inside enable_if -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Thanks. I moved the 1st typename out of enable_if in a separate metatfct (kind of binder1st for mpl) It still fails the compile error is here: http://codepad.org/gR04D5T5 regards,

Hicham Mouline a écrit :
You may want to use enable_if on the return type instead of the argument type. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Here is an alternative working function that doesn't use enable_if : http://codepad.org/KZ4OTKxY

Great, this works very well.... Thank you, I can't help thinking this is a king of common pattern perhaps used inside boost itself many times, and that there is some helper "something" for this already? Because, basically I need 1 S_impl for each extra additional argument. But I suppose I can generate them with BOOST_PP Rds,

Hicham Mouline a écrit :
Because, basically I need 1 S_impl for each extra additional argument. But I suppose I can generate them with BOOST_PP
Yes it should :) ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Here is the unedited code: http://codepad.org/CDOFhSqZ As it is shown here, in debug VS2005SP1, when I get inside the out-of-class def of GetSpot i and e both show garbage. When I added = Interp() and = Extrap() to the out-of-class def, debug works fine. I didn't try in Release yet, Rds,
participants (2)
-
Hicham Mouline
-
Joel Falcou