Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't using boost::tuple's .get work in template functions in gcc?

While trying to port some code to compile in linux I get peculiar compilation errors. Searching through the codebase I finally manage to get it down to the following code.

 5: // include and using statements
 6: template<typename RT, typename T1>
 7: RT func(tuple<T1> const& t) {
 8:     return t.get<0>();
 9: }
10: // test code

Trying to use it I get the error:

test.cpp: In function <functionName>:
test.cpp:8: error: expected primary-expression before ‘)’ token

The code works fine in Visual Studio but for some reason I can't figure out why it doesn't work with g++. Anyone here got a clue how on how to work around this?

like image 261
lyml Avatar asked Jun 10 '11 19:06

lyml


1 Answers

You need some template love:

return t.template get<0>();

Visual C++ does not parse templates correctly, which is why it incorrectly accepts the code without the template keyword. For more information on why the template is required here, see the Stack Overflow C++ FAQ "Where and why do I have to put “template” and “typename” on dependent names?"

like image 69
James McNellis Avatar answered Sep 23 '22 06:09

James McNellis