calvin
calvin

Reputation: 2925

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>;

Upvotes: 4

Views: 470

Answers (1)

463035818_is_not_an_ai
463035818_is_not_an_ai

Reputation: 122133

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.

Upvotes: 6

Related Questions