Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-05-12 04:33:28


Hubert Holin wrote:
> I welcome any suggestion on that matter (and would most welcome
> somebody showing me what I got wrong :-) ).

Maybe a two-step overload is what you are looking for:

<code>

#include <complex>
#include <iostream>
#include <valarray>

// (1/1) Plain vanilla templated function

template<typename T>
T f2(T x)
{
    ::std::cout << "Plain vanilla templated function" << ::std::endl;

    return(x);
}

// (1/2) Template-template function

template<typename T, template<typename> class U>
U<T> f2(U<T> x)
{
    ::std::cout << "Template-template function" << ::std::endl;

    return(x);
}

// (2/1) Plain vanilla templated function

template<typename T>
T f(T x)
{
    return f2(x);
}

// (2/2) Valarray function

template<typename T>
::std::valarray<T> f(const ::std::valarray<T> & x)
{
    ::std::cout << "Valarray function" << ::std::endl;

    ::std::valarray<T> result = x;

    return(result);
}

int main()
{
    double x(1);

    f(x);

    ::std::complex<double> y(0,1);

    f(y);

    const ::std::valarray<double> z(3);

    f(z);
}

</code>

This works for me and outputs:

Plain vanilla templated function
Template-template function
Valarray function

Hope it helps...

Regards, Daniel

-- 
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

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