Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: webrtc/base/scoped_ptr.h

Issue 1570473002: Replace manual casting to rvalue reference with calls to std::move (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/optional_unittest.cc ('k') | webrtc/system_wrappers/include/scoped_vector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 scoped_ptr& operator=(std::nullptr_t) { 367 scoped_ptr& operator=(std::nullptr_t) {
368 reset(); 368 reset();
369 return *this; 369 return *this;
370 } 370 }
371 371
372 // Deleted copy constructor and copy assignment, to make the type move-only. 372 // Deleted copy constructor and copy assignment, to make the type move-only.
373 scoped_ptr(const scoped_ptr& other) = delete; 373 scoped_ptr(const scoped_ptr& other) = delete;
374 scoped_ptr& operator=(const scoped_ptr& other) = delete; 374 scoped_ptr& operator=(const scoped_ptr& other) = delete;
375 375
376 // Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).) 376 // Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).)
377 scoped_ptr&& Pass() { return static_cast<scoped_ptr&&>(*this); } 377 scoped_ptr&& Pass() { return std::move(*this); }
378 378
379 // Reset. Deletes the currently owned object, if any. 379 // Reset. Deletes the currently owned object, if any.
380 // Then takes ownership of a new object, if given. 380 // Then takes ownership of a new object, if given.
381 void reset(element_type* p = nullptr) { impl_.reset(p); } 381 void reset(element_type* p = nullptr) { impl_.reset(p); }
382 382
383 // Accessors to get the owned object. 383 // Accessors to get the owned object.
384 // operator* and operator-> will assert() if there is no current object. 384 // operator* and operator-> will assert() if there is no current object.
385 element_type& operator*() const { 385 element_type& operator*() const {
386 assert(impl_.get() != nullptr); 386 assert(impl_.get() != nullptr);
387 return *impl_.get(); 387 return *impl_.get();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 scoped_ptr& operator=(std::nullptr_t) { 500 scoped_ptr& operator=(std::nullptr_t) {
501 reset(); 501 reset();
502 return *this; 502 return *this;
503 } 503 }
504 504
505 // Deleted copy constructor and copy assignment, to make the type move-only. 505 // Deleted copy constructor and copy assignment, to make the type move-only.
506 scoped_ptr(const scoped_ptr& other) = delete; 506 scoped_ptr(const scoped_ptr& other) = delete;
507 scoped_ptr& operator=(const scoped_ptr& other) = delete; 507 scoped_ptr& operator=(const scoped_ptr& other) = delete;
508 508
509 // Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).) 509 // Get an rvalue reference. (sp.Pass() does the same thing as std::move(sp).)
510 scoped_ptr&& Pass() { return static_cast<scoped_ptr&&>(*this); } 510 scoped_ptr&& Pass() { return std::move(*this); }
511 511
512 // Reset. Deletes the currently owned array, if any. 512 // Reset. Deletes the currently owned array, if any.
513 // Then takes ownership of a new object, if given. 513 // Then takes ownership of a new object, if given.
514 void reset(element_type* array = nullptr) { impl_.reset(array); } 514 void reset(element_type* array = nullptr) { impl_.reset(array); }
515 515
516 // Accessors to get the owned array. 516 // Accessors to get the owned array.
517 element_type& operator[](size_t i) const { 517 element_type& operator[](size_t i) const {
518 assert(impl_.get() != nullptr); 518 assert(impl_.get() != nullptr);
519 return impl_.get()[i]; 519 return impl_.get()[i];
520 } 520 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 612
613 // A function to convert T* into scoped_ptr<T> 613 // A function to convert T* into scoped_ptr<T>
614 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation 614 // Doing e.g. make_scoped_ptr(new FooBarBaz<type>(arg)) is a shorter notation
615 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg)) 615 // for scoped_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))
616 template <typename T> 616 template <typename T>
617 rtc::scoped_ptr<T> rtc_make_scoped_ptr(T* ptr) { 617 rtc::scoped_ptr<T> rtc_make_scoped_ptr(T* ptr) {
618 return rtc::scoped_ptr<T>(ptr); 618 return rtc::scoped_ptr<T>(ptr);
619 } 619 }
620 620
621 #endif // #ifndef WEBRTC_BASE_SCOPED_PTR_H__ 621 #endif // #ifndef WEBRTC_BASE_SCOPED_PTR_H__
OLDNEW
« no previous file with comments | « webrtc/base/optional_unittest.cc ('k') | webrtc/system_wrappers/include/scoped_vector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698