The reason lies behind the implementation and the standard to be honest;
Look at the GCC implementation of this:
/// extent
template<typename, unsigned _Uint>
struct extent
: public integral_constant<std::size_t, 0> { };
template<typename _Tp, unsigned _Uint, std::size_t _Size>
struct extent<_Tp[_Size], _Uint>
: public integral_constant<std::size_t,
_Uint == 0 ? _Size : extent<_Tp,
_Uint - 1>::value>
{ };
template<typename _Tp, unsigned _Uint>
struct extent<_Tp[], _Uint>
: public integral_constant<std::size_t,
_Uint == 0 ? 0 : extent<_Tp,
_Uint - 1>::value>
{ };
And even the possible implementation specified in the cppreference:
template<class T, unsigned N = 0>
struct extent : std::integral_constant<std::size_t, 0> {};
template<class T>
struct extent<T[], 0> : std::integral_constant<std::size_t, 0> {};
template<class T, unsigned N>
struct extent<T[], N> : std::extent<T, N-1> {};
template<class T, std::size_t I>
struct extent<T[I], 0> : std::integral_constant<std::size_t, I> {};
template<class T, std::size_t I, unsigned N>
struct extent<T[I], N> : std::extent<T, N-1> {};
T[]
is different from a reference to an array; so it falls back on the default one which is this one:
template<class T, unsigned N = 0>
struct extent : std::integral_constant<std::size_t, 0> {};
which is 0 all the time.
It is possible to customize it to support references as well, but then you probably would want it to support const
and volatile
and const volatile
and other stuff which the implementer (if it was me) made it like this (from my web++ project):
WEBPP_REMOVE_CVREF()
WEBPP_REMOVE_CVREF(const)
WEBPP_REMOVE_CVREF(volatile)
WEBPP_REMOVE_CVREF(const volatile)
WEBPP_REMOVE_CVREF(&)
WEBPP_REMOVE_CVREF(&&)
WEBPP_REMOVE_CVREF(const&)
WEBPP_REMOVE_CVREF(const&&)
WEBPP_REMOVE_CVREF(volatile&)
WEBPP_REMOVE_CVREF(volatile&&)
WEBPP_REMOVE_CVREF(const volatile&)
WEBPP_REMOVE_CVREF(const volatile&&)
Yeah it's not pretty to do this right? So it's more convenient and usually less confusing actually to do put this on the user and not the library implementer or the standard.
std::decay
o adapt as your need. – Ami