#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct C {
int i_=0;
C() {}
C(int i) : i_( i ) {}
C( const C& other) :i_(other.i_) {
std::cout << "A copy construction was made." << i_<<std::endl;
}
C& operator=( const C& other) {
i_= other.i_ ;
std::cout << "A copy assign was made."<< i_<<std::endl;
return *this;
}
C( C&& other ) noexcept :i_( std::move(other.i_)) {
std::cout << "A move construction was made." << i_ << std::endl;
}
C& operator=( C&& other ) noexcept {
i_ = std::move(other.i_);
std::cout << "A move assign was made." << i_ << std::endl;
return *this;
}
};
int main() {
//auto vec2 = std::vector<C>{{1},{2},{3},{4},{5}};
auto vec2 = std::vector<C>{std::initializer_list<int>{1,2,3,4,5}};
cout << "reversing\n";
std::reverse(vec2.begin(),vec2.end());
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCiAgICAgIHN0cnVjdCBDIHsKICAgICAgICBpbnQgaV89MDsKICAgICAgICBDKCkge30KICAgICAgICBDKGludCBpKSA6IGlfKCBpICkge30KICAgICAgICBDKCBjb25zdCBDJiBvdGhlcikgOmlfKG90aGVyLmlfKSB7CiAgICAgICAgICBzdGQ6OmNvdXQgPDwgIkEgY29weSBjb25zdHJ1Y3Rpb24gd2FzIG1hZGUuIiA8PCBpXzw8c3RkOjplbmRsOwogICAgICAgIH0KICAgICAgICBDJiBvcGVyYXRvcj0oIGNvbnN0IEMmIG90aGVyKSB7CiAgICAgICAgICBpXz0gb3RoZXIuaV8gOwogICAgICAgICAgc3RkOjpjb3V0IDw8ICJBIGNvcHkgYXNzaWduIHdhcyBtYWRlLiI8PCBpXzw8c3RkOjplbmRsOwogICAgICAgICAgcmV0dXJuICp0aGlzOwogICAgICAgIH0KICAgICAgICBDKCBDJiYgb3RoZXIgKSBub2V4Y2VwdCA6aV8oIHN0ZDo6bW92ZShvdGhlci5pXykpIHsKICAgICAgICAgIHN0ZDo6Y291dCA8PCAiQSBtb3ZlIGNvbnN0cnVjdGlvbiB3YXMgbWFkZS4iIDw8IGlfIDw8IHN0ZDo6ZW5kbDsKICAgICAgICB9CiAgICAgICAgQyYgb3BlcmF0b3I9KCBDJiYgb3RoZXIgKSBub2V4Y2VwdCB7CiAgICAgICAgICBpXyA9IHN0ZDo6bW92ZShvdGhlci5pXyk7CiAgICAgICAgICBzdGQ6OmNvdXQgPDwgIkEgbW92ZSBhc3NpZ24gd2FzIG1hZGUuIiA8PCBpXyA8PCBzdGQ6OmVuZGw7CiAgICAgICAgICByZXR1cm4gKnRoaXM7CiAgICAgICAgfQogICAgICB9OwogICAgICAKaW50IG1haW4oKSB7CiAgICAvL2F1dG8gdmVjMiA9IHN0ZDo6dmVjdG9yPEM+e3sxfSx7Mn0sezN9LHs0fSx7NX19OwogICAgYXV0byB2ZWMyID0gc3RkOjp2ZWN0b3I8Qz57c3RkOjppbml0aWFsaXplcl9saXN0PGludD57MSwyLDMsNCw1fX07CgoJY291dCA8PCAicmV2ZXJzaW5nXG4iOwoJc3RkOjpyZXZlcnNlKHZlYzIuYmVnaW4oKSx2ZWMyLmVuZCgpKTsKCXJldHVybiAwOwp9
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