Boost logo

Boost Users :

Subject: [Boost-users] different member function signatures based on class template arguments
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-04-08 07:51:44


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,


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net