0

First I have the following definitions:

template<class T, int N = 1>
struct Wrap { typedef initializer_list<typename Wrap<T, N - 1>::Value> Value; };

template<class T>
struct Wrap<T> { typedef initializer_list<T> Value; };

template<class T, int N = 1>
using List = typename Wrap<T, N>::Value;

And I have the static assert success:

static_assert(is_same<List<int>, initializer_list<int>>::value);

Which means List<int> should be the same type as initializer_list<int>.

And I have the Test class:

template<int N>
class Test {
public:
    template<class T>
    static void check(const List<T, N> &list) { }
};

But when I call:

Test<1>::check({1, 2, 3, 4});

There is a compile error:

No matching function for call to 'Test<1>::check(<brace-enclosed initializer list>)'

But if I change check to:

template<class T>
static void check(const initializer_list<T> &list) { }

The above call

Test<1>::check({1, 2, 3, 4});

Compile success.

Shouldn't List<int> and initializer_list<int> be the same type?

zhh
  • 2,346
  • 1
  • 11
  • 22

0 Answers0