Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any alternative for type alias in C++0x?

I want to create an alias arr for std::array<T, 32>.

template<typename T>
using arr = std::array<T, 32>;

However, it does not work on GCC 4.4.6 which supports only C++0x(without type alias).

I think it is a very bad idea to use GCC 4.4.6 now, however, I want to know if there are some ways to simulate type alias.

The following code may work, but arr is not precisely std::array<T, 32>, so I want a better solution.

template<typename T>
struct arr : public std::array<T, 32>;
like image 301
calvin Avatar asked Oct 29 '25 10:10

calvin


1 Answers

Before alias templates were a thing, it was common to write this instead:

template<typename T>
struct arr {
    typedef std::array<T, 32> type;
};

Instead of arr<T> you would have to use arr<T>::type and typename arr<T>::type when T is a template parameter.

like image 53
463035818_is_not_a_number Avatar answered Oct 31 '25 02:10

463035818_is_not_a_number



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!