3 回答
TA贡献1785条经验 获得超8个赞
initializer_list
move
begin
end
initializer_list
const T *
move
T const &&
T const &
initializer_list
initializer_list
const initializer_list
const
begin
end
最新情况:initializer_list
TA贡献1906条经验 获得超10个赞
bar(std::move(*it)); // kosher?
const
std::initializer_list
const
it
const T *
.
std::move(*it)
std::initializer_list
TA贡献1982条经验 获得超2个赞
list.begin()
const T *
T
T&&
const
template<typename T> class rref_capture{ T* ptr;public: rref_capture(T&& x) : ptr(&x) {} operator T&& () const { return std::move(*ptr); } // restitute rvalue ref};
initializer_list<T>
initializer_list<rref_capture<T> >
std::unique_ptr<int>
#include <memory>#include <initializer_list>class uptr_vec{ typedef std::unique_ptr<int> uptr; // move only type std::vector<uptr> data;public: uptr_vec(uptr_vec&& v) : data(std::move(v.data)) {} uptr_vec(std::initializer_list<rref_capture<uptr> > l) : data(l.begin(),l.end()) {} uptr_vec& operator=(const uptr_vec&) = delete; int operator[] (size_t index) const { return *data[index]; }};int main(){ std::unique_ptr<int> a(new int(3)), b(new int(1)),c(new int(4)); uptr_vec v { std::move(a), std::move(b), std::move(c) }; std::cout << v[0] << "," << v[1] << "," << v[2] << std::endl;}
- 3 回答
- 0 关注
- 470 浏览
添加回答
举报