c++11 - c++ what is the type of T[] in template specialization -


i have question implementation of std::remove_extent (visual studio 11)

    template<class _ty>         struct remove_extent         {         typedef _ty type;         };      template<class _ty, unsigned int _ix>         struct remove_extent<_ty[_ix]>         {         typedef _ty type;         };      template<class _ty>         struct remove_extent<_ty[]> //what for?         {         typedef _ty type;         }; 

i tried this: std::cout << typeid(int[]).name() << '\n';

and output is: int [0], presume _ty[] stands _ty[0].

but purpose of specializing _t[0], think second case has handled that.

also, doubt if t [0] valid type, if so, in case whould use that?

t[] array of unknown size; incomplete type, different sized array type. seems compiler, validly confusingly, uses otherwise invalid t[0] string representation of type.

so specialisation needed since won't covered partial specialisation sized arrays.

if so, in case whould use that?

you wouldn't use array of 0 size, since that's not valid type.

you can use incomplete types (including arrays of unknown size) in various places, such variable declarations. example:

extern int array[];                           // declaration incomplete type std::remove_extent<decltype(array)>::type x;  // ok, gives "int" array[3] = 42;                                // ok, array decays pointer  template <size_t n> size_t size(int (&a)[n]) {return n;} std::cout << size(array) << "\n";             // error, needs complete type  // somewhere else int array[17];                                // definition complete type std::cout << size(array) << "\n";             // ok, size known 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -