Merge pull request #12571 from kjbracey-arm/noncopy

C++11-ify NonCopyable
pull/12259/head
Anna Bridge 2020-03-12 11:07:05 +00:00 committed by GitHub
commit 0699ac4e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 11 deletions

View File

@ -91,18 +91,16 @@ namespace mbed {
* in the base declaration. * in the base declaration.
* *
* To solve that problem, the copy constructor and assignment operator have to * To solve that problem, the copy constructor and assignment operator have to
* be declared (but don't need to be defined) in the private section of the * be defined as deleted:
* Connection class:
* *
* @code * @code
* struct Connection { * struct Connection {
* private: * Connection(const Connection &) = delete;
* Connection(const Connection&); * Connection &operator=(const Connection &) = delete;
* Connection& operator=(const Connection&);
* } * }
* @endcode * @endcode
* *
* Although manually declaring private copy constructor and assignment functions * Although manually defining deleted copy constructor and assignment functions
* works, it is not ideal. These declarations are usually easy to forget, * works, it is not ideal. These declarations are usually easy to forget,
* not immediately visible, and may be obscure to uninformed programmers. * not immediately visible, and may be obscure to uninformed programmers.
* *
@ -211,18 +209,18 @@ protected:
} }
#else #else
private: public:
/** /**
* Declare copy constructor as private. Any attempt to copy construct * Define copy constructor as deleted. Any attempt to copy construct
* a NonCopyable will fail at compile time. * a NonCopyable will fail at compile time.
*/ */
NonCopyable(const NonCopyable &); NonCopyable(const NonCopyable &) = delete;
/** /**
* Declare copy assignment operator as private. Any attempt to copy assign * Define copy assignment operator as deleted. Any attempt to copy assign
* a NonCopyable will fail at compile time. * a NonCopyable will fail at compile time.
*/ */
NonCopyable &operator=(const NonCopyable &); NonCopyable &operator=(const NonCopyable &) = delete;
#endif #endif
#endif #endif
}; };