fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6.  
  7. struct C {
  8. int i_=0;
  9. C() {}
  10. C(int i) : i_( i ) {}
  11. C( const C& other) :i_(other.i_) {
  12. std::cout << "A copy construction was made." << i_<<std::endl;
  13. }
  14. C& operator=( const C& other) {
  15. i_= other.i_ ;
  16. std::cout << "A copy assign was made."<< i_<<std::endl;
  17. return *this;
  18. }
  19. C( C&& other ) noexcept :i_( std::move(other.i_)) {
  20. std::cout << "A move construction was made." << i_ << std::endl;
  21. }
  22. C& operator=( C&& other ) noexcept {
  23. i_ = std::move(other.i_);
  24. std::cout << "A move assign was made." << i_ << std::endl;
  25. return *this;
  26. }
  27. };
  28.  
  29. int main() {
  30. //auto vec2 = std::vector<C>{{1},{2},{3},{4},{5}};
  31. auto vec2 = std::vector<C>{std::initializer_list<int>{1,2,3,4,5}};
  32.  
  33. cout << "reversing\n";
  34. std::reverse(vec2.begin(),vec2.end());
  35. return 0;
  36. }
Compilation error #stdin compilation error #stdout 0s 3472KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:31:69: error: no matching function for call to 'std::vector<C>::vector(<brace-enclosed initializer list>)'
     auto vec2 = std::vector<C>{std::initializer_list<int>{1,2,3,4,5}};
                                                                     ^
In file included from /usr/include/c++/5/vector:64:0,
                 from prog.cpp:2:
/usr/include/c++/5/bits/stl_vector.h:401:9: note: candidate: template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&)
         vector(_InputIterator __first, _InputIterator __last,
         ^
/usr/include/c++/5/bits/stl_vector.h:401:9: note:   template argument deduction/substitution failed:
prog.cpp:31:69: note:   candidate expects 3 arguments, 1 provided
     auto vec2 = std::vector<C>{std::initializer_list<int>{1,2,3,4,5}};
                                                                     ^
In file included from /usr/include/c++/5/vector:64:0,
                 from prog.cpp:2:
/usr/include/c++/5/bits/stl_vector.h:373:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = C; _Alloc = std::allocator<C>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<C>]
       vector(initializer_list<value_type> __l,
       ^
/usr/include/c++/5/bits/stl_vector.h:373:7: note:   no known conversion for argument 1 from 'std::initializer_list<int>' to 'std::initializer_list<C>'
/usr/include/c++/5/bits/stl_vector.h:348:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&) [with _Tp = C; _Alloc = std::allocator<C>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<C>]
       vector(vector&& __rv, const allocator_type& __m)
       ^
/usr/include/c++/5/bits/stl_vector.h:348:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/5/bits/stl_vector.h:339:7: note: candidate: std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, const allocator_type&) [with _Tp = C; _Alloc = std::allocator<C>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<C>]
       vector(const vector& __x, const allocator_type& __a)
       ^
/usr/include/c++/5/bits/stl_vector.h:339:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/5/bits/stl_vector.h:335:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = C; _Alloc = std::allocator<C>]
       vector(vector&& __x) noexcept
       ^
/usr/include/c++/5/bits/stl_vector.h:335:7: note:   no known conversion for argument 1 from 'std::initializer_list<int>' to 'std::vector<C>&&'
/usr/include/c++/5/bits/stl_vector.h:318:7: note: candidate: std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = C; _Alloc = std::allocator<C>]
       vector(const vector& __x)
       ^
/usr/include/c++/5/bits/stl_vector.h:318:7: note:   no known conversion for argument 1 from 'std::initializer_list<int>' to 'const std::vector<C>&'
/usr/include/c++/5/bits/stl_vector.h:289:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const allocator_type&) [with _Tp = C; _Alloc = std::allocator<C>; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::value_type = C; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<C>]
       vector(size_type __n, const value_type& __value,
       ^
/usr/include/c++/5/bits/stl_vector.h:289:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/5/bits/stl_vector.h:277:7: note: candidate: std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = C; _Alloc = std::allocator<C>; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<C>]
       vector(size_type __n, const allocator_type& __a = allocator_type())
       ^
/usr/include/c++/5/bits/stl_vector.h:277:7: note:   no known conversion for argument 1 from 'std::initializer_list<int>' to 'std::vector<C>::size_type {aka unsigned int}'
/usr/include/c++/5/bits/stl_vector.h:264:7: note: candidate: std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = C; _Alloc = std::allocator<C>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<C>]
       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
       ^
/usr/include/c++/5/bits/stl_vector.h:264:7: note:   no known conversion for argument 1 from 'std::initializer_list<int>' to 'const allocator_type& {aka const std::allocator<C>&}'
/usr/include/c++/5/bits/stl_vector.h:253:7: note: candidate: std::vector<_Tp, _Alloc>::vector() [with _Tp = C; _Alloc = std::allocator<C>]
       vector()
       ^
/usr/include/c++/5/bits/stl_vector.h:253:7: note:   candidate expects 0 arguments, 1 provided
stdout
Standard output is empty