Boost logo

Boost Users :

Subject: Re: [Boost-users] Can not compile a program that uses typeof package by gcc?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-10-20 23:19:42


AMDG

Peng Yu wrote:
>> In line 51-55 of you attached file, it says the following.
>>
>> template <typename T1, typename T2>
>> Y<typename A::multiply_traits<T1, T2>::result_type>
>> operator*(const Y<T1> &y, const T2 &t) {
>> return Y<T1>(y.the_t() * t);
>> }
>>
>> This way requires that I have to explicitly say 'multiply_traits' is
>> from the namespace A. I wanted to use the following instead, which
>> does not need to specify which the namespaces T1 and T2 are. But the
>> following code still results in the compiler error.
>>
>> template <typename T1, typename T2>
>> Y<BOOST_TYPEOF(T1() * T2())>
>> operator*(const Y<T1> &y, const T2 &t) {
>> return Y<T1>(y.the_t() * t);
>> }
>>
>> My question is not resolved. I'm attaching the source file with some
>> comments to avoid any confusion. Would you please take another look at
>> the problem?
>>

Alright. If you don't want to refer to multiply_traits from namespace
A, then put a generic multiply_traits somewhere else. When it is defined
using Boost.Typeof, it will work for any types. It does not matter what
namespace multiply_traits is defined in. Really.

template<class T1, class T2>
struct typeof_multiply {
    BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, (make<T1>() * make<T2>()));
    typedef typename nested::type type;
};

...

template<class T1, class T2>
Y<typename typeof_multiply<T1, T2>::type> operator*(...);

Really, all this does is to move the typeof calculation into a separate
metafunction.

In Christ,
Steven Watanabe


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