I am trying to initialize data_
private class data member which is a C++11 array of length 3 with the initializer list constructor:
template<typename Type>
class triElement
{
public:
triElement(std::initializer_list<Type> list)
:
data_(list)
{}
auto begin() const
{
return data_.begin();
}
auto end() const
{
return data_.end();
}
private:
std::array<Type, 3> data_;
};
And the compilation of the complete code example fails with the error:
g++ -std=c++1y -O2 -Wall -pedantic -pthread main.cpp && ./a.out
main.cpp: In instantiation of 'triElement<Type>::triElement(const std::initializer_list<_Tp>&) [with Type = int]':
main.cpp:80:31: required from here
main.cpp:37:27: error: no matching function for call to 'std::array<int, 3ul>::array(const std::initializer_list<int>&)'
data_(list)
Even though exactly the same approach works when the attribute data
is of type std::vector:
template<typename Type>
class elements
{
public:
elements(std::initializer_list<Type> list)
:
data_(list)
{}
auto begin() const
{
return data_.begin();
}
auto end() const
{
return data_.end();
}
private:
std::vector<Type> data_;
};
Is there something special I need to think of when delegating the initializer list constructor call to the C++11 array attribute?