Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2004-07-29 08:18:33


Arkadiy Vertleyb writes:
> This would probably be OK, since GCC has the native typeof support.
> However, when I use the native support, I run into a different problem
that
> can be illustrated by the following code:
>
> template<class T, class U>
> typeof(T() + U()) sum(const T& t, const U& u)
> {
> return t + u;
> }
>
> main()
> {
> sum(5, 3.14); // this is line 9
> return 0;
> }
>
> The compile of this code fails with following message:
>
> a.cpp:9: internal compiler error: in write_type, at cp/mangle.c:1555

The following compiles for me (GCC 3.3.3 mingw special):

    template<class T, class U> struct typeof_
    {
        typedef typeof(T() + U()) type;
    };

    template<class T, class U>
    typename typeof_<T,U>::type sum(const T& t, const U& u)
    {
            return t + u;
    }

    int main()
    {
            sum(5, 3.14); // this is line 9
            return 0;
    }

--
Aleksey Gurtovoy
MetaCommunications Engineering

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