Boost logo

Boost :

Subject: Re: [boost] Library design Q : overloads v/s default args
From: Thomas Klimpel (Thomas.Klimpel_at_[hidden])
Date: 2010-06-21 10:58:52

David Abrahams wrote:
> > In fact, Rutgers code doesn't erase rvalue-ness as well,
> I think you mean *does*, right?


> > it was just me misinterpreting things. So what he does is really
> > just a "perfect forwarding" emulation, just as Boost.Parameter
> > does. However, I wonder whether Boost.Parameter uses the
> > preprocessor to implicitly generate a similar amount of code as
> > Rutgers solution explicitly generates.
> Well, Boost.Parameter has the advantage of knowing which parameters
> need to be passed by non-const reference, so unless all your
> parameters are “out” or “in_out” parameters, it probably does better
> than Rutger's solution.

Even so I can well imagine that Boost.Parameter might work better in certain cases than Rutger's solution, I can't imagine how Boost.Parameter could have more information about the code than the code generator.

> > In that case, I would wonder whether it would be possible to
> > selectively turn off the T const& overload for parameters that don't
> > need it (so that we could still use the "workaround" mentioned
> > above).
> Why would you want to turn that one off, as opposed to the T& one (as
> Boost.Parameter does)? Seems kinda crazy.

Well, perhaps the old fortran interfaces with their unbelievable long lists of input and output parameters are crazy. Below is one overload for ggevx, but the code generator has generated 2^5=32 of these. The function has "only" 12 template parameters, but 15 "out" or "in_out" parameters. So if there is no way to tell Boost.Parameter for which of these "in_out" parameters the "T const&" overload can be omitted, it will be forced to generate 2^15 = 32768 overloads.

// Overloaded function for ggevx. Its overload differs for
// * MatrixA&
// * MatrixB&
// * MatrixVL&
// * MatrixVR&
// * User-defined workspace
template< typename MatrixA, typename MatrixB, typename VectorALPHAR,
        typename VectorALPHAI, typename VectorBETA, typename MatrixVL,
        typename MatrixVR, typename VectorLSCALE, typename VectorRSCALE,
        typename VectorRCONDE, typename VectorRCONDV, typename Workspace >
inline typename boost::enable_if< detail::is_workspace< Workspace >,
        std::ptrdiff_t >::type
ggevx( const char balanc, const char jobvl, const char jobvr,
        const char sense, MatrixA& a, MatrixB& b, VectorALPHAR& alphar,
        VectorALPHAI& alphai, VectorBETA& beta, MatrixVL& vl, MatrixVR& vr,
        fortran_int_t& ilo, fortran_int_t& ihi, VectorLSCALE& lscale,
        VectorRSCALE& rscale, typename remove_imaginary<
        typename bindings::value_type< MatrixA >::type >::type& abnrm,
        typename remove_imaginary< typename bindings::value_type<
        MatrixA >::type >::type& bbnrm, VectorRCONDE& rconde,
        VectorRCONDV& rcondv, Workspace work ) {
    return ggevx_impl< typename bindings::value_type<
            MatrixA >::type >::invoke( balanc, jobvl, jobvr, sense, a, b,
            alphar, alphai, beta, vl, vr, ilo, ihi, lscale, rscale, abnrm,
            bbnrm, rconde, rcondv, work );


Boost list run by bdawes at, gregod at, cpdaniel at, john at