How does the compiler choose between array template specializations?
I just stumbled across the std :: tr1 :: extent template and it puzzled me. I've never looked at array parameters in my life, so I don't understand how they work. So, given the code from gcctype_traits
template<typename _Tp, unsigned _Uint, std::size_t _Size>
struct extent<_Tp[_Size], _Uint>
template<typename _Tp, unsigned _Uint>
struct extent<_Tp[], _Uint>
how does the compiler choose between these specializations? What type should I go to extent
in order to choose it?
source to share
extent<int[], 0>::value == 0 // second one chosen
int[]
is an incomplete type, the compiler does not know its meaning sizeof
. The outer dimension may remain incomplete, as it doesn't matter that the array functions correctly in most contexts (in particular, indexing will still work). Something like int[1][]
it won't be right anymore.
extent<int[2], 0>::value == 2 // first one chosen
Of course this can be nested:
extent<int[][2], 0>::value == 0 // second one chosen, with `_Tp` being `int[2]`
extent<int[][2], 1>::value == 2 // second one chosen again
source to share