fork(1) download
  1. #include <array>
  2. #include <initializer_list>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. template<class Container>
  7. class SequenceContainerWrapper
  8. {
  9. Container cont;
  10. public:
  11. using value_type = typename Container::value_type;
  12. using reference = typename Container::reference;
  13. using size_type = typename Container::size_type;
  14. SequenceContainerWrapper(initializer_list<value_type> init) : cont(init) {}
  15. reference operator[] (size_type n) {return cont[n];}
  16. // lots of other code that does nothing but wrapping
  17. };
  18.  
  19. int main()
  20. {
  21. SequenceContainerWrapper<array<int, 4>> arr({1,2,3,4});
  22. cout << arr[2] << '\n';
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'SequenceContainerWrapper<Container>::SequenceContainerWrapper(std::initializer_list<typename Container::value_type>) [with Container = std::array<int, 4u>; typename Container::value_type = int]':
prog.cpp:21:55:   required from here
prog.cpp:14:74: error: no matching function for call to 'std::array<int, 4u>::array(std::initializer_list<int>&)'
   SequenceContainerWrapper(initializer_list<value_type> init) : cont(init) {}
                                                                          ^
In file included from prog.cpp:1:0:
/usr/include/c++/5/array:89:12: note: candidate: std::array<int, 4u>::array()
     struct array
            ^
/usr/include/c++/5/array:89:12: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/5/array:89:12: note: candidate: constexpr std::array<int, 4u>::array(const std::array<int, 4u>&)
/usr/include/c++/5/array:89:12: note:   no known conversion for argument 1 from 'std::initializer_list<int>' to 'const std::array<int, 4u>&'
/usr/include/c++/5/array:89:12: note: candidate: constexpr std::array<int, 4u>::array(std::array<int, 4u>&&)
/usr/include/c++/5/array:89:12: note:   no known conversion for argument 1 from 'std::initializer_list<int>' to 'std::array<int, 4u>&&'
stdout
Standard output is empty