In C++03 or earlier, is there a way of implementing the auto
keyword? Not an object class, but so that it can be used like this [C++11]
auto x = 5;
std::cout << x;
I quickly 'whipped up' an implementation, but it is pretty rubbish, as you can cast it to any type - too much like an object
class, and pretty basic, I know, but anyway, here it is:
class auto_t
{
public:
template < typename _Ty > auto_t(const _Ty &_Value)
: __data(_Value)
{
}
template < typename _Ty > operator _Ty()
{
return (_Ty)__data;
}
private:
void *__data;
};
#define auto auto_t
Not really. That's why C++11 introduces it as a keyword, and not a library feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With