|
Boost Users : |
From: Daniel Krügler (dsp_at_[hidden])
Date: 2008-05-21 03:07:51
Hansi wrote:
>
> Noah Roberts schrieb:
>
>>Hansi wrote:
>>
>>>Hello,
>>>
>>>at the moment I want to make a getter function for a tuple type. The
>>>tuple is internally hidden in a class. For that I want to make a
>>>function which returns the values inside the tuple. The best solution
>>>would be if I can make a enum which defines the position inside the
>>>tuple and a template function which returns the value for this tuple.
>>>
>>>I have tested the following, but it doesn't work:
>>>
>>>typedef struct Members
>>> {
>>> enum Member
>>> {
>>> name = 0,
>>> value = 1,
>>> };
>>> }Members;
>>>
>>> template<enum Member member>
>>> element<0, Properties::Property>::type name()(const
>>>boost::tuples::tuple<std::wstring, boost::any>& prop)
>>> {
>>> return boost::tuples::get<member>(prop);
>>> }
>>
>>I didn't quite understand your goals here so I implemented both I
>>thought you could mean:
>>
>>
>>#include <boost/tuple/tuple.hpp>
>>#include <string>
>>#include <iostream>
>>
>>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() { return
>>tup.get<NAME>(); }
>
>
> this version doesn't work with my compiler (msvc8.0). I get the error:
>
> error C2899:typename cannot be used outside a template declaration
>
> But this would be the preferred version for me. Have you an idea how I
> can solve this?
This is a compiler error and should be reported as such. Even in C++03
the usage of typename is not limited to *dependent* names (although it
must only occur in a template context), see [temp.res]/5:
"[..] The keyword typename shall be applied only to qualified names,
but those names need not be dependent. The keyword typename shall be
used only in contexts in which dependent names can be used. This
includes template declarations and definitions but excludes explicit
specialization declarations and explicit instantiation
declarations.[..]"
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