decltype template parameter

Started by
2 comments, last by Matt-D 10 years, 10 months ago

Hi, I seem to having a little trouble with something that is seemingly simple.

I would like to get a typedef from my own traits class where the template is instantiated based on a member T::member.

It would be easier to just show an example of what I'm talking about


template <typename T> class someclass
{
public:
	// doesnt work
	typedef ns::some_traits<decltype(T::member)>::type type;
};

// works
typedef ns::some_traits<decltype(otherclass::member)>::type type;

To me this looks like I'm missing a typename somewhere in there but I've tried that in a number of variations.

Could it be a compiler bug (which I doubt)? I'm using the Visual C++ November 2012 CTP compiler. If not what is the problem here?

Thanks in advance.

Advertisement

template <typename T> class someclass
{
public:
	// doesnt work
	typedef typename ns::some_traits<typename T::member>::type type;
};

Thanks for the reply Rob, but that won't and doesn't work.

I've discovered after a little test that my problem lies elsewhere and will come back with a new problem.

I should probably mention that the member is actually a method, I'm trying to pass the operator( ) type as a template parameter and its a little closer to this:

<decltype(&T::operator( ))>

This actually worked in a test case but for some reason does not work with my actual traits class.. I'll figure it out..

EDIT: I ran this code through GCC and everything compiled and worked as expected, which only confirms my theory that this is a compiler bug. Really annoying..

EDIT2: Now I'm having some issues with GCC and const member functions.. *sigh*

If it's a method (member function), you may also need the "template" keyword, as in the following:


t::template f<int>(); // call a function template

extra-fun example:


typename t::template iterator<int>::value_type v;

See:

http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords

http://eigen.tuxfamily.org/dox-devel/TopicTemplateKeyword.html#TopicTemplateKeywordExplanation // more details in "Resources for further reading" -- at the very bottom of the page

This topic is closed to new replies.

Advertisement