Boost logo

Boost Users :

From: Daniel Krügler (dsp_at_[hidden])
Date: 2008-05-22 02:29:57


Noah Roberts wrote:
> Hansi wrote:
>
>>Hello,
>>
>>Thank you for your helped.
>>You was right. I have tested your code inside mine. For that I have
>>adapted something and the problem (I have posted it in another answer).
>>The problem ist that I had the follwing struct:
>>
>>struct Test
>>{
>> typedef boost::tuple<int,char> tuple_t;
>> tuple_t tup;
>> enum Members { NAME, VALUE };
>>
>> typename boost::tuples::element<NAME, tuple_t>::type
>> name()
>> { return boost::get<NAME>(tup); }
>>};
>>
>>and here the declaration doesn't work.
>
>
> loose the typename. I read what others stated about its appropriateness
> and I don't know if that is true or not. What I do know is that the
> compiler we both use won't accept it.
>
> If you remove typename it should work.

I totally agree with you, the typename here - at least what is
visible from this snippet context - is not legal according
to C++03, see [temp.res], 5:

"The keyword typename shall only be used in template declarations
and definitions, including in the return type of a function template
or member function template, in the return type for the definition
of a member function of a class template or of a class nested within
a class template, and in the type-specifier for the definition
of a static member of a class template or of a class nested within
a class template."

Concerning the opinion of others: My original reply
suggesting that the compiler is broken was related to
a different code, which started with a template context
like this:

template < typename T1, typename T2 >
struct Test {
   typedef boost::tuple<T1,T2> tuple_t;
   tuple_t tup;

   enum Members { NAME, VALUE };
   typename boost::tuples::element<NAME, tuple_t>::type name() {
     ...
   }
};

The typename in front of boost::tuples::element is legal
and it is *required* in this case. My original posting
overlooked that the arguments of the relevant template
were dependent, but the answer was still correct, because
the important point is that the typename is legal in a
template context, even if the corresponding name is *not*
dependent. So this example is legal as well:

#include <utility>

template <typename>
struct TT {
   typename std::pair<int, double>::first_type name() {
     return 0;
   }
};

int main() {
   return TT<void>().name();
}

If the compiler does not accept the typename here, it is
broken, which was the essence of my OP.

Greetings from Bremen,

Daniel Krügler


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