Here is a piece of code
// check if type of static array
template <class T>
struct ABIStaticArray : std::false_type //#1
{
};
// stringN type => bytesN
template <std::size_t N>
struct ABIStaticArray<std::array<char, N>> : std::false_type //#2
{
};
// a fixed-length array of N elements of type T.
template <class T, std::size_t N>
struct ABIStaticArray<std::array<T, N>> : std::true_type //#3
{
};
// fixed length of type, default 1 except static array type
template <class T, class Enable = void>
struct Length //#4
{
enum
{
value = 1
};
};
// length of static array type
template <class T>
struct Length<T, typename std::enable_if<ABIStaticArray<T>::value>::type> //#5
{
enum
{
value = std::tuple_size<T>::value * Length<typename std::tuple_element<0, T>::type>::value
};
};
- Why does the std::enable_if in specialized template of Length only have the first parameter?
- If I pass in a StaticArray, how does it match the specialized template of Length, if the value of first param of std::enable_if in specialized template of Length is true, the specialized template will become:
template <class T>
struct Length<T, void>
{
enum
{
value = std::tuple_size<T>::value * Length<typename std::tuple_element<0, T>::type>::value
};
};
why need this specialized template, what is the difference with the basic template of Length? the call of Length likes:
Length<std::array<int, 5>>::value
the result is 5
Please help, thanks very much!