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
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
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 :p
Again, many thanks,
gumbers
Re: Problem with trick to overcome the absence of template typedefs
Quote:
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 :p
(Incidentally, if you read the recent C++0x "slow chat" forum, template typedefs will not be supported by the up and coming MSVC10.)
Re: Problem with trick to overcome the absence of template typedefs
Quote:
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".
Re: Problem with trick to overcome the absence of template typedefs
Quote:
Originally Posted by
Graham
If it isn't, they'll have to start calling it "C++1x".
Nahhh. we will just call the coming years 200A,200B,200C....:D:D:D:D