-
January 16th, 2009, 11:48 AM
#1
Problem with trick to overcome the absence of template typedefs
Hi there,
Can anyone see the problem with this code? http://codepad.org/ODBfNNW2
Thanks a lot,
Ricardo Abreu
-
January 16th, 2009, 12:09 PM
#2
Re: Problem with trick to overcome the absence of template typedefs
Put all relevant information here in this thread. Do you think that link will work in 5 years?
Code:
#include <utility>
#include <iostream>
namespace Testing
{
template<typename T>
struct CmdArg
{
typedef std::pair<T, bool> type;
};
template<typename T>
typename CmdArg<T>::type f(const T& t)
{
return CmdArg<T>::type(t, false);
}
}
int main()
{
Testing::CmdArg<int>::type arg = Testing::f(11);
std::cout << arg.first << " " << arg.second << std::endl;
return 0;
}
Fixes are in red.
gg
-
January 19th, 2009, 08:18 AM
#3
Re: Problem with trick to overcome the absence of template typedefs
OK, its solved. I actually had to add another 'typename' for it to work:
Code:
#include <utility>
#include <iostream>
namespace Testing
{
template<typename T>
struct CmdArg
{
typedef std::pair<T, bool> type;
};
template<typename T>
typename CmdArg<T>::type f(const T& t)
{
return typename CmdArg<T>::type(t, false);
}
}
int main()
{
Testing::CmdArg<int>::type arg = Testing::f(11);
std::cout << arg.first << " " << arg.second << std::endl;
return 0;
}
Thank you and sorry for not posting the code here before - I assumed IRC rules. Also, hopefully in 5 years C++ will already have template typedefs
Again, many thanks,
gumbers
-
January 19th, 2009, 08:27 AM
#4
Re: Problem with trick to overcome the absence of template typedefs
Originally Posted by gumbers
Also, hopefully in 5 years C++ will already have template typedefs
C++0x (which might be finalised this year) will have template typedefs via a template "using" statement. Now, whether or not compilers have implemented or will soon implement it is another matter, but hopefully they will take less than 5 years to get it done
(Incidentally, if you read the recent C++0x "slow chat" forum, template typedefs will not be supported by the up and coming MSVC10.)
-
January 20th, 2009, 11:36 AM
#5
Re: Problem with trick to overcome the absence of template typedefs
Originally Posted by laserlight
C++0x (which might be finalised this year) [...]
If it isn't, they'll have to start calling it "C++1x".
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
January 20th, 2009, 02:13 PM
#6
Re: Problem with trick to overcome the absence of template typedefs
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|