C++?????????????10??C++11????
???????????? ???????[ 2014/11/26 11:37:42 ] ????????C++ ????? ???????
????????????????????????????????????????C++???μ????????????????????????????????????????????????????????????????γ?????????b4???????????????????????b1???????????????????????????????getBuffer()??????????????????????????????????
???????????????????????????г?????????????????????????????std::move????????????????string???????std::string??std::unique_ptr???????????????塣???????????_name(temp._name)??臨??????????????????????_buffer?????????????std::unique_ptr???????????????С?????????????std::string????????????????б?????????????????????????Buffer??????????????????????????????????????????????????????????????????“temp”????????????????????????????????std::move?????????????γ??????????????????????????????????std::move????????????????????????????????????á?
???????£??????????????????????????????????????????????????????????????????????в?????????е?Member 7805758????????????????????????д?????????У?
1 template <typename T>
2 class Buffer
3 {
4 std::string _name;
5 size_t _size;
6 std::unique_ptr<T[]> _buffer;
7
8 public:
9 // constructor
10 Buffer(const std::string& name = ""?? size_t size = 16):
11 _name(name)??
12 _size(size)??
13 _buffer(size ? new T[size] : nullptr)
14 {}
15
16 // copy constructor
17 Buffer(const Buffer& copy):
18 _name(copy._name)??
19 _size(copy._size)??
20 _buffer(copy._size ? new T[copy._size] : nullptr)
21 {
22 T* source = copy._buffer.get();
23 T* dest = _buffer.get();
24 std::copy(source?? source + copy._size?? dest);
25 }
26
27 // copy assignment operator
28 Buffer& operator=(Buffer copy)
29 {
30 swap(*this. copy);
31 return *this;
32 }
33
34 // move constructor
35 Buffer(Buffer&& temp):Buffer()
36 {
37 swap(*this?? temp);
38 }
39
40 friend void swap(Buffer& first?? Buffer& second) noexcept
41 {
42 using std::swap;
43 swap(first._name ?? second._name);
44 swap(first._size ?? second._size);
45 swap(first._buffer ?? second._buffer);
46 }
47 };
???????
??????????????C++11??????????????????????????????????????C++???????????????Щ??????????????е?????????????????????е??Щ????????Щ?????????????????????
???????
????????????????????????CPOL??ɡ?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11