Jump to content

  • Log In with Google      Sign In   
  • Create Account

decltype template parameter


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 roadysix_   Members   -  Reputation: 162

Like
0Likes
Like

Posted 21 June 2013 - 04:38 PM

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.


Edited by roadysix_, 21 June 2013 - 04:39 PM.


Sponsor:

#2 RobTheBloke   Crossbones+   -  Reputation: 2341

Like
0Likes
Like

Posted 21 June 2013 - 04:41 PM

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


Edited by RobTheBloke, 21 June 2013 - 04:44 PM.


#3 roadysix_   Members   -  Reputation: 162

Like
0Likes
Like

Posted 21 June 2013 - 05:44 PM

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*


Edited by roadysix_, 21 June 2013 - 06:39 PM.


#4 Matt-D   Crossbones+   -  Reputation: 1469

Like
0Likes
Like

Posted 23 June 2013 - 12:45 PM

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


Edited by Matt-D, 23 June 2013 - 12:46 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS